improve linkfilter

This commit is contained in:
Erik 2022-07-13 11:42:17 +03:00
parent 22bcb8ce89
commit e261debb69
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -441,7 +441,12 @@ module.exports = class AutoModeration extends Observer {
if (!msg.content) return; if (!msg.content) return;
const content = msg.content.split('').join(''); //Copy the string... const content = msg.content.split('').join(''); //Copy the string...
let matches = content.match(this.regex.linkRegG); let matches = content.match(this.regex.linkRegG);
if (!matches) matches = content.replace(/\s/u, '').match(this.regex.linkRegG); let removedWhitespace = false;
if (!matches) {
matches = content.replace(/\s/u, '').match(this.regex.linkRegG);
removedWhitespace = true;
}
if (!matches) return; if (!matches) return;
let remove = false; let remove = false;
const filterResult = {}; const filterResult = {};
@ -480,6 +485,9 @@ module.exports = class AutoModeration extends Observer {
// console.log(parts, validTld); // console.log(parts, validTld);
if (!validTld) continue; if (!validTld) continue;
const valid = await resolver.validateDomain(domain); const valid = await resolver.validateDomain(domain);
if (removedWhitespace && !match.includes(`${domain}/`)) continue;
if (!valid) { if (!valid) {
if (match.includes(`${domain}/`)) this.client.emit('linkFilterWarn', { guild: wrapper, message: wrapper.format('LINKFILTER_WARN', { domain, link: match }) }); if (match.includes(`${domain}/`)) this.client.emit('linkFilterWarn', { guild: wrapper, message: wrapper.format('LINKFILTER_WARN', { domain, link: match }) });
continue; continue;