added enable/disable command

This commit is contained in:
Erik 2021-12-22 11:30:50 +02:00
parent e85c938683
commit 907540236b
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589
3 changed files with 52 additions and 1 deletions

View File

@ -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) {

View File

@ -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;

View 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;