few changes in the slowmode command (Bsian)

merge-requests/6/head
DedShot™#9195 2020-05-17 17:46:44 -04:00
parent 4529867037
commit f92d51323b
1 changed files with 10 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { Message } from 'eris'; import { Message, GuildTextableChannel } from 'eris';
import moment, { unitOfTime } from 'moment'; import moment, { unitOfTime } from 'moment';
import { Client, Command } from '../class'; import { Client, Command } from '../class';
@ -13,22 +13,19 @@ export default class Slowmode extends Command {
this.enabled = true; this.enabled = true;
} }
public async run(message: Message, args: string[]) { public async run(message: Message<GuildTextableChannel>, args: string[]) {
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.');
let momentSeconds: number; const Length = args[0].match(/[a-z]+|[^a-z]+/gi);
if (args[0]) { const length = Number(Length[0]);
const Length = args[0].match(/[a-z]+|[^a-z]+/gi); if (Number.isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.');
const length = Number(Length[0]); const unit = Length[1] as unitOfTime.Base;
if (isNaN(length)) return this.error(message.channel, 'Could not determine the slowmode time.'); const momentSeconds: number = moment.duration(length, unit || 's').asSeconds();
const unit = Length[1] as unitOfTime.Base;
momentSeconds = moment.duration(length, unit || 's').asSeconds();
}
if (momentSeconds > 21600) return this.error(message.channel, 'Slowmode cannot be longer than 6 hours.'); if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.');
// @ts-ignore
return message.channel.edit({ rateLimitPerUser: momentSeconds }); return message.channel.edit({ rateLimitPerUser: momentSeconds }).then((c) => message.addReaction(':success:477618704155410452'));
} catch (err) { } catch (err) {
return this.client.util.handleError(err, message, this); return this.client.util.handleError(err, message, this);
} }