From cba3456e37364c4a54bb75e852a4fe2fc323fb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Tue, 26 May 2020 19:41:00 -0400 Subject: [PATCH] regex in constructor --- src/commands/slowmode.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index 72b302b..00e2490 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -3,6 +3,8 @@ import moment, { unitOfTime } from 'moment'; import { Client, Command } from '../class'; export default class Slowmode extends Command { + regex: RegExp; + constructor(client: Client) { super(client); this.name = 'slowmode'; @@ -11,16 +13,16 @@ export default class Slowmode extends Command { this.permissions = 1; this.guildOnly = true; this.enabled = true; + this.regex = /[a-z]+|[^a-z]+/gi; } public async run(message: Message, args: string[]) { try { if (!args[0]) return this.error(message.channel, 'This command requires an argument.'); - const [length, unit] = args[0].match(/[a-z]+|[^a-z]+/gi); - // eslint-disable-next-line no-restricted-globals - if (isNaN(length as unknown as number)) return this.error(message.channel, 'Could not determine the slowmode time.'); - const momentSeconds: number = Number(moment.duration(length, unit as unitOfTime.Base || 's').asSeconds().toFixed()); + const [length, unit] = args[0].match(this.regex); + if (Number.isNaN(Number(length))) return this.error(message.channel, 'Could not determine the slowmode time.'); + const momentSeconds: number = Math.round(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.');