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) {