3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-16 14:45:02 +00:00
This commit is contained in:
rubyowo 2024-10-27 11:30:33 +00:00 committed by GitHub
commit 875ff9933e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 78 additions and 4 deletions

View file

@ -3,18 +3,19 @@ import z from "zod";
import { noop } from "../../../utils.js";
import { automodAction } from "../helpers.js";
const configSchema = z.strictObject({});
export const ArchiveThreadAction = automodAction({
configSchema,
configSchema: z.strictObject({
lock: z.boolean().optional(),
}),
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 AnyThreadChannel => c?.isThread() ?? false);
for (const thread of threads) {
actionConfig.lock ? await thread.setLocked().catch(noop) : null;
await thread.setArchived().catch(noop);
}
},

View file

@ -7,7 +7,9 @@ import { BanAction } from "./ban.js";
import { ChangeNicknameAction } from "./changeNickname.js";
import { ChangePermsAction } from "./changePerms.js";
import { CleanAction } from "./clean.js";
import { EditPostTagsAction } from "./editPostTags.js";
import { KickAction } from "./kick.js";
import { LockThreadAction } from "./lockThread.js";
import { LogAction } from "./log.js";
import { MuteAction } from "./mute.js";
import { PauseInvitesAction } from "./pauseInvites.js";
@ -17,6 +19,7 @@ import { SetAntiraidLevelAction } from "./setAntiraidLevel.js";
import { SetCounterAction } from "./setCounter.js";
import { SetSlowmodeAction } from "./setSlowmode.js";
import { StartThreadAction } from "./startThread.js";
import { UnlockThreadAction } from "./unlockThread.js";
import { WarnAction } from "./warn.js";
export const availableActions = {
@ -37,6 +40,9 @@ export const availableActions = {
set_slowmode: SetSlowmodeAction,
start_thread: StartThreadAction,
archive_thread: ArchiveThreadAction,
lock_thread: LockThreadAction,
unlock_thread: UnlockThreadAction,
edit_post_tags: EditPostTagsAction,
change_perms: ChangePermsAction,
pause_invites: PauseInvitesAction,
} satisfies Record<string, AutomodActionBlueprint<any>>;

View file

@ -0,0 +1,29 @@
import { AnyThreadChannel } from "discord.js";
import z from "zod";
import { zSnowflake } from "../../../utils.js";
import { automodAction } from "../helpers.js";
export const EditPostTagsAction = automodAction({
configSchema: z.strictObject({
tags: z.array(zSnowflake),
append: z.boolean().optional(),
delete: z.boolean().optional(),
}),
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 AnyThreadChannel => (c?.isThread() && c?.parent?.isThreadOnly() && c?.editable) ?? false);
const tags: string[] = actionConfig.tags;
for (const thread of threads) {
const finalTags = actionConfig.append
? thread.appliedTags.concat(tags)
: actionConfig.delete
? thread.appliedTags.filter((id) => !tags.includes(id))
: tags;
await thread.setAppliedTags(finalTags);
}
},
});

View file

@ -0,0 +1,19 @@
import { AnyThreadChannel } from "discord.js";
import z from "zod";
import { noop } from "../../../utils.js";
import { automodAction } from "../helpers.js";
export const LockThreadAction = automodAction({
configSchema: z.strictObject({}),
async apply({ pluginData, contexts }) {
const threads = contexts
.filter((c) => c.message?.channel_id)
.map((c) => pluginData.guild.channels.cache.get(c.message!.channel_id))
.filter((c): c is AnyThreadChannel => (c?.isThread() && c?.editable) ?? false);
for (const thread of threads) {
await thread.setLocked().catch(noop);
}
},
});

View file

@ -0,0 +1,19 @@
import { AnyThreadChannel } from "discord.js";
import z from "zod";
import { noop } from "../../../utils.js";
import { automodAction } from "../helpers.js";
export const UnlockThreadAction = automodAction({
configSchema: z.strictObject({}),
async apply({ pluginData, contexts }) {
const threads = contexts
.filter((c) => c.message?.channel_id)
.map((c) => pluginData.guild.channels.cache.get(c.message!.channel_id))
.filter((c): c is AnyThreadChannel => (c?.isThread() && c?.editable) ?? false);
for (const thread of threads) {
await thread.setLocked(false).catch(noop);
}
},
});