diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index 76b2a60e..24ebfb7c 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -15,6 +15,7 @@ import { ReplyAction } from "./reply"; import { SetAntiraidLevelAction } from "./setAntiraidLevel"; import { SetCounterAction } from "./setCounter"; import { SetSlowmodeAction } from "./setSlowmode"; +import { UnArchiveThreadAction } from "./unArchiveThread"; import { WarnAction } from "./warn"; export const availableActions: Record> = { @@ -34,6 +35,7 @@ export const availableActions: Record> = { set_counter: SetCounterAction, set_slowmode: SetSlowmodeAction, archive_thread: ArchiveThreadAction, + unarchive_thread: UnArchiveThreadAction, }; export const AvailableActions = t.type({ @@ -53,4 +55,5 @@ export const AvailableActions = t.type({ set_counter: SetCounterAction.configType, set_slowmode: SetSlowmodeAction.configType, archive_thread: ArchiveThreadAction.configType, + unarchive_thread: UnArchiveThreadAction.configType, }); diff --git a/backend/src/plugins/Automod/actions/unArchiveThread.ts b/backend/src/plugins/Automod/actions/unArchiveThread.ts new file mode 100644 index 00000000..cdd17d74 --- /dev/null +++ b/backend/src/plugins/Automod/actions/unArchiveThread.ts @@ -0,0 +1,27 @@ +import { ThreadChannel } from "discord.js"; +import * as t from "io-ts"; +import { noop, tNullable } from "../../../utils"; +import { automodAction } from "../helpers"; + +export const UnArchiveThreadAction = automodAction({ + configType: t.type({ + unlock: tNullable(t.boolean), + }), + defaultConfig: { + unlock: false, + }, + + async apply({ pluginData, contexts, actionConfig }) { + const threads = contexts + .filter((c) => c.message?.channel_id) + .map((c) => pluginData.guild.channels.cache.get(c.message!.channel_id)) + .filter((c): c is ThreadChannel => (c?.isThread() && c.archived) ?? false); + + for (const thread of threads) { + if (actionConfig.unlock) { + await thread.setLocked(false).catch(noop); + } + await thread.setArchived(false).catch(noop); + } + }, +});