diff --git a/backend/src/plugins/Automod/actions/archiveThread.ts b/backend/src/plugins/Automod/actions/archiveThread.ts index ca1e6242..f0532a93 100644 --- a/backend/src/plugins/Automod/actions/archiveThread.ts +++ b/backend/src/plugins/Automod/actions/archiveThread.ts @@ -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); } }, diff --git a/backend/src/plugins/Automod/actions/availableActions.ts b/backend/src/plugins/Automod/actions/availableActions.ts index e499a42d..4c65f846 100644 --- a/backend/src/plugins/Automod/actions/availableActions.ts +++ b/backend/src/plugins/Automod/actions/availableActions.ts @@ -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>; diff --git a/backend/src/plugins/Automod/actions/editPostTags.ts b/backend/src/plugins/Automod/actions/editPostTags.ts new file mode 100644 index 00000000..19603bfb --- /dev/null +++ b/backend/src/plugins/Automod/actions/editPostTags.ts @@ -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); + } + }, +}); diff --git a/backend/src/plugins/Automod/actions/lockThread.ts b/backend/src/plugins/Automod/actions/lockThread.ts new file mode 100644 index 00000000..ff98020b --- /dev/null +++ b/backend/src/plugins/Automod/actions/lockThread.ts @@ -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); + } + }, +}); diff --git a/backend/src/plugins/Automod/actions/unlockThread.ts b/backend/src/plugins/Automod/actions/unlockThread.ts new file mode 100644 index 00000000..51c352c8 --- /dev/null +++ b/backend/src/plugins/Automod/actions/unlockThread.ts @@ -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); + } + }, +});