few changes in the slowmode command (Bsian)
parent
4529867037
commit
f92d51323b
|
@ -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;
|
|
||||||
if (args[0]) {
|
|
||||||
const Length = args[0].match(/[a-z]+|[^a-z]+/gi);
|
const Length = args[0].match(/[a-z]+|[^a-z]+/gi);
|
||||||
const length = Number(Length[0]);
|
const length = Number(Length[0]);
|
||||||
if (isNaN(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 unit = Length[1] as unitOfTime.Base;
|
const unit = Length[1] as unitOfTime.Base;
|
||||||
momentSeconds = moment.duration(length, unit || 's').asSeconds();
|
const momentSeconds: number = 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue