3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

feat: add lock unlock thread and edit forum post tags actions

This commit is contained in:
Ruby 2024-10-25 13:09:13 +02:00
parent eb5fda8d19
commit 12652f1613
No known key found for this signature in database
GPG key ID: E0BDFAF7AE9E0531
5 changed files with 70 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,21 @@
import { PublicThreadChannel } 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),
}),
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 PublicThreadChannel => (c?.isThread() && c?.parent?.isThreadOnly() && c?.editable) ?? false);
for (const thread of threads) {
await thread.setAppliedTags(actionConfig.tags);
}
},
});

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);
}
},
});