fix bug with whitelist checking and error loggin

This commit is contained in:
Erik 2021-06-16 21:38:52 +03:00
parent 269bd70070
commit 29964f3a53
No known key found for this signature in database
GPG Key ID: 7E862371D3409F16

View File

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