diff --git a/backend/src/plugins/Automod/Automod.ts b/backend/src/plugins/Automod/Automod.ts index 609cdb83..d6b91400 100644 --- a/backend/src/plugins/Automod/Automod.ts +++ b/backend/src/plugins/Automod/Automod.ts @@ -60,10 +60,12 @@ import { TMatchWordsTrigger, TMemberJoinTrigger, TRule, + TMatchAttachmentTypeTrigger, } from "./types"; import { pluginInfo } from "./info"; import { ERRORS, RecoverablePluginError } from "../../RecoverablePluginError"; import Timeout = NodeJS.Timeout; +import { StrictValidationError } from "src/validatorUtils"; const unactioned = (action: TextRecentAction | OtherRecentAction) => !action.actioned; @@ -116,6 +118,19 @@ const defaultMatchLinksTrigger: Partial = { match_custom_status: false, }; +const defaultMatchAttachmentTypeTrigger: Partial = { + filetype_blacklist: [], + blacklist_enabled: false, + filetype_whitelist: [], + whitelist_enabled: false, + match_messages: true, + match_embeds: true, + match_visible_names: false, + match_usernames: false, + match_nicknames: false, + match_custom_status: false, +}; + const defaultTextSpamTrigger: Partial> = { per_channel: true, }; @@ -130,6 +145,7 @@ const defaultTriggers = { match_regex: defaultMatchRegexTrigger, match_invites: defaultMatchInvitesTrigger, match_links: defaultMatchLinksTrigger, + match_attachment_type: defaultMatchAttachmentTypeTrigger, message_spam: defaultTextSpamTrigger, mention_spam: defaultTextSpamTrigger, link_spam: defaultTextSpamTrigger, @@ -249,6 +265,21 @@ export class AutomodPlugin extends ZeppelinPlugin`, + ]); + } else if (!white && !black) { + throw new StrictValidationError([ + `Must have either blacklist or whitelist enabled at rule <${rule.name}/match_attachment_type>`, + ]); + } + } } } @@ -457,6 +488,23 @@ export class AutomodPlugin extends ZeppelinPlugin { + return this.evaluateMatchAttachmentTypeTrigger(trigger.match_attachment_type, msg); + }); + if (match) return { ...match, trigger: "match_attachment_type" } as TextTriggerMatchResult; + } + if (trigger.message_spam) { const match = this.matchTextSpamTrigger(RecentActionType.Message, trigger.message_spam, msg); if (match) return { ...match, rule, trigger: "message_spam" }; @@ -1319,6 +1374,8 @@ export class AutomodPlugin extends ZeppelinPlugin; +export const MatchAttachmentTypeTrigger = t.type({ + filetype_blacklist: t.array(t.string), + blacklist_enabled: t.boolean, + filetype_whitelist: t.array(t.string), + whitelist_enabled: t.boolean, + match_messages: t.boolean, + match_embeds: t.boolean, + match_visible_names: t.boolean, + match_usernames: t.boolean, + match_nicknames: t.boolean, + match_custom_status: t.boolean, +}); +export type TMatchAttachmentTypeTrigger = t.TypeOf; + export const BaseSpamTrigger = t.type({ amount: t.number, within: t.string, @@ -280,6 +294,7 @@ export const Rule = t.type({ match_regex: tNullable(MatchRegexTrigger), match_invites: tNullable(MatchInvitesTrigger), match_links: tNullable(MatchLinksTrigger), + match_attachment_type: tNullable(MatchAttachmentTypeTrigger), message_spam: tNullable(MessageSpamTrigger), mention_spam: tNullable(MentionSpamTrigger), link_spam: tNullable(LinkSpamTrigger),