/check-limit: show when the user can use the bot again by default

fixes #12
This commit is contained in:
Wroclaw 2023-09-25 11:10:21 +02:00
parent 80f4f18eab
commit 49b074f98e

View file

@ -22,9 +22,20 @@ export default class MyLimit extends Command implements Command {
]; ];
async execute(interaction: ChatInputCommandInteraction) { 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; 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; if (recoveryFor <= 0) recoveryFor = 1;
const userQuotaRecovery = await config.quota.getUserQuotaRecovery(interaction.user, interaction, recoveryFor); const userQuotaRecovery = await config.quota.getUserQuotaRecovery(interaction.user, interaction, recoveryFor);