diff --git a/src/events/interactionCreate/interactionTypes/handleCommandInteraction/index.ts b/src/events/interactionCreate/interactionTypes/handleCommandInteraction/index.ts index 3701b67..c4004ee 100644 --- a/src/events/interactionCreate/interactionTypes/handleCommandInteraction/index.ts +++ b/src/events/interactionCreate/interactionTypes/handleCommandInteraction/index.ts @@ -27,7 +27,11 @@ export default async function handleCommandInteraction( const { guildCooldown, userCooldown, guildMemberCooldown } = await cooldownManager.checkCooldowns(cooldownItem, guild, user); - if (guildCooldown || userCooldown || guildMemberCooldown) { + if ( + (guildCooldown && guildCooldown.expiresAt > new Date()) || + (userCooldown && userCooldown.expiresAt > new Date()) || + (guildMemberCooldown && guildMemberCooldown.expiresAt > new Date()) + ) { await handleCooldown( interaction, guildCooldown, diff --git a/src/events/messageCreate/components/earnCredits.ts b/src/events/messageCreate/components/earnCredits.ts index 4c00157..e581d8b 100644 --- a/src/events/messageCreate/components/earnCredits.ts +++ b/src/events/messageCreate/components/earnCredits.ts @@ -56,7 +56,10 @@ async function isUserOnCooldown(guild: Guild, author: User): Promise { guild, author ); - return cooldownActive !== null; + + if (!cooldownActive) return false; + + return cooldownActive.expiresAt > new Date(); } async function setCooldown(guild: Guild, user: User) { diff --git a/src/handlers/CooldownManager.ts b/src/handlers/CooldownManager.ts index 55656c0..2a9a2d8 100644 --- a/src/handlers/CooldownManager.ts +++ b/src/handlers/CooldownManager.ts @@ -18,21 +18,19 @@ class CooldownManager { user: user ? { connect: { id: user.id } } : undefined, }; - const { guildCooldown, guildMemberCooldown, userCooldown } = - await this.checkCooldowns(cooldownItem, guild, user); + const existingCooldown = await this.checkCooldown( + cooldownItem, + guild, + user + ); - if (guildCooldown || guildMemberCooldown || userCooldown) { - await prisma.cooldown.updateMany({ + if (existingCooldown) { + await prisma.cooldown.update({ where: { - cooldownItem, - guild: guild ? { id: guild.id } : undefined, - user: user ? { id: user.id } : undefined, + id: existingCooldown.id, }, data: { - cooldownItem, expiresAt, - guildId: guild ? guild.id : undefined, - userId: user ? user.id : undefined, }, }); } else { @@ -62,7 +60,6 @@ class CooldownManager { cooldownItem, guild: guild ? { id: guild.id } : null, user: user ? { id: user.id } : null, - expiresAt: { gte: new Date() }, }; const cooldown = await prisma.cooldown.findFirst({ where }); const duration = Date.now() - start;