From 02c33a0e64a4f6c7ee36f50cf2d5a06beb4818a4 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:21:47 +1100 Subject: [PATCH] Refactor the automodRules --- src/events/messageCreate.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 82cd601..106d53a 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -22,8 +22,9 @@ export default class MessageCreate { if (client.config.botSwitches.automod && !message.member?.roles.cache.has(client.config.dcServer.roles.dcmod) && !message.member?.roles.cache.has(client.config.dcServer.roles.admin) && message.guildId === client.config.dcServer.id) { const automodFailReason = 'msg got possibly deleted by another bot.'; const automodLog = 'Automod:'; - const automodRules = { - phishingDetection: { + const automodRules = [ + { + name: 'phishingDetection', check: async()=>await __PRIVATE__.phishingDetection(message), action: async()=>{ automodded = true; @@ -32,7 +33,8 @@ export default class MessageCreate { await Automoderator.repeatedMessages(client, message, 'softban', 60000, 3, 'phish', '15m', 'Phishing scam link'); } }, - prohibitedWords: { + { + name: 'prohibitedWords', check: async()=>await client.prohibitedWords.findWord(Automoderator.scanMsg(message)), action: async()=>{ automodded = true; @@ -41,7 +43,8 @@ export default class MessageCreate { await Automoderator.repeatedMessages(client, message, 'mute', 30000, 3, 'bw', '30m', 'Prohibited word spam'); } }, - discordInvite: { + { + name: 'discordInvite', check: ()=>message.content.toLowerCase().includes('discord.gg/') && !MessageTool.isStaff(message.member as Discord.GuildMember), action: async()=>{ const validInvite = await client.fetchInvite(message.content.split(' ').find(x=>x.includes('discord.gg/'))).catch(()=>null); @@ -53,14 +56,15 @@ export default class MessageCreate { } } }, - imageOnly: { + { + name: 'imageOnly', check: ()=>!MessageTool.isStaff(message.member as Discord.GuildMember), action: async()=>await Automoderator.imageOnly(message) } - }; + ]; - for (const rule of Object.values(automodRules)) { - if (!automodded && await rule.check()) { + for (const rule of automodRules) { + if (!automodded && rule.name && await rule.check()) { await rule.action(); break; }