3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 14:11:50 +00:00

add locking to archive_thread

This commit is contained in:
metal 2021-09-14 14:10:42 +00:00 committed by GitHub
parent 00bb477903
commit 9406136861
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,19 +1,26 @@
import { ThreadChannel } from "discord.js"; import { ThreadChannel } from "discord.js";
import * as t from "io-ts"; import * as t from "io-ts";
import { noop } from "../../../utils"; import { noop, tNullable } from "../../../utils";
import { automodAction } from "../helpers"; import { automodAction } from "../helpers";
export const ArchiveThreadAction = automodAction({ export const ArchiveThreadAction = automodAction({
configType: t.type({}), configType: t.type({
defaultConfig: {}, lock: tNullable(t.boolean),
}),
defaultConfig: {
lock: false,
},
async apply({ pluginData, contexts }) { async apply({ pluginData, contexts, actionConfig }) {
const threads = contexts const threads = contexts
.filter((c) => c.message?.channel_id) .filter((c) => c.message?.channel_id)
.map((c) => pluginData.guild.channels.cache.get(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) { for (const thread of threads) {
if (actionConfig.lock) {
await thread.setLocked().catch(noop);
}
await thread.setArchived().catch(noop); await thread.setArchived().catch(noop);
} }
}, },