3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-11 04:57:19 +00:00
This commit is contained in:
metal 2021-10-29 18:21:04 +07:00 committed by GitHub
commit 1d742675c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 6 deletions

View file

@ -1,19 +1,27 @@
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.thread?.id)
.map((c) => pluginData.guild.channels.cache.get(c.message!.channel_id)) .map((c) => pluginData.guild.channels.cache.get(c.thread!.id))
.filter((c): c is ThreadChannel => c?.isThread() ?? false); .filter((c): c is ThreadChannel => c?.isThread() ?? false);
for (const thread of threads) { for (const thread of threads) {
if (actionConfig.lock && !thread.locked) {
await thread.setLocked().catch(noop);
}
if (thread.archived) continue;
await thread.setArchived().catch(noop); await thread.setArchived().catch(noop);
} }
}, },

View file

@ -15,6 +15,7 @@ import { ReplyAction } from "./reply";
import { SetAntiraidLevelAction } from "./setAntiraidLevel"; import { SetAntiraidLevelAction } from "./setAntiraidLevel";
import { SetCounterAction } from "./setCounter"; import { SetCounterAction } from "./setCounter";
import { SetSlowmodeAction } from "./setSlowmode"; import { SetSlowmodeAction } from "./setSlowmode";
import { UnArchiveThreadAction } from "./unArchiveThread";
import { WarnAction } from "./warn"; import { WarnAction } from "./warn";
export const availableActions: Record<string, AutomodActionBlueprint<any>> = { export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
@ -34,6 +35,7 @@ export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
set_counter: SetCounterAction, set_counter: SetCounterAction,
set_slowmode: SetSlowmodeAction, set_slowmode: SetSlowmodeAction,
archive_thread: ArchiveThreadAction, archive_thread: ArchiveThreadAction,
unarchive_thread: UnArchiveThreadAction,
}; };
export const AvailableActions = t.type({ export const AvailableActions = t.type({
@ -53,4 +55,5 @@ export const AvailableActions = t.type({
set_counter: SetCounterAction.configType, set_counter: SetCounterAction.configType,
set_slowmode: SetSlowmodeAction.configType, set_slowmode: SetSlowmodeAction.configType,
archive_thread: ArchiveThreadAction.configType, archive_thread: ArchiveThreadAction.configType,
unarchive_thread: UnArchiveThreadAction.configType,
}); });

View file

@ -0,0 +1,28 @@
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() ?? false);
for (const thread of threads) {
if (actionConfig.unlock && thread.locked) {
await thread.setLocked(false).catch(noop);
}
if (!thread.archived) continue;
await thread.setArchived(false).catch(noop);
}
},
});