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:
parent
00bb477903
commit
9406136861
1 changed files with 12 additions and 5 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue