linkfilter debugging

This commit is contained in:
Erik 2022-06-28 18:48:52 +03:00
parent 5904f4cd47
commit 5065b85952
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -515,9 +515,11 @@ module.exports = class AutoModeration extends Observer {
if (!matches) return; if (!matches) return;
let remove = false; let remove = false;
const filterResult = {}; const filterResult = {};
let log = 'Link filter debug:';
for (const match of matches) { for (const match of matches) {
const { domain } = match.match(linkReg).groups; const { domain } = match.match(linkReg).groups;
log += `\nMatched link ${match}: `;
const predicate = (dom) => { const predicate = (dom) => {
return dom.includes(domain) || domain.includes(dom); return dom.includes(domain) || domain.includes(dom);
@ -534,7 +536,10 @@ module.exports = class AutoModeration extends Observer {
remove = true; remove = true;
break; break;
} else if (whitelistMode) { } else if (whitelistMode) {
if (whitelist.some(predicate)) continue; if (whitelist.some(predicate)) {
log += 'in whitelist';
continue;
}
const valid = await resolver.validateDomain(domain); const valid = await resolver.validateDomain(domain);
if (!valid) { if (!valid) {
this.client.emit('linkFilterWarn', { message: guild.format('LINKFILTER_WARN', { domain }) }); this.client.emit('linkFilterWarn', { message: guild.format('LINKFILTER_WARN', { domain }) });
@ -549,6 +554,9 @@ module.exports = class AutoModeration extends Observer {
} }
log += `\nFilter result: ${inspect(filterResult)}\nRemove: ${remove}`;
this.logger.debug(log);
if (!remove) return; if (!remove) return;
msg.filtered = filterResult; msg.filtered = filterResult;
filterResult.filter = 'link'; filterResult.filter = 'link';