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:
parent
eb5fda8d19
commit
12652f1613
5 changed files with 70 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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>>;
|
||||
|
|
21
backend/src/plugins/Automod/actions/editPostTags.ts
Normal file
21
backend/src/plugins/Automod/actions/editPostTags.ts
Normal 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);
|
||||
}
|
||||
},
|
||||
});
|
19
backend/src/plugins/Automod/actions/lockThread.ts
Normal file
19
backend/src/plugins/Automod/actions/lockThread.ts
Normal 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);
|
||||
}
|
||||
},
|
||||
});
|
19
backend/src/plugins/Automod/actions/unlockThread.ts
Normal file
19
backend/src/plugins/Automod/actions/unlockThread.ts
Normal 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);
|
||||
}
|
||||
},
|
||||
});
|
Loading…
Add table
Reference in a new issue