3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-23 17:45:03 +00:00
zeppelin/backend/src/plugins/Automod/actions/archiveThread.ts
2021-09-14 15:37:45 +00:00

28 lines
832 B
TypeScript

import { ThreadChannel } from "discord.js";
import * as t from "io-ts";
import { noop, tNullable } from "../../../utils";
import { automodAction } from "../helpers";
export const ArchiveThreadAction = automodAction({
configType: t.type({
lock: tNullable(t.boolean),
}),
defaultConfig: {
lock: 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() ?? false);
for (const thread of threads) {
if (actionConfig.lock && !thread.locked) {
await thread.setLocked().catch(noop);
}
if (thread.archived) continue;
await thread.setArchived().catch(noop);
}
},
});