From 3a36b3e5efd15f6e3a8ffd9a6de7cd732ae57ef6 Mon Sep 17 00:00:00 2001 From: metal Date: Tue, 14 Sep 2021 15:31:44 +0000 Subject: [PATCH] fixes --- .../Automod/actions/unArchiveThread.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 backend/src/plugins/Automod/actions/unArchiveThread.ts diff --git a/backend/src/plugins/Automod/actions/unArchiveThread.ts b/backend/src/plugins/Automod/actions/unArchiveThread.ts new file mode 100644 index 00000000..db8bd4b0 --- /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.thread?.id) + .map(c => pluginData.guild.channels.cache.get(c.thread!.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); + } + }, +});