From 9aa486a28c482d0cdcf8d915e2e0609722735858 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:26:24 +1000 Subject: [PATCH] Get moyai'd. --- src/components/Automod.ts | 19 +++++++++++++++++++ src/events/messageCreate.ts | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/components/Automod.ts b/src/components/Automod.ts index c428c9b..41ef517 100644 --- a/src/components/Automod.ts +++ b/src/components/Automod.ts @@ -37,6 +37,25 @@ export default class Automoderator { data.timeout = setTimeout(()=>delete client.repeatedMessages[message.author.id], thresholdTime); } } + static isSpam(client:TClient, message:Discord.Message, threshold:number): boolean { + const now = Date.now(); + const time = 30000; + + if (!client.repeatedMessages[message.author.id]) client.repeatedMessages[message.author.id] = {type: 'spam', count: 1, firstTime: now, timeout: null}; + else { + const data = client.repeatedMessages[message.author.id]; + if (now - data.firstTime < time) { + data.count++; + if (data.count >= threshold) return true; + } else { + data.count = 1; + data.firstTime = now; + } + clearTimeout(data.timeout); + data.timeout = setTimeout(()=>delete client.repeatedMessages[message.author.id], time); + } + return false; + } static async imageOnly(message:Discord.Message) { const io_channels = ['468896467688620032']; let deleteReason:string = 'This is an image-only channel and your message did not contain any images.'; diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 831ed62..c62f5ad 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -43,6 +43,17 @@ export default class MessageCreate { await Automoderator.repeatedMessages(client, message, 'mute', 30000, 3, 'bw', '30m', 'Prohibited word spam'); } }, + { + name: 'messageSpam', + check: ()=>Automoderator.isSpam(client, message, 4) && !MessageTool.isStaff(message.member as Discord.GuildMember), + action: async()=>{ + automodded = true; + message.delete().catch(()=>Logger.console('log', `${automodLog}MessageSpam`, automodFailReason)); + message.channel.send('Spamming is not cool, slow down!').then(x=>setTimeout(()=>x.delete(), 15000)); + await Automoderator.repeatedMessages(client, message, 'mute', 30000, 4, 'spam', '30m', 'Message spam'); + delete client.repeatedMessages[message.author.id]; + } + }, { name: 'discordInvite', check: ()=>message.content.toLowerCase().includes('discord.gg/') && !MessageTool.isStaff(message.member as Discord.GuildMember),