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

add append, delete options to the edit_post_tags action

This commit is contained in:
Ruby 2024-10-27 12:23:26 +01:00
parent 12652f1613
commit 022313556f
No known key found for this signature in database
GPG key ID: E0BDFAF7AE9E0531

View file

@ -1,4 +1,4 @@
import { PublicThreadChannel } from "discord.js"; import { AnyThreadChannel } from "discord.js";
import z from "zod"; import z from "zod";
import { zSnowflake } from "../../../utils.js"; import { zSnowflake } from "../../../utils.js";
import { automodAction } from "../helpers.js"; import { automodAction } from "../helpers.js";
@ -6,16 +6,24 @@ import { automodAction } from "../helpers.js";
export const EditPostTagsAction = automodAction({ export const EditPostTagsAction = automodAction({
configSchema: z.strictObject({ configSchema: z.strictObject({
tags: z.array(zSnowflake), tags: z.array(zSnowflake),
append: z.boolean().optional(),
delete: z.boolean().optional(),
}), }),
async apply({ pluginData, contexts, actionConfig }) { async apply({ pluginData, contexts, actionConfig }) {
const threads = contexts const threads = contexts
.filter((c) => c.message?.channel_id) .filter((c) => c.message?.channel_id)
.map((c) => pluginData.guild.channels.cache.get(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) { 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);
} }
}, },
}); });