regex in constructor
parent
34d363b071
commit
cba3456e37
|
@ -3,6 +3,8 @@ import moment, { unitOfTime } from 'moment';
|
|||
import { Client, Command } from '../class';
|
||||
|
||||
export default class Slowmode extends Command {
|
||||
regex: RegExp;
|
||||
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'slowmode';
|
||||
|
@ -11,16 +13,16 @@ export default class Slowmode extends Command {
|
|||
this.permissions = 1;
|
||||
this.guildOnly = true;
|
||||
this.enabled = true;
|
||||
this.regex = /[a-z]+|[^a-z]+/gi;
|
||||
}
|
||||
|
||||
public async run(message: Message<GuildTextableChannel>, args: string[]) {
|
||||
try {
|
||||
if (!args[0]) return this.error(message.channel, 'This command requires an argument.');
|
||||
|
||||
const [length, unit] = args[0].match(/[a-z]+|[^a-z]+/gi);
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
if (isNaN(length as unknown as number)) return this.error(message.channel, 'Could not determine the slowmode time.');
|
||||
const momentSeconds: number = Number(moment.duration(length, unit as unitOfTime.Base || 's').asSeconds().toFixed());
|
||||
const [length, unit] = args[0].match(this.regex);
|
||||
if (Number.isNaN(Number(length))) return this.error(message.channel, 'Could not determine the slowmode time.');
|
||||
const momentSeconds: number = Math.round(moment.duration(length, unit as unitOfTime.Base || 's').asSeconds());
|
||||
|
||||
if (momentSeconds > 21600 || momentSeconds < 0) return this.error(message.channel, 'Slowmode must be between 0 seconds and 6 hours.');
|
||||
|
||||
|
|
Loading…
Reference in New Issue