few changes
diff --git a/src/events/messageChecks.ts b/src/events/messageChecks.ts
index 83cfff1..4e99c61 100644
--- a/src/events/messageChecks.ts
+++ b/src/events/messageChecks.ts
@@ -1,101 +1,100 @@
import { LinkCheck, MalwareCheck, NSFWCheck, SizeCheck, TestString, TestImage } from '../automations/unscan.js'
-import readConfig from '../utils/readConfig.js'
import { Message } from 'discord.js'
export const event = 'messageCreate'
-export async function callback(_, message) {
- if (message.author.bot) return
- if (message.channel.type === 'dm') return
+export async function callback(client, message) {
+ if (message.author.bot) return
+ if (message.channel.type === 'dm') return
- let content = message.content.toLowerCase() || ''
- let config = await readConfig(message.guild.id);
+ let content = message.content.toLowerCase() || ''
+ let config = await client.memory.readGuildInfo(message.guild.id);
- if (config.filters.invite.enabled) {
- if (!config.filters.invite.allowed.users.includes(message.author.id) ||
- !config.filters.invite.allowed.channels.includes(message.channel.id) ||
- !message.author.roles.cache.some(role => config.filters.invite.allowed.roles.includes(role.id))
- ) {
- if ((/(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/.test(content))) {
- message.delete();
- return toLog(message, 'invite', content.match(/(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/))
- }
- }
- }
+ if (config.filters.invite.enabled) {
+ if (!config.filters.invite.allowed.users.includes(message.author.id) ||
+ !config.filters.invite.allowed.channels.includes(message.channel.id) ||
+ !message.author.roles.cache.some(role => config.filters.invite.allowed.roles.includes(role.id))
+ ) {
+ if ((/(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/.test(content))) {
+ message.delete();
+ return toLog(message, 'invite', content.match(/(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/))
+ }
+ }
+ }
- let attachments = message.attachments.map(element => element)
- attachments = [...attachments, ...content.match(
- /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi
- ) ?? []].filter(element => (element.url ? element.url : element))
- if (attachments.length > 0) {
- attachments.forEach(async element => {
- if(!message) return;
- let url = element.url ? element.url : element
- if (url != undefined) {
- if(/\.+(webp|png|jpg|jpeg|bmp)/.test(url)) {
- if (config.filters.images.NSFW && !message.channel.nsfw) {
- if (await NSFWCheck(url)) {
- await message.delete()
- return toLog(message, 'NSFW', url)
- }
- }
- if (config.filters.images.size) {
- if(!url.match(/\.+(webp|png|jpg)$/gi)) return
- if(!await SizeCheck(element)) {
- await message.delete()
- return toLog(message, 'size', url)
- }
- }
- }
- if (config.filters.malware) {
- if (!MalwareCheck(url)) {
- await message.delete()
- return toLog(message, 'malware', url)
- }
- }
- }
- });
- }
- if(!message) return;
+ let attachments = message.attachments.map(element => element)
+ attachments = [...attachments, ...content.match(
+ /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi
+ ) ?? []].filter(element => (element.url ? element.url : element))
+ if (attachments.length > 0) {
+ attachments.forEach(async element => {
+ if(!message) return;
+ let url = element.url ? element.url : element
+ if (url != undefined) {
+ if(/\.+(webp|png|jpg|jpeg|bmp)/.test(url)) {
+ if (config.filters.images.NSFW && !message.channel.nsfw) {
+ if (await NSFWCheck(url)) {
+ await message.delete()
+ return toLog(message, 'NSFW', url)
+ }
+ }
+ if (config.filters.images.size) {
+ if(!url.match(/\.+(webp|png|jpg)$/gi)) return
+ if(!await SizeCheck(element)) {
+ await message.delete()
+ return toLog(message, 'size', url)
+ }
+ }
+ }
+ if (config.filters.malware) {
+ if (!MalwareCheck(url)) {
+ await message.delete()
+ return toLog(message, 'malware', url)
+ }
+ }
+ }
+ });
+ }
+ if(!message) return;
- if (await LinkCheck(message)) {
- await message.delete()
- return toLog(message, 'link')
- }
+ if (await LinkCheck(message)) {
+ await message.delete()
+ return toLog(message, 'link')
+ }
- if (config.filters.wordFilter.enabled) {
- let check = TestString(content, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict)
- if(check != "none") {
- await message.delete()
- return toLog(message, 'wordFilter', content)
- }
- }
+ if (config.filters.wordFilter.enabled) {
+ let check = TestString(content, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict)
+ if(check != "none") {
+ await message.delete()
+ return toLog(message, 'wordFilter', content)
+ }
+ }
- if (!config.filters.pings.allowed.users.includes(message.author.id) ||
- !config.filters.pings.allowed.channels.includes(message.channel.id) ||
- !message.author.roles.cache.some(role => config.filters.pings.allowed.roles.includes(role.id))
- ) {
- if (config.filters.pings.everyone && message.mentions.everyone) {
- message.delete();
- return toLog(message, 'mention everyone')
- }
- if (config.filters.pings.roles) {
- for(let role of message.mentions.roles) {
- if(!message) return;
- if (!config.filters.pings.allowed.roles.includes(role.id)) {
- message.delete();
- return toLog(message, 'mention role')
- }
- }
- }
- if(!message) return;
- if (message.mentions.users.size >= config.filters.pings.mass && config.filters.pings.mass) {
- message.delete();
- return toLog(message, 'Mass Pings')
- }
- }
+ if (!config.filters.pings.allowed.users.includes(message.author.id) ||
+ !config.filters.pings.allowed.channels.includes(message.channel.id) ||
+ !message.author.roles.cache.some(role => config.filters.pings.allowed.roles.includes(role.id))
+ ) {
+ if (config.filters.pings.everyone && message.mentions.everyone) {
+ message.delete();
+ return toLog(message, 'mention everyone')
+ }
+ if (config.filters.pings.roles) {
+ for(let role of message.mentions.roles) {
+ if(!message) return;
+ if (!config.filters.pings.allowed.roles.includes(role.id)) {
+ message.delete();
+ return toLog(message, 'mention role')
+ }
+ }
+ }
+ if(!message) return;
+ if (message.mentions.users.size >= config.filters.pings.mass && config.filters.pings.mass) {
+ message.delete();
+ return toLog(message, 'Mass Pings')
+ }
+ }
}
async function toLog(message: Message, reason: string, data?: any) {
- // log(message.guild.id, {type: reason, data: data})
+ // log(message.guild.id, {type: reason, data: data})
}