diff --git a/backend/src/plugins/Tags/TagsPlugin.ts b/backend/src/plugins/Tags/TagsPlugin.ts index 83f00116..b7b146f3 100644 --- a/backend/src/plugins/Tags/TagsPlugin.ts +++ b/backend/src/plugins/Tags/TagsPlugin.ts @@ -19,6 +19,7 @@ import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin"; import { mapToPublicFn } from "../../pluginUtils"; import { renderTagBody } from "./util/renderTagBody"; import { findTagByName } from "./util/findTagByName"; +import { StrictValidationError } from "src/validatorUtils"; const defaultOptions: PluginOptions = { config: { @@ -29,6 +30,7 @@ const defaultOptions: PluginOptions = { global_tag_cooldown: null, user_cooldown: null, global_cooldown: null, + auto_delete_command: false, categories: {}, @@ -71,6 +73,28 @@ export const TagsPlugin = zeppelinGuildPlugin()("tags", { findTagByName: mapToPublicFn(findTagByName), }, + configPreprocessor(options) { + if (options.config.delete_with_command && options.config.auto_delete_command) { + throw new StrictValidationError([ + `Cannot have both (global) delete_with_command and global_delete_invoke enabled`, + ]); + } + + // Check each category for conflicting options + if (options.config?.categories) { + for (const [name, opts] of Object.entries(options.config.categories)) { + const cat = options.config.categories[name]; + if (cat.delete_with_command && cat.auto_delete_command) { + throw new StrictValidationError([ + `Cannot have both (category specific) delete_with_command and category_delete_invoke enabled at `, + ]); + } + } + } + + return options; + }, + onLoad(pluginData) { const { state, guild } = pluginData; diff --git a/backend/src/plugins/Tags/types.ts b/backend/src/plugins/Tags/types.ts index f22e0eac..15b0ce5b 100644 --- a/backend/src/plugins/Tags/types.ts +++ b/backend/src/plugins/Tags/types.ts @@ -16,6 +16,7 @@ export const TagCategory = t.type({ user_category_cooldown: tNullable(t.union([t.string, t.number])), // Per user, per tag category global_tag_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per tag global_category_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per category + auto_delete_command: tNullable(t.boolean), // Any tag, per tag category tags: t.record(t.string, Tag), @@ -31,6 +32,7 @@ export const ConfigSchema = t.type({ global_tag_cooldown: tNullable(t.union([t.string, t.number])), // Any user, per tag user_cooldown: tNullable(t.union([t.string, t.number])), // Per user global_cooldown: tNullable(t.union([t.string, t.number])), // Any tag use + auto_delete_command: t.boolean, // Any tag categories: t.record(t.string, TagCategory), diff --git a/backend/src/plugins/Tags/util/onMessageCreate.ts b/backend/src/plugins/Tags/util/onMessageCreate.ts index e2dbb961..431d4155 100644 --- a/backend/src/plugins/Tags/util/onMessageCreate.ts +++ b/backend/src/plugins/Tags/util/onMessageCreate.ts @@ -1,7 +1,7 @@ import { TagsPluginType } from "../types"; import { SavedMessage } from "../../../data/entities/SavedMessage"; import { GuildPluginData } from "knub"; -import { convertDelayStringToMS, resolveMember, tStrictMessageContent } from "../../../utils"; +import { convertDelayStringToMS, noop, resolveMember, tStrictMessageContent } from "../../../utils"; import { validate } from "../../../validatorUtils"; import { LogType } from "../../../data/LogType"; import { TextChannel } from "eris"; @@ -108,4 +108,10 @@ export async function onMessageCreate(pluginData: GuildPluginData