From 9406136861937c92c3749dded4341819ee992759 Mon Sep 17 00:00:00 2001 From: metal Date: Tue, 14 Sep 2021 14:10:42 +0000 Subject: [PATCH] add locking to archive_thread --- .../plugins/Automod/actions/archiveThread.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/src/plugins/Automod/actions/archiveThread.ts b/backend/src/plugins/Automod/actions/archiveThread.ts index 6fe871a5..b5d771e3 100644 --- a/backend/src/plugins/Automod/actions/archiveThread.ts +++ b/backend/src/plugins/Automod/actions/archiveThread.ts @@ -1,19 +1,26 @@ import { ThreadChannel } from "discord.js"; import * as t from "io-ts"; -import { noop } from "../../../utils"; +import { noop, tNullable } from "../../../utils"; import { automodAction } from "../helpers"; export const ArchiveThreadAction = automodAction({ - configType: t.type({}), - defaultConfig: {}, + configType: t.type({ + lock: tNullable(t.boolean), + }), + defaultConfig: { + lock: false, + }, - async apply({ pluginData, contexts }) { + 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() ?? false); + .filter((c): c is ThreadChannel => (c?.isThread() && !c.archived) ?? false); for (const thread of threads) { + if (actionConfig.lock) { + await thread.setLocked().catch(noop); + } await thread.setArchived().catch(noop); } },