From b3e2e0cffb90f2789ebed6ee0dff06f71436fa19 Mon Sep 17 00:00:00 2001 From: Almeida Date: Sat, 4 Sep 2021 17:37:49 +0100 Subject: [PATCH] Add archive_thread action to automod (#271) --- .../plugins/Automod/actions/archiveThread.ts | 20 +++++++++++++++++++ .../Automod/actions/availableActions.ts | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 backend/src/plugins/Automod/actions/archiveThread.ts diff --git a/backend/src/plugins/Automod/actions/archiveThread.ts b/backend/src/plugins/Automod/actions/archiveThread.ts new file mode 100644 index 00000000..7c7aa218 --- /dev/null +++ b/backend/src/plugins/Automod/actions/archiveThread.ts @@ -0,0 +1,20 @@ +import { ThreadChannel } from "discord.js"; +import * as t from "io-ts"; +import { noop } from "../../../utils"; +import { automodAction } from "../helpers"; + +export const ArchiveThreadAction = automodAction({ + configType: t.type({}), + defaultConfig: {}, + + async apply({ pluginData, contexts }) { + 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() ?? false); + + for (const thread of threads) { + await thread.setArchived().catch(noop); + } + }, +}); diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index fbdcf8f9..76b2a60e 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -3,6 +3,7 @@ import { AutomodActionBlueprint } from "../helpers"; import { AddRolesAction } from "./addRoles"; import { AddToCounterAction } from "./addToCounter"; import { AlertAction } from "./alert"; +import { ArchiveThreadAction } from "./archiveThread"; import { BanAction } from "./ban"; import { ChangeNicknameAction } from "./changeNickname"; import { CleanAction } from "./clean"; @@ -32,6 +33,7 @@ export const availableActions: Record> = { add_to_counter: AddToCounterAction, set_counter: SetCounterAction, set_slowmode: SetSlowmodeAction, + archive_thread: ArchiveThreadAction, }; export const AvailableActions = t.type({ @@ -50,4 +52,5 @@ export const AvailableActions = t.type({ add_to_counter: AddToCounterAction.configType, set_counter: SetCounterAction.configType, set_slowmode: SetSlowmodeAction.configType, + archive_thread: ArchiveThreadAction.configType, });