pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 1 | import { LinkCheck, MalwareCheck, NSFWCheck, SizeCheck, TestString, TestImage } from '../automations/unscan.js' |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 2 | import { Message } from 'discord.js' |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 3 | import client from '../utils/client.js' |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 4 | |
| 5 | export const event = 'messageCreate' |
| 6 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 7 | export async function callback(client, message) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 8 | const { log, NucleusColors, entry, renderUser } = client.logger |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 9 | if (message.author.bot) return |
| 10 | if (message.channel.type === 'dm') return |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 11 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 12 | let content = message.content.toLowerCase() || '' |
| 13 | let config = await client.memory.readGuildInfo(message.guild.id); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 14 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 15 | if (config.filters.invite.enabled) { |
| 16 | if (!config.filters.invite.allowed.users.includes(message.author.id) || |
| 17 | !config.filters.invite.allowed.channels.includes(message.channel.id) || |
| 18 | !message.author.roles.cache.some(role => config.filters.invite.allowed.roles.includes(role.id)) |
| 19 | ) { |
| 20 | if ((/(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/.test(content))) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 21 | return message.delete(); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 22 | } |
| 23 | } |
| 24 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 25 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 26 | let attachments = message.attachments.map(element => element) |
| 27 | attachments = [...attachments, ...content.match( |
| 28 | /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi |
| 29 | ) ?? []].filter(element => (element.url ? element.url : element)) |
| 30 | if (attachments.length > 0) { |
| 31 | attachments.forEach(async element => { |
| 32 | if(!message) return; |
| 33 | let url = element.url ? element.url : element |
| 34 | if (url != undefined) { |
| 35 | if(/\.+(webp|png|jpg|jpeg|bmp)/.test(url)) { |
| 36 | if (config.filters.images.NSFW && !message.channel.nsfw) { |
| 37 | if (await NSFWCheck(url)) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 38 | return await message.delete() |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | if (config.filters.images.size) { |
| 42 | if(!url.match(/\.+(webp|png|jpg)$/gi)) return |
| 43 | if(!await SizeCheck(element)) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 44 | return await message.delete() |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | } |
| 48 | if (config.filters.malware) { |
| 49 | if (!MalwareCheck(url)) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 50 | return await message.delete() |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | } |
| 54 | }); |
| 55 | } |
| 56 | if(!message) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 57 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 58 | if (await LinkCheck(message)) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 59 | return await message.delete() |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 60 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 61 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 62 | if (config.filters.wordFilter.enabled) { |
| 63 | let check = TestString(content, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict) |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 64 | if(check !== null) { |
| 65 | return await message.delete() |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 66 | } |
| 67 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 68 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 69 | if (!config.filters.pings.allowed.users.includes(message.author.id) || |
| 70 | !config.filters.pings.allowed.channels.includes(message.channel.id) || |
| 71 | !message.author.roles.cache.some(role => config.filters.pings.allowed.roles.includes(role.id)) |
| 72 | ) { |
| 73 | if (config.filters.pings.everyone && message.mentions.everyone) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 74 | return message.delete(); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 75 | } |
| 76 | if (config.filters.pings.roles) { |
| 77 | for(let role of message.mentions.roles) { |
| 78 | if(!message) return; |
| 79 | if (!config.filters.pings.allowed.roles.includes(role.id)) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 80 | return message.delete(); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | } |
| 84 | if(!message) return; |
| 85 | if (message.mentions.users.size >= config.filters.pings.mass && config.filters.pings.mass) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 86 | return message.delete(); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 87 | } |
| 88 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 89 | } |