forked from Galactic/modmail
added enable/disable command
This commit is contained in:
parent
e85c938683
commit
907540236b
@ -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) {
|
||||
|
||||
|
@ -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;
|
23
structure/commands/Disable.js
Normal file
23
structure/commands/Disable.js
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user