disable/enable commands/categories
This commit is contained in:
		
							parent
							
								
									2fed78ec04
								
							
						
					
					
						commit
						51d8c63637
					
				
					 2 changed files with 161 additions and 0 deletions
				
			
		
							
								
								
									
										89
									
								
								bot/commands/Configuration/disable.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								bot/commands/Configuration/disable.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,89 @@
 | 
			
		|||
const Command = require('../../base/Command.js');
 | 
			
		||||
 | 
			
		||||
class Disable extends Command {
 | 
			
		||||
    constructor (client) {
 | 
			
		||||
        super(client, {
 | 
			
		||||
            description: 'Disables a command/category so they can\'t be used in this server.',
 | 
			
		||||
            usage: '`disable command [command]` - Disables the specified command.\n`disable category [category]` - Disables the specified category.',
 | 
			
		||||
            examples: '`disable command cuddle`\n`disable category music`',
 | 
			
		||||
            userPerms: ['ADMINISTRATOR']
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async run (message, args, data) {
 | 
			
		||||
        const essentialCategories = [
 | 
			
		||||
            'Configuration',
 | 
			
		||||
            'Developer'
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        const essentialCommands = [
 | 
			
		||||
            'help'
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        if (!args[0]) {
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        } else {
 | 
			
		||||
            if (!args[1]) return message.channel.send(
 | 
			
		||||
                'You didn\'t specify a command/category to disable!'
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            if (args[0] === 'command') {
 | 
			
		||||
                const array = data.guild.disabledcommands;
 | 
			
		||||
                const name = args[1].toLowerCase();
 | 
			
		||||
                let command;
 | 
			
		||||
                
 | 
			
		||||
                if (this.client.commands.has(name)) {
 | 
			
		||||
                    command = this.client.commands.get(name);
 | 
			
		||||
                } else if (this.client.aliases.has(name)) {
 | 
			
		||||
                    command = this.client.commands.get(this.client.aliases.get(name));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (!command) return message.channel.send(
 | 
			
		||||
                    `\`${args[0]}\` does not exist as a command or an alias.`
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                if (essentialCategories.includes(command.help.category) || essentialCommands.includes(command.help.name)) {
 | 
			
		||||
                    return message.channel.send('This command is essential, and cannot be disabled.');
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                if (array.includes(command.help.name)) return message.channel.send(
 | 
			
		||||
                    'This command has already been disabled. Use `enable` to re-enable it.'
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                array.push(command.help.name);
 | 
			
		||||
 | 
			
		||||
                await this.client.db.updateGuild(message.guild.id, 'disabledcommands', array);
 | 
			
		||||
    
 | 
			
		||||
                return message.channel.send(`Disabled command \`${name}\``);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (args[0] === 'category') {
 | 
			
		||||
                const array = data.guild.disabledcategories;
 | 
			
		||||
                const name = args[1].toProperCase();
 | 
			
		||||
 | 
			
		||||
                if (!this.client.categories.includes(name)) return message.channel.send(
 | 
			
		||||
                    'I couldn\'t find this category. Are you sure you spelt it correctly?'
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                if (essentialCategories.includes(name)) return message.channel.send(
 | 
			
		||||
                    'This category is essential, and cannot be disabled.'
 | 
			
		||||
                );
 | 
			
		||||
                
 | 
			
		||||
                if (array.includes(name)) return message.channel.send(
 | 
			
		||||
                    'This command has already been disabled. Use `enable` to re-enable it.'
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                array.push(name);
 | 
			
		||||
 | 
			
		||||
                await this.client.db.updateGuild(message.guild.id, 'disabledcategories', array);
 | 
			
		||||
    
 | 
			
		||||
                return message.channel.send(`Disabled category \`${name}\``);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return message.channel.send('didn\'t specify whether to disable a command or category');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = Disable;
 | 
			
		||||
							
								
								
									
										72
									
								
								bot/commands/Configuration/enable.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								bot/commands/Configuration/enable.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,72 @@
 | 
			
		|||
const Command = require('../../base/Command.js');
 | 
			
		||||
 | 
			
		||||
class Enable extends Command {
 | 
			
		||||
    constructor (client) {
 | 
			
		||||
        super(client, {
 | 
			
		||||
            description: 'Re-enables a previously disabled command/category.',
 | 
			
		||||
            usage: '`enable command [command]` - Enables the specified command.\n`enable category [category]` - Enables the specified category.',
 | 
			
		||||
            examples: '`enable command cuddle`\n`enable category music`',
 | 
			
		||||
            userPerms: ['ADMINISTRATOR']
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async run (message, args, data) {        
 | 
			
		||||
        if (!args[0]) {
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        } else {
 | 
			
		||||
            if (!args[1]) return message.channel.send(
 | 
			
		||||
                'You didn\'t specify a command/category to enable!'
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            if (args[0] === 'command') {
 | 
			
		||||
                const array = data.guild.disabledcommands;
 | 
			
		||||
                const name = args[1].toLowerCase();
 | 
			
		||||
                let command;
 | 
			
		||||
                
 | 
			
		||||
                if (this.client.commands.has(name)) {
 | 
			
		||||
                    command = this.client.commands.get(name);
 | 
			
		||||
                } else if (this.client.aliases.has(name)) {
 | 
			
		||||
                    command = this.client.commands.get(this.client.aliases.get(name));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (!command) return message.channel.send(
 | 
			
		||||
                    `\`${args[0]}\` does not exist as a command or an alias.`
 | 
			
		||||
                );
 | 
			
		||||
                
 | 
			
		||||
                if (!array.includes(command.help.name)) return message.channel.send(
 | 
			
		||||
                    'This command isn\'t disabled.'
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                array.remove(command.help.name);
 | 
			
		||||
 | 
			
		||||
                await this.client.db.updateGuild(message.guild.id, 'disabledcommands', array);
 | 
			
		||||
    
 | 
			
		||||
                return message.channel.send(`Enabled command \`${name}\``);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (args[0] === 'category') {
 | 
			
		||||
                const array = data.guild.disabledcategories;
 | 
			
		||||
                const name = args[1].toProperCase();
 | 
			
		||||
 | 
			
		||||
                if (!this.client.categories.includes(name)) return message.channel.send(
 | 
			
		||||
                    'I couldn\'t find this category. Are you sure you spelt it correctly?'
 | 
			
		||||
                );
 | 
			
		||||
                
 | 
			
		||||
                if (!array.includes(name)) return message.channel.send(
 | 
			
		||||
                    'This command isn\'t disabled.'
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                array.remove(name);
 | 
			
		||||
 | 
			
		||||
                await this.client.db.updateGuild(message.guild.id, 'disabledcategories', array);
 | 
			
		||||
    
 | 
			
		||||
                return message.channel.send(`Enabled category \`${name}\``);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return message.channel.send('didn\'t specify whether to enable a command or category');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = Enable;
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue