mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 22:01:50 +00:00
add locking to archive_thread
This commit is contained in:
parent
00bb477903
commit
9406136861
1 changed files with 12 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue