diff --git a/src/commands/slowmode.ts b/src/commands/slowmode.ts new file mode 100644 index 0000000..8713f3c --- /dev/null +++ b/src/commands/slowmode.ts @@ -0,0 +1,37 @@ +import { Message } from 'eris'; +import { Client, Command } from '../class'; + +export default class Slowmode extends Command { + constructor(client: Client) { + super(client); + this.name = 'slowmode'; + this.description = 'Set slowmode to a channel.'; + this.usage = 'slowmode [time] [seconds | minutes | hours]'; + this.permissions = 1; + this.guildOnly = true; + this.enabled = true; + } + + 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.***`); + + // @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.***`); + } + + 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.***`); + // @ts-ignore + return message.channel.edit({ rateLimitPerUser: time }); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} \ No newline at end of file