Drop: Fix cooldown formatting (fixes #15)
Formatted cooldown strings are now properly pluralized trimmed for zero values and also include seconds.
This commit is contained in:
@@ -18,7 +18,7 @@ module.exports = {
|
||||
const cooldowns = await UserUtils.getCooldowns(user);
|
||||
if (cooldowns.dropCooldown > 0 && permissionLevel < 2) {
|
||||
interaction.editReply({
|
||||
content: `You can drop more cards in ${Math.floor((cooldowns.dropCooldown % 3600000) / 60000)} minutes`,
|
||||
content: `You can't drop a card yet! ${cooldowns.dropCooldownFormatted}`,
|
||||
ephemeral: false
|
||||
});
|
||||
return;
|
||||
@@ -108,7 +108,7 @@ module.exports = {
|
||||
let permissionLevel = await UserUtils.getPermissionLevel(i.member);
|
||||
if (cooldowns.pullCooldown > 0 && permissionLevel < 2) {
|
||||
i.reply({
|
||||
content: `You can claim more cards in ${Math.floor((cooldowns.pullCooldown % 3600000) / 60000)} minutes`,
|
||||
content: `You can't claim a card yet! ${cooldowns.pullCooldownFormatted}`,
|
||||
ephemeral: false
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -48,9 +48,13 @@ module.exports = {
|
||||
reply[`next${key}Timestamp`] = user[`next${key}`].getTime();
|
||||
let cooldown = Math.max(reply[`next${key}Timestamp`] - reply['now'], 0);
|
||||
reply[`${key.toLowerCase()}Cooldown`] = cooldown;
|
||||
let hours = Math.floor(cooldown / 3600000);
|
||||
let minutes = Math.floor((cooldown % 3600000) / 60000);
|
||||
let seconds = Math.floor((cooldown % 60000) / 1000);
|
||||
if (cooldown > 0) {
|
||||
reply[`${key.toLowerCase()}CooldownFormatted`] = `Next ${key} in ${Math.floor(cooldown / 3600000)} hours ` +
|
||||
`and ${Math.floor((cooldown % 3600000) / 60000)} minutes`;
|
||||
reply[`${key.toLowerCase()}CooldownFormatted`] = `Next ${key} in ` + (hours >= 1 ? `${hours} hour${hours > 1 ? 's' : ''} ` : '') +
|
||||
`${minutes} minute${minutes > 1 ? 's' : ''} ` +
|
||||
`${seconds} second${seconds > 1 ? 's' : ''}`;
|
||||
} else {
|
||||
reply[`${key.toLowerCase()}CooldownFormatted`] = `${key} Ready!`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user