enable/disable commands
This commit is contained in:
parent
8a51d4f77e
commit
17d3fb5e22
@ -1,4 +1,5 @@
|
||||
const { SlashCommand } = require("../../../interfaces");
|
||||
const { Emojis } = require("../../../../constants");
|
||||
const { SlashCommand, CommandError } = require("../../../interfaces");
|
||||
|
||||
class Commands extends SlashCommand {
|
||||
|
||||
@ -6,14 +7,99 @@ class Commands extends SlashCommand {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'commands',
|
||||
module: 'administration'
|
||||
module: 'administration',
|
||||
description: 'Manage commands',
|
||||
options: [{
|
||||
name: ['disable', 'enable'],
|
||||
type: 'SUB_COMMAND',
|
||||
description: ['Disable commands', 'Enable commands'],
|
||||
options: [{
|
||||
name: 'commands',
|
||||
type: 'STRING',
|
||||
description: ''
|
||||
} ]
|
||||
}, {
|
||||
name: ['list'],
|
||||
type: 'SUB_COMMAND',
|
||||
description: ['List disabled commands'],
|
||||
options: []
|
||||
}],
|
||||
memberPermissions: ['MANAGE_GUILD']
|
||||
});
|
||||
}
|
||||
|
||||
execute(interaction, opts) {
|
||||
async execute(interaction, { commands }) {
|
||||
|
||||
const { subcommand, guild } = interaction;
|
||||
|
||||
const settings = await guild.settings();
|
||||
const { disabledCommands = [] } = settings;
|
||||
|
||||
if (subcommand.name === 'list') return this._listDisabledCommands(interaction, disabledCommands);
|
||||
|
||||
if (!commands) throw new CommandError(interaction, { index: 'COMMAND_COMMANDS_MISSING_ARG' });
|
||||
|
||||
const resolved = [],
|
||||
invalid = [],
|
||||
alreadyDisabled = [];
|
||||
let warning = false;
|
||||
for (const _cmd of commands.value.split(' ')) {
|
||||
const [cmd] = this.client.resolver.components(_cmd, 'command');
|
||||
if (!cmd) {
|
||||
invalid.push(_cmd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resolved.includes(cmd.resolveable) || cmd.resolveable === 'command:commands') continue;
|
||||
if (disabledCommands.includes(cmd.resolveable) && subcommand.name === 'disable') {
|
||||
alreadyDisabled.push(cmd.resolveable);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cmd.module.name === 'administration' && subcommand.name === 'disable') warning = true;
|
||||
|
||||
resolved.push(cmd.resolveable);
|
||||
}
|
||||
|
||||
if (!resolved.length) {
|
||||
let response = null;
|
||||
if (alreadyDisabled.length) response = interaction.format('COMMAND_COMMANDS_ALREADY_DISABLED', { alreadyDisabled: alreadyDisabled.join('`, `') });
|
||||
else response = interaction.format('COMMAND_COMMANDS_NO_RESOLVED');
|
||||
if (invalid.length) response += '\n\n' + interaction.format('COMMAND_COMMANDS_INVALID', { invalid: invalid.join('`, `') });
|
||||
return { content: response, emoji: 'failure' };
|
||||
}
|
||||
|
||||
if (subcommand.name === 'disable') {
|
||||
disabledCommands.push(...resolved);
|
||||
} else if (subcommand.name === 'enable') {
|
||||
for (const disabled of resolved) {
|
||||
const index = disabledCommands.indexOf(disabled);
|
||||
if(index > -1) disabledCommands.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
await guild.updateSettings({ disabledCommands });
|
||||
|
||||
let response = interaction.format(`COMMAND_COMMANDS_${subcommand.name.toUpperCase()}`, { resolved: resolved.join(`**, **`) });
|
||||
if (alreadyDisabled.length) response += '\n\n' + interaction.format('COMMAND_COMMANDS_ALREADY_DISABLED', { alreadyDisabled: alreadyDisabled.join('`, `') });
|
||||
if (invalid.length) response += '\n\n' + interaction.format('COMMAND_COMMANDS_INVALID', { invalid: invalid.join('`, `') });
|
||||
|
||||
return {
|
||||
content: response, emoji: 'success', embeds: warning ? [{
|
||||
title: `${Emojis.warning} WARNING`,
|
||||
color: 0xffe15c,
|
||||
description: interaction.format('COMMAND_COMMANDS_DISABLE_WARN')
|
||||
}] : undefined };
|
||||
|
||||
}
|
||||
|
||||
async _listDisabledCommands(interaction, commands) {
|
||||
|
||||
if (!commands?.length) return { index: 'COMMAND_COMMANDS_NONE_DISABLED' };
|
||||
return { content: interaction.format('COMMAND_COMMANDS_LIST', { commands: commands.join('`, `') }) };
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//module.exports = Commands;
|
||||
module.exports = Commands;
|
Loading…
Reference in New Issue
Block a user