add phishing check

This commit is contained in:
Ryan Cao 2022-05-21 19:49:08 +08:00
parent 0f15e2fb2c
commit a2e1e1a3cf
No known key found for this signature in database
GPG key ID: 528A2C1B6656B97F
4 changed files with 128 additions and 1 deletions

View file

@ -3,8 +3,10 @@ import { commands, aliases } from './commands';
import * as BuildConfig from './constants';
import Filter from 'bad-words';
import { isBad } from './badLinks';
import { green, bold, blue, underline } from 'kleur/colors';
import urlRegex from 'url-regex';
const client = new Client({
intents: [
@ -69,6 +71,34 @@ client.once('ready', async () => {
});
}
{
const urlMatches = e.content.matchAll(urlRegex());
if (urlMatches) {
console.log('Found links in message!');
for (const match of urlMatches) {
console.log('[link]', match[0]);
if (await isBad(match[0])) {
await e.delete();
await e.channel.send({
content: `<@${e.author.id}>`,
embeds: [
{
title: 'Hold on!',
description:
'There seems to be a phishing / malware link in your message.',
color: 'RED',
},
],
});
return;
}
}
}
}
const cmd = e.content.split(' ')[0];
if (!cmd.startsWith('!')) return;
let func = commands[cmd];