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:
parent
12652f1613
commit
022313556f
1 changed files with 11 additions and 3 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue