forked from Galactic/galactic-bot
111 lines
3.4 KiB
JavaScript
111 lines
3.4 KiB
JavaScript
const { Command } = require('../../../../interfaces/');
|
|
|
|
class CommandsCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'commands',
|
|
module: 'information',
|
|
aliases: [
|
|
'cmd',
|
|
'cmds',
|
|
'command'
|
|
],
|
|
clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'],
|
|
usage: '[module]',
|
|
arguments: [
|
|
// {
|
|
// name: 'user',
|
|
// type: 'BOOLEAN',
|
|
// types: ['VERBAL', 'FLAG'],
|
|
// default: true
|
|
// },
|
|
]
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
async execute(message, { params }) {
|
|
|
|
if (!params.length) 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 message.embed(command.usageEmbed(message, true));
|
|
}
|
|
//list module's commands
|
|
|
|
const commands = mod.components.filter((c) => c.type === 'command');
|
|
let text = '';
|
|
|
|
for(const command of commands.values()) {
|
|
text += command.disabled ? `~~${command.name}~~\n` : `${command.name}\n`; //TODO: Denote disabled commands somehow
|
|
}
|
|
|
|
const embed = {
|
|
author: {
|
|
name: message.format('C_COMMANDS_TITLE'),
|
|
icon_url: this.client.user.avatarURL() //eslint-disable-line camelcase
|
|
},
|
|
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) {
|
|
|
|
const 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).size - a.components.filter(filter).size;
|
|
});
|
|
|
|
for (const mod of sortedModules.values()) {
|
|
const 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)
|
|
|| !command.archivable) continue;
|
|
field.value += command.disabled ? `~~${command.name}~~\n` : `${command.name}\n`;
|
|
}
|
|
if (field.value) fields.push(field);
|
|
}
|
|
|
|
const embed = {
|
|
author: {
|
|
name: message.format('C_COMMANDS_TITLE'),
|
|
icon_url: this.client.user.avatarURL() //eslint-disable-line camelcase
|
|
},
|
|
description: message.format('C_COMMANDS'),
|
|
fields,
|
|
footer: {
|
|
text: message.format('C_COMMANDS_FOOTER')
|
|
}
|
|
};
|
|
|
|
return message.embed(embed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = CommandsCommand; |