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