From 36d02a8f122a009dec092dcd0a894c9746022a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Fri, 17 Apr 2020 21:10:18 -0400 Subject: [PATCH] Added slow mode command --- slowmode.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 slowmode.ts diff --git a/slowmode.ts b/slowmode.ts new file mode 100644 index 0000000..76575a3 --- /dev/null +++ b/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); + } + } +}