mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-11 13:07:20 +00:00
Merge 574f56b7bb
into 95c3efbdb4
This commit is contained in:
commit
1d742675c5
3 changed files with 45 additions and 6 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -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,
|
||||||
});
|
});
|
||||||
|
|
28
backend/src/plugins/Automod/actions/unArchiveThread.ts
Normal file
28
backend/src/plugins/Automod/actions/unArchiveThread.ts
Normal 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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue