From 3a863f203f61ccb4a80cd25a971e7053452e60f6 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Thu, 16 Feb 2023 22:29:45 +1100 Subject: [PATCH] Glad I didn't pull the untested changes to main bot. --- src/events/messageCreate.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 70514cb..91e1920 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -16,6 +16,7 @@ export default { if (client.bannedWords._content.some((x)=>msgarr.includes(x)) && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId) && client.config.botSwitches.automod){ automodded = true; + const threshold = 30000; message.delete().catch(err=>console.log('bannedWords automod; msg got possibly deleted by another bot.')) message.channel.send('That word is banned here.').then((x)=>setTimeout(()=>x.delete(), 5000)); if (client.repeatedMessages[message.author.id]){ @@ -24,10 +25,7 @@ export default { // reset timeout clearTimeout(client.repeatedMessages[message.author.id].timeout); - client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, 30000); - - // this is the time in which 4 messages have to be sent, in milliseconds (ms) - const threshold = 30000; + client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, threshold); // message mustve been sent after (now - threshold), so purge those that were sent earlier client.repeatedMessages[message.author.id].data = client.repeatedMessages[message.author.id].data.filter((x, i)=>i >= Date.now() - threshold) @@ -39,41 +37,39 @@ export default { // if a spammed message exists; if (spammedMessage){ - // mute - await client.punishments.addPunishment('mute', { time: '30m' }, (client.user as Discord.User).id, 'Automod; Banned words', message.author, message.member as Discord.GuildMember); - // clear their list of long messages delete client.repeatedMessages[message.author.id]; + await client.punishments.addPunishment('mute', { time: '30m' }, (client.user as Discord.User).id, 'Automod; Banned words', message.author, message.member as Discord.GuildMember); } } else { - client.repeatedMessages[message.author.id] = new client.collection(); + client.repeatedMessages[message.author.id] = {data: new client.collection(), timeout: setTimeout(onTimeout, threshold)} client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {cont: 0, ch: message.channelId}); // autodelete after 30 secs - client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, 30000); + client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, threshold); } } if (message.content.toLowerCase().includes('discord.gg/') && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId)) { automodded = true; + const threshold = 60000; message.delete().catch(err=>console.log('advertisement automod; msg got possibly deleted by another bot.')) message.channel.send('Advertising other Discord servers is not allowed.').then(x=>setTimeout(()=>x.delete(), 10000)) if (client.repeatedMessages[message.author.id]){ client.repeatedMessages[message.author.id].data.set(message.createdTimestamp,{cont:1,ch:message.channelId}); clearTimeout(client.repeatedMessages[message.author.id].timeout); - client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, 60000); - const threshold = 60000; + client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, threshold); client.repeatedMessages[message.author.id].data = client.repeatedMessages[message.author.id].data.filter((x, i)=> i >= Date.now() - threshold) - const spammedMessage = client.repeatedMessages[message.author.id]?.data.find((x)=>{ + const spammedMessage = client.repeatedMessages[message.author.id].data.find((x)=>{ return client.repeatedMessages[message.author.id].data.filter((y)=>x.cont === y.cont).size >= 4; }); if (spammedMessage){ - await client.punishments.addPunishment('mute', {time: '1h'}, (client.user as Discord.User).id, 'Automod; Discord advertisement', message.author, message.member as Discord.GuildMember); delete client.repeatedMessages[message.author.id]; + await client.punishments.addPunishment('mute', {time: '1h'}, (client.user as Discord.User).id, 'Automod; Discord advertisement', message.author, message.member as Discord.GuildMember); } }else{ client.repeatedMessages[message.author.id] = new client.collection(); client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {cont: 1, ch: message.channelId}); - client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, 60000); + client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, threshold); } }