diff --git a/structure/Client.js b/structure/Client.js index 11731a9..cd32340 100644 --- a/structure/Client.js +++ b/structure/Client.js @@ -106,7 +106,7 @@ class ModmailClient extends Client { const commandName = rawCommand.substring(prefix.length); const command = this.registry.find(commandName); if (!command) return; - message._caller = commandName; + message._caller = commandName.toLowerCase(); if (command.showUsage && !args.length) { diff --git a/structure/Modmail.js b/structure/Modmail.js index c6b787c..f4f90c5 100644 --- a/structure/Modmail.js +++ b/structure/Modmail.js @@ -29,6 +29,8 @@ class Modmail { this.replies = {}; this.lastReminder = null; + this.disabled = false; + this.disabledReason = null; this.channels = new ChannelHandler(this, opts); this._ready = false; @@ -65,6 +67,9 @@ class Modmail { // this.client.logger.info(`Fetching messages from discord for modmail`); // TODO: Fetch messages from discord in modmail channels + this.disabled = this.cache.misc.disabled || false; + this.disabledReason = this.cache.misc.disabledReason || null; + this.channels.init(); this._ready = true; @@ -130,6 +135,13 @@ class Modmail { } else if (now - this.spammers[author.id].start > 15) this.spammers[author.id] = { start: now, count: 1, timeout: false, warned: false }; else this.spammers[author.id].count++; + if (this.disabled) { + let reason = `Modmail has been disabled for the time being`; + if (this.disabledReason) reason += ` for the following reason:\n\n${this.disabledReason}`; + else reason += `.`; + return author.send(reason); + } + const pastModmail = await this.cache.loadModmailHistory(author.id) .catch((err) => { this.client.logger.error(`Error during loading of past mail:\n${err.stack}`); @@ -415,6 +427,22 @@ class Modmail { } + disable (reason) { + this.disabled = true; + if (reason) this.disabledReason = reason; + else this.disabledReason = null; + + this.cache.misc.disabled = true; + this.cache.misc.disabledReason = this.disabledReason; + this.cache.savePersistentCache(); + } + + enable () { + this.disabled = false; + this.cache.misc.disabled = false; + this.cache.savePersistentCache(); + } + } module.exports = Modmail; \ No newline at end of file diff --git a/structure/commands/Disable.js b/structure/commands/Disable.js new file mode 100644 index 0000000..612264d --- /dev/null +++ b/structure/commands/Disable.js @@ -0,0 +1,23 @@ +const Command = require('../Command'); + +class Ping extends Command { + + constructor (client) { + super(client, { + name: 'disable', + aliases: [ 'enable' ] + }); + } + + async execute ({ _caller }, { clean }) { + + if (_caller === 'enable') this.client.modmail.enable(); + else this.client.modmail.disable(clean); + + return `:thumbsup: ${_caller}d`; + + } + +} + +module.exports = Ping; \ No newline at end of file