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

add unarchive_thread

This commit is contained in:
metal 2021-09-14 14:10:30 +00:00 committed by GitHub
parent c84d1a0be1
commit 00bb477903
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

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