handle decimal numbers in slowmode command (Bsian)
parent
f92d51323b
commit
9b2cebde85
|
@ -17,13 +17,12 @@ export default class Slowmode extends Command {
|
||||||
try {
|
try {
|
||||||
if (!args[0]) return this.error(message.channel, 'This command requires an argument.');
|
if (!args[0]) return this.error(message.channel, 'This command requires an argument.');
|
||||||
|
|
||||||
const Length = args[0].match(/[a-z]+|[^a-z]+/gi);
|
const [length, unit]: Array<string> = args[0].match(/[a-z]+|[^a-z]+/gi);
|
||||||
const length = Number(Length[0]);
|
if (Number.isNaN(Number(length))) return this.error(message.channel, 'Could not determine the slowmode time.');
|
||||||
if (Number.isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.');
|
const momentSeconds: number = moment.duration(length, unit as unitOfTime.Base || 's').asSeconds();
|
||||||
const unit = Length[1] as unitOfTime.Base;
|
|
||||||
const momentSeconds: number = moment.duration(length, unit || 's').asSeconds();
|
|
||||||
|
|
||||||
if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.');
|
if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.');
|
||||||
|
if (momentSeconds % 1) return this.error(message.channel, 'Slowmode cannot have decimals');
|
||||||
|
|
||||||
return message.channel.edit({ rateLimitPerUser: momentSeconds }).then((c) => message.addReaction(':success:477618704155410452'));
|
return message.channel.edit({ rateLimitPerUser: momentSeconds }).then((c) => message.addReaction(':success:477618704155410452'));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in New Issue