From ca3f926cb89543554bec776df90c97c1f05a222b Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:02:30 +1100 Subject: [PATCH] bruh.exe has stopped responding. --- src/components/CacheServer.ts | 1 + src/events/interactionCreate.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/CacheServer.ts b/src/components/CacheServer.ts index c755a45..e47280d 100644 --- a/src/components/CacheServer.ts +++ b/src/components/CacheServer.ts @@ -29,6 +29,7 @@ export default class CacheServer { if (jsonMode) return await RedisClient.json.set(key, '.', value); else return await RedisClient.set(key, JSON.stringify(value)); } + /** @param time Cache expiration in seconds */ public static expiry = async(key:any, time:number)=>await RedisClient.expire(key, time); // NOTE: time is in seconds, not milliseconds -- you know what you did wrong public static delete = async(key:any)=>await RedisClient.del(key); public static init() { diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 80bc9c1..0d574f6 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -2,6 +2,7 @@ import Discord from 'discord.js'; import TClient from '../client.js'; import Logger from '../helpers/Logger.js'; import MessageTool from '../helpers/MessageTool.js'; +import CacheServer from '../components/CacheServer.js'; const logPrefix = 'Interaction'; export default class InteractionCreate { static async run(client:TClient, interaction:Discord.BaseInteraction){ @@ -41,17 +42,24 @@ export default class InteractionCreate { return console.log('An error occurred while running autocomplete:\n', error) } } - static handleButton(client:TClient, interaction:Discord.ButtonInteraction<'cached'>) { + static async handleButton(client:TClient, interaction:Discord.ButtonInteraction<'cached'>) { + const time = Date.now(); if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){ const RoleID = interaction.customId.replace('reaction-',''); + let key = `${interaction.user.id}:role_room`; + const isRatelimited = await CacheServer.get(key, false); + const timeDiff = time - isRatelimited; + if (timeDiff < 5000) return interaction.reply({content: 'You are on **__cooldown__**, please avoid spam-clicking next time.\n\n*This system is put in place due to selfbots.. I\'m sorry!*', ephemeral: true}); + const MFFarm1 = '1149139369433776269'; const MFFarm2 = '1149139583729160325'; if (interaction.member.roles.cache.has(RoleID)) interaction.member.roles.remove(RoleID, 'Button Role').then(()=>interaction.reply({content: `You have been removed from <@&${RoleID}>`, ephemeral: true})); - else interaction.member.roles.add(RoleID, 'Button Role').then(()=>{ + else interaction.member.roles.add(RoleID, 'Button Role').then(async()=>{ this.roleConflictHandler(interaction, MFFarm1, MFFarm2, RoleID); - interaction.reply({content: `You have been added to <@&${RoleID}>`, ephemeral: true, fetchReply: true}) + await interaction.reply({content: `You have been added to <@&${RoleID}>`, ephemeral: true, fetchReply: true}); + CacheServer.set(key, time, false).then(()=>CacheServer.expiry(key, 10)); }); } else if (interaction.customId.includes('deleteEvalEmbed')) { if (!client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'You are not whitelisted, therefore you cannot delete this message.', ephemeral: true});