Used moment instead of a custom time parser
parent
e892d7a6d6
commit
4529867037
|
@ -1,4 +1,5 @@
|
||||||
import { Message } from 'eris';
|
import { Message } from 'eris';
|
||||||
|
import moment, { unitOfTime } from 'moment';
|
||||||
import { Client, Command } from '../class';
|
import { Client, Command } from '../class';
|
||||||
|
|
||||||
export default class Slowmode extends Command {
|
export default class Slowmode extends Command {
|
||||||
|
@ -6,7 +7,7 @@ export default class Slowmode extends Command {
|
||||||
super(client);
|
super(client);
|
||||||
this.name = 'slowmode';
|
this.name = 'slowmode';
|
||||||
this.description = 'Set slowmode to a channel.';
|
this.description = 'Set slowmode to a channel.';
|
||||||
this.usage = 'slowmode [time] [seconds | minutes | hours]';
|
this.usage = 'slowmode <length[unit]>';
|
||||||
this.permissions = 1;
|
this.permissions = 1;
|
||||||
this.guildOnly = true;
|
this.guildOnly = true;
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
|
@ -14,22 +15,20 @@ export default class Slowmode extends Command {
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
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 momentSeconds: number;
|
||||||
let time: number = args[0];
|
if (args[0]) {
|
||||||
if (isNaN(time)) {
|
const Length = args[0].match(/[a-z]+|[^a-z]+/gi);
|
||||||
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} The first argument must be a number.***`);
|
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 (momentSeconds > 21600) return this.error(message.channel, 'Slowmode cannot be longer than 6 hours.');
|
||||||
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.***`);
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return message.channel.edit({ rateLimitPerUser: time });
|
return message.channel.edit({ rateLimitPerUser: momentSeconds });
|
||||||
} 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