From 1152108621eed80c76628018fe6b29d9878d2ccb Mon Sep 17 00:00:00 2001 From: janderedev Date: Sun, 16 Jan 2022 15:50:11 +0100 Subject: [PATCH] add custom rule channel filtering --- src/bot/modules/custom_rules/message_content_trigger.ts | 5 +++++ src/struct/antispam/CustomRuleTrigger.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/bot/modules/custom_rules/message_content_trigger.ts b/src/bot/modules/custom_rules/message_content_trigger.ts index f1cf472..4321b39 100644 --- a/src/bot/modules/custom_rules/message_content_trigger.ts +++ b/src/bot/modules/custom_rules/message_content_trigger.ts @@ -11,6 +11,11 @@ async function messageContentTrigger(message: Message, trigger: CustomRuleTrigge let matched = false; if (trigger.matcher) { + if (trigger.channelFilter) { + if (trigger.channelFilter.mode == 'WHITELIST' && !trigger.channelFilter.channels.includes(message.channel_id)) return false; + if (trigger.channelFilter.mode == 'BLACKLIST' && trigger.channelFilter.channels.includes(message.channel_id)) return false; + } + if (trigger.matcher instanceof RegExp) { /** * Since users will eventually be able to provide regexes, we need to protect diff --git a/src/struct/antispam/CustomRuleTrigger.ts b/src/struct/antispam/CustomRuleTrigger.ts index 45a935e..6e84e4f 100644 --- a/src/struct/antispam/CustomRuleTrigger.ts +++ b/src/struct/antispam/CustomRuleTrigger.ts @@ -10,6 +10,13 @@ class CustomRuleTrigger { userFilter?: 'user' | 'bot' | 'any'; + channelFilter?: { + // Whitelist only triggers the rule in specified channels, + // Blacklist only triggers the rule in channels not specified + mode: 'WHITELIST'|'BLACKLIST', + channels: string[], + } + // The minimum delay between rule matches. If omitted, rule matches every message timeout?: { perUser?: number;