This commit is contained in:
Dragon Fire
2021-06-20 20:19:13 -04:00
parent ff93912afc
commit adc9d497ee
+8 -10
View File
@@ -99,15 +99,17 @@ module.exports = class CommandClient extends Client {
return; return;
} }
} }
const throttleAmount = command.throttles.get(msg.author.id) || 0; const throttleAmount = command.throttles.get(msg.author.id);
if (throttleAmount >= command.throttling.usages) { if (throttleAmount && throttleAmount.usages >= command.throttling.usages) {
const timeout = command._timeouts.get(msg.author.id); const timeout = command._timeouts.get(msg.author.id);
await msg.reply( const timeLeft = Math.round((timeout.timeFinish - Date.now()) / 1000);
`Please wait ${getTimeLeft(timeout)} seconds before using the \`${command.name}\` command again.` await msg.reply(`Please wait ${timeLeft} seconds before using the \`${command.name}\` command again.`);
);
return; return;
} }
command.throttles.set(msg.author.id, throttleAmount + 1); command.throttles.set(msg.author.id, {
usages: throttleAmount + 1,
timeFinish: Date.now() + (command.throttling.duration * 1000)
});
if (!throttleAmount) { if (!throttleAmount) {
const timeout = setTimeout(() => command.throttles.delete(msg.author.id), command.throttling.duration * 1000); const timeout = setTimeout(() => command.throttles.delete(msg.author.id), command.throttling.duration * 1000);
command._timeouts.set(msg.author.id, timeout); command._timeouts.set(msg.author.id, timeout);
@@ -232,7 +234,3 @@ module.exports = class CommandClient extends Client {
return buf; return buf;
} }
}; };
function getTimeLeft(timeout) {
return Math.ceil((timeout._idleStart + timeout._idleTimeout - Date.now()) / 1000);
}