From 29964f3a53c4318e1c37ea25831c517af0e63996 Mon Sep 17 00:00:00 2001 From: Navy Date: Wed, 16 Jun 2021 21:38:52 +0300 Subject: [PATCH] fix bug with whitelist checking and error loggin --- .../components/observers/Automoderation.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/structure/client/components/observers/Automoderation.js b/structure/client/components/observers/Automoderation.js index 2048cf2..17189bb 100644 --- a/structure/client/components/observers/Automoderation.js +++ b/structure/client/components/observers/Automoderation.js @@ -111,7 +111,7 @@ module.exports = class AutoModeration extends Observer { try { // NOTE: Remove try-catch after debug content = FilterUtil.normalise(Util.removeMarkdown(msg.cleanContent)); } catch (err) { - this.client.logger.debug(log); + this.client.logger.error(`Error in message filtering:\n${err.stack}\n${msg.cleanContent}`); return; } log += `\nNormalised: ${content}`; @@ -182,7 +182,7 @@ module.exports = class AutoModeration extends Observer { for (const reg of regex) { - const match = content.match(new RegExp(`(?:^|\\s)(${reg})`, 'iu')); // (?:^|\\s) |un + const match = content.toLowerCase().match(new RegExp(`(?:^|\\s)(${reg})`, 'iu')); // (?:^|\\s) |un if (match) { //log += `\next reg: ${tmp}`; @@ -192,7 +192,7 @@ module.exports = class AutoModeration extends Observer { try { // This is for debugging only inWL = this.whitelist.find(fullWord); } catch (err) { - this.client.logger.debug(fullWord, match[0], words); + this.client.logger.debug(fullWord, match[1], words); } if (inWL || whitelist.some((word) => word === fullWord)) continue; @@ -200,7 +200,7 @@ module.exports = class AutoModeration extends Observer { filterResult = { match: fullWord, matched: true, - _matcher: match[0].toLowerCase(), + _matcher: match[1].toLowerCase(), matcher: `Regex: __${reg}__`, type: 'regex' }; @@ -316,7 +316,13 @@ module.exports = class AutoModeration extends Observer { const logChannel = await guild.resolveChannel(_logChannel); const msg = edited || message; if (!msg.content) return; - const content = FilterUtil.normalise(msg.cleanContent); + let content = null; + try { + content = FilterUtil.normalise(msg.cleanContent); + } catch (err) { + this.client.logger.error(`Error in message flag:\n${err.stack}\n${msg.cleanContent}`); + return; + } let match = null; for (const reg of words) {