From 9b2cebde85a82b1ab905c9dbf5d738dea3ef3377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Mon, 18 May 2020 22:20:05 -0400 Subject: [PATCH] handle decimal numbers in slowmode command (Bsian) --- src/commands/slowmode.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index 8d6f55a..33807c5 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -17,13 +17,12 @@ export default class Slowmode extends Command { try { 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 = Number(Length[0]); - if (Number.isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.'); - const unit = Length[1] as unitOfTime.Base; - const momentSeconds: number = moment.duration(length, unit || 's').asSeconds(); + const [length, unit]: Array = args[0].match(/[a-z]+|[^a-z]+/gi); + if (Number.isNaN(Number(length))) return this.error(message.channel, 'Could not determine the slowmode time.'); + const momentSeconds: number = moment.duration(length, unit as unitOfTime.Base || 's').asSeconds(); 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')); } catch (err) {