diff --git a/backend/src/plugins/CustomEvents/actions/setChannelPermissionOverrides.ts b/backend/src/plugins/CustomEvents/actions/setChannelPermissionOverrides.ts new file mode 100644 index 00000000..595a56e2 --- /dev/null +++ b/backend/src/plugins/CustomEvents/actions/setChannelPermissionOverrides.ts @@ -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; + +export async function setChannelPermissionOverridesAction( + pluginData: GuildPluginData, + 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}`, + ); + } +} diff --git a/backend/src/plugins/CustomEvents/functions/runEvent.ts b/backend/src/plugins/CustomEvents/functions/runEvent.ts index bd0b3ef5..3b304ff9 100644 --- a/backend/src/plugins/CustomEvents/functions/runEvent.ts +++ b/backend/src/plugins/CustomEvents/functions/runEvent.ts @@ -9,6 +9,7 @@ import { moveToVoiceChannelAction } from "../actions/moveToVoiceChannelAction"; import { messageAction } from "../actions/messageAction"; import { makeRoleMentionableAction } from "../actions/makeRoleMentionableAction"; import { makeRoleUnmentionableAction } from "../actions/makeRoleUnmentionableAction"; +import { setChannelPermissionOverridesAction } from "../actions/setChannelPermissionOverrides"; export async function runEvent( pluginData: GuildPluginData, @@ -30,6 +31,8 @@ export async function runEvent( await makeRoleMentionableAction(pluginData, action, values, event, eventData); } else if (action.type === "make_role_unmentionable") { await makeRoleUnmentionableAction(pluginData, action, values, event, eventData); + } else if (action.type === "set_channel_permission_overrides") { + await setChannelPermissionOverridesAction(pluginData, action, values, event, eventData); } } } catch (e) { diff --git a/backend/src/plugins/CustomEvents/types.ts b/backend/src/plugins/CustomEvents/types.ts index 8bd0ffdf..44058777 100644 --- a/backend/src/plugins/CustomEvents/types.ts +++ b/backend/src/plugins/CustomEvents/types.ts @@ -6,6 +6,7 @@ import { MoveToVoiceChannelAction } from "./actions/moveToVoiceChannelAction"; import { MessageAction } from "./actions/messageAction"; import { MakeRoleMentionableAction } from "./actions/makeRoleMentionableAction"; import { MakeRoleUnmentionableAction } from "./actions/makeRoleUnmentionableAction"; +import { SetChannelPermissionOverridesAction } from "./actions/setChannelPermissionOverrides"; // Triggers const CommandTrigger = t.type({ @@ -26,6 +27,7 @@ const AnyAction = t.union([ MessageAction, MakeRoleMentionableAction, MakeRoleUnmentionableAction, + SetChannelPermissionOverridesAction, ]); type TAnyAction = t.TypeOf;