add custom rule channel filtering

This commit is contained in:
janderedev 2022-01-16 15:50:11 +01:00
parent 66babfc40e
commit 1152108621
Signed by: Lea
GPG key ID: 5D5E18ACB990F57A
2 changed files with 12 additions and 0 deletions

View file

@ -11,6 +11,11 @@ async function messageContentTrigger(message: Message, trigger: CustomRuleTrigge
let matched = false; let matched = false;
if (trigger.matcher) { 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) { if (trigger.matcher instanceof RegExp) {
/** /**
* Since users will eventually be able to provide regexes, we need to protect * Since users will eventually be able to provide regexes, we need to protect

View file

@ -10,6 +10,13 @@ class CustomRuleTrigger {
userFilter?: 'user' | 'bot' | 'any'; 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 // The minimum delay between rule matches. If omitted, rule matches every message
timeout?: { timeout?: {
perUser?: number; perUser?: number;