From 49b074f98e3f6276f0d2fc00510687cd25dab51f Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Mon, 25 Sep 2023 11:10:21 +0200 Subject: [PATCH] /check-limit: show when the user can use the bot again by default fixes #12 --- src/commands/check-limit.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/commands/check-limit.ts b/src/commands/check-limit.ts index c9e667b..834a8e0 100644 --- a/src/commands/check-limit.ts +++ b/src/commands/check-limit.ts @@ -22,9 +22,20 @@ export default class MyLimit extends Command implements Command { ]; async execute(interaction: ChatInputCommandInteraction) { - let recoveryFor = interaction.options.getInteger("recovery-for", false) ?? 1; + let recoveryFor = interaction.options.getInteger("recovery-for", false); const ephemeral = interaction.options.getBoolean("ephemeral", false) ?? true; + if (recoveryFor === null) { + const userQuota = await config.quota.checkUser( + interaction.user, + interaction, + ); + const remaining = userQuota.quota - userQuota.used; + // NOTE: In order for user to execute the bot again, the used must be lower than quota + // user can't execute if quota and used are equal + // thus why we add 1 here + recoveryFor = remaining >= 0 ? 1 : 1 - remaining; + } if (recoveryFor <= 0) recoveryFor = 1; const userQuotaRecovery = await config.quota.getUserQuotaRecovery(interaction.user, interaction, recoveryFor);