Fix masked link detection
This commit is contained in:
parent
3abcf23c21
commit
3ae2f5f708
@ -73,8 +73,8 @@ export default class AutoModeration extends Observer implements Initialisable
|
|||||||
|
|
||||||
this.regex = {
|
this.regex = {
|
||||||
invite: /((discord\s*\.?\s*gg\s*)|discord(app)?\.com\/invite)\/\s?(?<code>[a-z0-9]+)/iu,
|
invite: /((discord\s*\.?\s*gg\s*)|discord(app)?\.com\/invite)\/\s?(?<code>[a-z0-9]+)/iu,
|
||||||
linkRegG: /(https?:\/\/(www\.)?)?(?<domain>([a-z0-9-]{1,63}\.)?([a-z0-9-]{1,63})(\.[a-z0-9-]{2,63})(\.[a-z0-9-]{2,63})?)(\/\S*)?/iug,
|
linkRegG: /(https?:\/\/(www\.)?)?(?<domain>([a-z0-9-]{1,63}\.)?([a-z0-9-]{1,63})(\.[a-z0-9-]{2,63})(\.[a-z0-9-]{2,63})?)(\/[^()\s]*)?/iug,
|
||||||
linkReg: /(https?:\/\/(www\.)?)?(?<domain>([a-z0-9-]{1,63}\.)?([a-z0-9-]{1,63})(\.[a-z0-9-]{2,63})(\.[a-z0-9-]{2,63})?)(\/\S*)?/iu,
|
linkReg: /(https?:\/\/(www\.)?)?(?<domain>([a-z0-9-]{1,63}\.)?([a-z0-9-]{1,63})(\.[a-z0-9-]{2,63})(\.[a-z0-9-]{2,63})?)(\/[^()\s]*)?/iu,
|
||||||
mention: /<@!?(?<id>[0-9]{18,22})>/u,
|
mention: /<@!?(?<id>[0-9]{18,22})>/u,
|
||||||
mentionG: /<@!?(?<id>[0-9]{18,22})>/gu,
|
mentionG: /<@!?(?<id>[0-9]{18,22})>/gu,
|
||||||
};
|
};
|
||||||
@ -534,11 +534,13 @@ export default class AutoModeration extends Observer implements Initialisable
|
|||||||
return;
|
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);
|
||||||
|
console.log('matches', matches);
|
||||||
let removedWhitespace = false;
|
let removedWhitespace = false;
|
||||||
if (!matches)
|
if (!matches)
|
||||||
{
|
{
|
||||||
matches = content.replace(/\s/u, '').match(this.regex.linkRegG);
|
matches = content.replace(/\s/u, '').match(this.regex.linkRegG);
|
||||||
removedWhitespace = true;
|
removedWhitespace = true;
|
||||||
|
console.log('secondary matches', matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!matches)
|
if (!matches)
|
||||||
@ -550,6 +552,7 @@ export default class AutoModeration extends Observer implements Initialisable
|
|||||||
for (const match of matches)
|
for (const match of matches)
|
||||||
{
|
{
|
||||||
let domain = match.match(this.regex.linkReg)!.groups?.domain;
|
let domain = match.match(this.regex.linkReg)!.groups?.domain;
|
||||||
|
console.log('domain', domain);
|
||||||
if (!domain)
|
if (!domain)
|
||||||
continue;
|
continue;
|
||||||
domain = domain.toLowerCase();
|
domain = domain.toLowerCase();
|
||||||
@ -586,10 +589,11 @@ export default class AutoModeration extends Observer implements Initialisable
|
|||||||
|
|
||||||
const parts = domain.split('.');
|
const parts = domain.split('.');
|
||||||
const validTld = this.topLevelDomains.find(parts[parts.length - 1]);
|
const validTld = this.topLevelDomains.find(parts[parts.length - 1]);
|
||||||
// console.log(parts, validTld);
|
console.log(parts, validTld);
|
||||||
if (!validTld)
|
if (!validTld)
|
||||||
continue;
|
continue;
|
||||||
const valid = await resolver.validateDomain(domain);
|
const valid = await resolver.validateDomain(domain);
|
||||||
|
console.log('valid domain?', valid);
|
||||||
|
|
||||||
if (removedWhitespace && !match.includes(`${domain}/`))
|
if (removedWhitespace && !match.includes(`${domain}/`))
|
||||||
continue;
|
continue;
|
||||||
|
@ -65,6 +65,9 @@ Command takes no arguments
|
|||||||
[GENERAL_ANONYMOUS]
|
[GENERAL_ANONYMOUS]
|
||||||
》 Anonymous
|
》 Anonymous
|
||||||
|
|
||||||
|
[GENERAL_AUTOLOG]
|
||||||
|
》 Autolog
|
||||||
|
|
||||||
[GENERAL_MESSAGES]
|
[GENERAL_MESSAGES]
|
||||||
》 Messages
|
》 Messages
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user