diff --git a/backend/src/plugins/Automod/actions/editPostTags.ts b/backend/src/plugins/Automod/actions/editPostTags.ts index 19603bfb..1f3aa7f5 100644 --- a/backend/src/plugins/Automod/actions/editPostTags.ts +++ b/backend/src/plugins/Automod/actions/editPostTags.ts @@ -1,4 +1,4 @@ -import { PublicThreadChannel } from "discord.js"; +import { AnyThreadChannel } from "discord.js"; import z from "zod"; import { zSnowflake } from "../../../utils.js"; import { automodAction } from "../helpers.js"; @@ -6,16 +6,24 @@ 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 PublicThreadChannel => (c?.isThread() && c?.parent?.isThreadOnly() && c?.editable) ?? false); + .filter((c): c is AnyThreadChannel => (c?.isThread() && c?.parent?.isThreadOnly() && c?.editable) ?? false); + const tags: string[] = actionConfig.tags; for (const thread of threads) { - await thread.setAppliedTags(actionConfig.tags); + const finalTags = actionConfig.append + ? thread.appliedTags.concat(tags) + : actionConfig.delete + ? thread.appliedTags.filter((id) => !tags.includes(id)) + : tags; + await thread.setAppliedTags(finalTags); } }, });