mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Add 'set_channel_permission_overrides' custom event action
This commit is contained in:
parent
7839cc7da1
commit
e7efd48519
3 changed files with 46 additions and 0 deletions
|
@ -0,0 +1,41 @@
|
||||||
|
import { GuildPluginData } from "knub";
|
||||||
|
import { CustomEventsPluginType, TCustomEvent } from "../types";
|
||||||
|
import * as t from "io-ts";
|
||||||
|
import { ActionError } from "../ActionError";
|
||||||
|
|
||||||
|
export const SetChannelPermissionOverridesAction = t.type({
|
||||||
|
type: t.literal("set_channel_permission_overrides"),
|
||||||
|
channel: t.string,
|
||||||
|
overrides: t.array(
|
||||||
|
t.type({
|
||||||
|
type: t.union([t.literal("member"), t.literal("role")]),
|
||||||
|
id: t.string,
|
||||||
|
allow: t.number,
|
||||||
|
deny: t.number,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
export type TSetChannelPermissionOverridesAction = t.TypeOf<typeof SetChannelPermissionOverridesAction>;
|
||||||
|
|
||||||
|
export async function setChannelPermissionOverridesAction(
|
||||||
|
pluginData: GuildPluginData<CustomEventsPluginType>,
|
||||||
|
action: TSetChannelPermissionOverridesAction,
|
||||||
|
values: any,
|
||||||
|
event: TCustomEvent,
|
||||||
|
eventData: any,
|
||||||
|
) {
|
||||||
|
const channel = pluginData.guild.channels.get(action.channel);
|
||||||
|
if (!channel) {
|
||||||
|
throw new ActionError(`Unknown channel: ${action.channel}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const override of action.overrides) {
|
||||||
|
await channel.editPermission(
|
||||||
|
override.id,
|
||||||
|
override.allow,
|
||||||
|
override.deny,
|
||||||
|
override.type,
|
||||||
|
`Custom event: ${event.name}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import { moveToVoiceChannelAction } from "../actions/moveToVoiceChannelAction";
|
||||||
import { messageAction } from "../actions/messageAction";
|
import { messageAction } from "../actions/messageAction";
|
||||||
import { makeRoleMentionableAction } from "../actions/makeRoleMentionableAction";
|
import { makeRoleMentionableAction } from "../actions/makeRoleMentionableAction";
|
||||||
import { makeRoleUnmentionableAction } from "../actions/makeRoleUnmentionableAction";
|
import { makeRoleUnmentionableAction } from "../actions/makeRoleUnmentionableAction";
|
||||||
|
import { setChannelPermissionOverridesAction } from "../actions/setChannelPermissionOverrides";
|
||||||
|
|
||||||
export async function runEvent(
|
export async function runEvent(
|
||||||
pluginData: GuildPluginData<CustomEventsPluginType>,
|
pluginData: GuildPluginData<CustomEventsPluginType>,
|
||||||
|
@ -30,6 +31,8 @@ export async function runEvent(
|
||||||
await makeRoleMentionableAction(pluginData, action, values, event, eventData);
|
await makeRoleMentionableAction(pluginData, action, values, event, eventData);
|
||||||
} else if (action.type === "make_role_unmentionable") {
|
} else if (action.type === "make_role_unmentionable") {
|
||||||
await makeRoleUnmentionableAction(pluginData, action, values, event, eventData);
|
await makeRoleUnmentionableAction(pluginData, action, values, event, eventData);
|
||||||
|
} else if (action.type === "set_channel_permission_overrides") {
|
||||||
|
await setChannelPermissionOverridesAction(pluginData, action, values, event, eventData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { MoveToVoiceChannelAction } from "./actions/moveToVoiceChannelAction";
|
||||||
import { MessageAction } from "./actions/messageAction";
|
import { MessageAction } from "./actions/messageAction";
|
||||||
import { MakeRoleMentionableAction } from "./actions/makeRoleMentionableAction";
|
import { MakeRoleMentionableAction } from "./actions/makeRoleMentionableAction";
|
||||||
import { MakeRoleUnmentionableAction } from "./actions/makeRoleUnmentionableAction";
|
import { MakeRoleUnmentionableAction } from "./actions/makeRoleUnmentionableAction";
|
||||||
|
import { SetChannelPermissionOverridesAction } from "./actions/setChannelPermissionOverrides";
|
||||||
|
|
||||||
// Triggers
|
// Triggers
|
||||||
const CommandTrigger = t.type({
|
const CommandTrigger = t.type({
|
||||||
|
@ -26,6 +27,7 @@ const AnyAction = t.union([
|
||||||
MessageAction,
|
MessageAction,
|
||||||
MakeRoleMentionableAction,
|
MakeRoleMentionableAction,
|
||||||
MakeRoleUnmentionableAction,
|
MakeRoleUnmentionableAction,
|
||||||
|
SetChannelPermissionOverridesAction,
|
||||||
]);
|
]);
|
||||||
type TAnyAction = t.TypeOf<typeof AnyAction>;
|
type TAnyAction = t.TypeOf<typeof AnyAction>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue