Used moment instead of a custom time parser
parent
e892d7a6d6
commit
4529867037
|
@ -1,4 +1,5 @@
|
|||
import { Message } from 'eris';
|
||||
import moment, { unitOfTime } from 'moment';
|
||||
import { Client, Command } from '../class';
|
||||
|
||||
export default class Slowmode extends Command {
|
||||
|
@ -6,7 +7,7 @@ export default class Slowmode extends Command {
|
|||
super(client);
|
||||
this.name = 'slowmode';
|
||||
this.description = 'Set slowmode to a channel.';
|
||||
this.usage = 'slowmode [time] [seconds | minutes | hours]';
|
||||
this.usage = 'slowmode <length[unit]>';
|
||||
this.permissions = 1;
|
||||
this.guildOnly = true;
|
||||
this.enabled = true;
|
||||
|
@ -14,24 +15,22 @@ export default class Slowmode extends Command {
|
|||
|
||||
public async run(message: Message, args: string[]) {
|
||||
try {
|
||||
if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy the slowmode time.***`);
|
||||
if (!args[0]) return this.error(message.channel, 'This command requires an argument.');
|
||||
|
||||
// @ts-ignore
|
||||
let time: number = args[0];
|
||||
if (isNaN(time)) {
|
||||
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} The first argument must be a number.***`);
|
||||
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();
|
||||
}
|
||||
|
||||
if (args[1]) {
|
||||
if (args[1] === 'm' || args[1] === 'min'|| args[1] === 'mins' || args[1] === 'minute' || args[1] === 'minutes') time *= 60;
|
||||
else if (args[1] === 'h' || args[1] === 'hour' || args[1] === 'hours') time = time * 60 * 60;
|
||||
else time = time;
|
||||
}
|
||||
if (time > 21600) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Maximum slow mode is 6 hours.***`);
|
||||
if (momentSeconds > 21600) return this.error(message.channel, 'Slowmode cannot be longer than 6 hours.');
|
||||
// @ts-ignore
|
||||
return message.channel.edit({ rateLimitPerUser: time });
|
||||
return message.channel.edit({ rateLimitPerUser: momentSeconds });
|
||||
} catch (err) {
|
||||
return this.client.util.handleError(err, message, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue