From f92d51323b00043789ad79dc4d31a0485008ffa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Sun, 17 May 2020 17:46:44 -0400 Subject: [PATCH] few changes in the slowmode command (Bsian) --- src/commands/slowmode.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts index b842182..8d6f55a 100644 --- a/src/commands/slowmode.ts +++ b/src/commands/slowmode.ts @@ -1,4 +1,4 @@ -import { Message } from 'eris'; +import { Message, GuildTextableChannel } from 'eris'; import moment, { unitOfTime } from 'moment'; import { Client, Command } from '../class'; @@ -13,22 +13,19 @@ export default class Slowmode extends Command { this.enabled = true; } - public async run(message: Message, args: string[]) { + public async run(message: Message, args: string[]) { try { if (!args[0]) return this.error(message.channel, 'This command requires an argument.'); - let momentSeconds: number; - if (args[0]) { - const Length = args[0].match(/[a-z]+|[^a-z]+/gi); - const length = Number(Length[0]); - if (isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.'); - const unit = Length[1] as unitOfTime.Base; - momentSeconds = moment.duration(length, unit || 's').asSeconds(); - } + 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(); - if (momentSeconds > 21600) return this.error(message.channel, 'Slowmode cannot be longer than 6 hours.'); - // @ts-ignore - return message.channel.edit({ rateLimitPerUser: momentSeconds }); + if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.'); + + return message.channel.edit({ rateLimitPerUser: momentSeconds }).then((c) => message.addReaction(':success:477618704155410452')); } catch (err) { return this.client.util.handleError(err, message, this); }