From e7a22c443efcfccba50a0ee77b3df452b28eacf6 Mon Sep 17 00:00:00 2001 From: Emily J Date: Sun, 25 Oct 2020 19:29:01 +1100 Subject: [PATCH] start working on disable command --- bot/commands/Configuration/disable.js | 57 +++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/bot/commands/Configuration/disable.js b/bot/commands/Configuration/disable.js index 6c1edd5..1d02a34 100644 --- a/bot/commands/Configuration/disable.js +++ b/bot/commands/Configuration/disable.js @@ -15,7 +15,58 @@ module.exports = class { }; } - run (client, message, args, data) { - + async run (client, message, [action, ...toDisable], data) { + const essential = { + categories: ['Configuration', 'Developer'], + commands: ['help'] + }; + + if (!action || action.toLowerCase() === 'list') { + return; + } + + if (!toDisable) return message.channel.createMessage( + `${client.constants.emojis.userError} You didn't specify what command/category to disable. Usage: \`${this.help.usage}\`` + ); + + if (action.toLowerCase() === 'command' || action.toLowerCase() === 'cmd') { + const disabled = data.guild.disabledcommands; + const notFound = []; + const alreadyDisabled = []; + const cannotDisable = []; + + for (let cmd of toDisable) { + cmd = cmd.toLowerCase(); + let command; + + if (client.commands.has(cmd)) { + command = client.commands.get(cmd); + } else if (client.aliases.has(cmd)) { + command = client.commands.get(client.aliases.get(cmd)); + } + + if (!command) { + notFound.push(cmd); + toDisable.remove(cmd); + } + + if (essential.commands.includes(command.name) || essential.categories.includes(command.category)) { + cannotDisable.push(cmd); + toDisable.remove(cmd); + } + + if (disabled.includes(cmd)) { + alreadyDisabled.push(cmd); + toDisable.remove(cmd); + } + } + + if (toDisable.length > 0) { + const push = disabled.concat(toDisable); + await client.db.updateGuild(message.channel.guild.id, 'disabledcommands', push); + + } + + } } -}; \ No newline at end of file +} \ No newline at end of file