From 38f71c6d8d11706da3fd5f60f05443040de7bcec Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Fri, 22 May 2020 20:49:29 +0300 Subject: [PATCH] logs: add excluded_channels --- backend/src/plugins/Logs.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/backend/src/plugins/Logs.ts b/backend/src/plugins/Logs.ts index 399426f3..906db287 100644 --- a/backend/src/plugins/Logs.ts +++ b/backend/src/plugins/Logs.ts @@ -37,6 +37,7 @@ const LogChannel = t.partial({ batch_time: t.number, excluded_users: t.array(t.string), excluded_message_regexes: t.array(TSafeRegex), + excluded_channels: t.array(t.string), }); type TLogChannel = t.TypeOf; @@ -148,10 +149,32 @@ export class LogsPlugin extends ZeppelinPlugin { } } + // If this entry is from an excluded channel, skip it + if (opts.excluded_channels) { + if (type === LogType.MESSAGE_DELETE || type === LogType.MESSAGE_DELETE_BARE) { + if (opts.excluded_channels.includes(data.message.channel.id)) { + continue logChannelLoop; + } + } + + if (type === LogType.MESSAGE_EDIT) { + if (opts.excluded_channels.includes(data.before.channel.id)) { + continue logChannelLoop; + } + } + + if (type === LogType.MESSAGE_SPAM_DETECTED || type === LogType.CENSOR || type === LogType.CLEAN) { + if (opts.excluded_channels.includes(data.channel.id)) { + continue logChannelLoop; + } + } + } + + // If this entry contains a message with an excluded regex, skip it if (type === LogType.MESSAGE_DELETE && opts.excluded_message_regexes && data.message.data.content) { for (const regex of opts.excluded_message_regexes) { if (regex.test(data.message.data.content)) { - return; + continue logChannelLoop; } } } @@ -159,7 +182,7 @@ export class LogsPlugin extends ZeppelinPlugin { if (type === LogType.MESSAGE_EDIT && opts.excluded_message_regexes && data.before.data.content) { for (const regex of opts.excluded_message_regexes) { if (regex.test(data.before.data.content)) { - return; + continue logChannelLoop; } } }