110 lines
3.2 KiB
JavaScript
110 lines
3.2 KiB
JavaScript
const { Command } = require('../../../../interfaces/');
|
|
|
|
class CommandsCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'commands',
|
|
module: 'information',
|
|
aliases: [
|
|
'cmd',
|
|
'cmds',
|
|
'command'
|
|
],
|
|
usage: '[module]',
|
|
arguments: [
|
|
// {
|
|
// name: 'user',
|
|
// type: 'BOOLEAN',
|
|
// types: ['VERBAL', 'FLAG'],
|
|
// default: true
|
|
// },
|
|
]
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
async execute(message, { params }) {
|
|
|
|
if (!params.length) // list all commands
|
|
return this._listCommands(message);
|
|
|
|
params = params.join(' ');
|
|
|
|
const [ mod ] = this.client.resolver.components(params, 'module', false);
|
|
if(!mod) {
|
|
const [ command ] = this.client.resolver.components(params, 'command', false);
|
|
if (!command) return message.format('C_COMMAND_INVALID');
|
|
return await message._showUsage(command);
|
|
}
|
|
//list module's commands
|
|
|
|
const commands = mod.components.filter(c=>c.type === 'command');
|
|
let text = '';
|
|
|
|
for(let command of commands.values()) {
|
|
text += command.disabled ? `~~${command.name}~~\n` : `${command.name}`; //TODO: Denote disabled commands somehow
|
|
}
|
|
|
|
const embed = {
|
|
author: {
|
|
name: message.format('C_COMMANDS_TITLE'),
|
|
icon_url: this.client.user.avatarURL()
|
|
},
|
|
description: message.format('C_COMMANDS') + '\n' + message.format('C_COMMANDS_TEMPLATE', { mod: mod.name, text }),
|
|
footer: {
|
|
text: message.format('C_COMMANDS_FOOTER')
|
|
}
|
|
};
|
|
|
|
return message.embed(embed);
|
|
|
|
}
|
|
|
|
_listCommands(message) {
|
|
|
|
let fields = [];
|
|
const sortedModules = this.client.registry.components
|
|
.filter(c => c.type === 'module')
|
|
.sort((a, b) => {
|
|
const filter = c => c.type === 'command';
|
|
return b.components.filter(filter) - a.components.filter(filter);
|
|
});
|
|
|
|
for (const mod of sortedModules.values()) {
|
|
let field = {
|
|
name: mod.id,
|
|
value: '',
|
|
inline: true
|
|
};
|
|
|
|
for (const command of mod.components.values()) {
|
|
if (command.type !== 'command'
|
|
|| (command.restricted && !this.client._options.bot.owners.includes(message.author.id))) continue;
|
|
field.value += `${command.name}\n`;
|
|
}
|
|
if (field.value) fields.push(field);
|
|
}
|
|
|
|
const embed = {
|
|
author: {
|
|
name: message.format('C_COMMANDS_TITLE'),
|
|
icon_url: this.client.user.avatarURL()
|
|
},
|
|
description: message.format('C_COMMANDS'),
|
|
fields,
|
|
footer: {
|
|
text: message.format('C_COMMANDS_FOOTER')
|
|
}
|
|
};
|
|
|
|
return message.embed(embed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = CommandsCommand; |