2020-05-07 01:26:16 +02:00
|
|
|
const { Command } = require('../../../../interfaces/');
|
|
|
|
|
|
|
|
class CommandsCommand extends Command {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'commands',
|
|
|
|
module: 'information',
|
|
|
|
aliases: [
|
|
|
|
'cmd',
|
|
|
|
'cmds',
|
|
|
|
'command'
|
|
|
|
],
|
2020-11-09 19:15:02 +01:00
|
|
|
clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'],
|
2020-05-07 01:26:16 +02:00
|
|
|
usage: '[module]',
|
|
|
|
arguments: [
|
2020-05-08 08:50:54 +02:00
|
|
|
// {
|
2020-05-07 01:26:16 +02:00
|
|
|
// name: 'user',
|
|
|
|
// type: 'BOOLEAN',
|
|
|
|
// types: ['VERBAL', 'FLAG'],
|
|
|
|
// default: true
|
2020-05-08 08:50:54 +02:00
|
|
|
// },
|
2020-05-07 01:26:16 +02:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
this.client = client;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async execute(message, { params }) {
|
2020-07-04 12:23:10 +02:00
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
if (!params.length) return this._listCommands(message);
|
2020-05-07 01:26:16 +02:00
|
|
|
|
|
|
|
params = params.join(' ');
|
|
|
|
|
|
|
|
const [ mod ] = this.client.resolver.components(params, 'module', false);
|
2020-07-26 22:10:46 +02:00
|
|
|
if (!mod) {
|
2020-05-07 01:26:16 +02:00
|
|
|
const [ command ] = this.client.resolver.components(params, 'command', false);
|
|
|
|
if (!command) return message.format('C_COMMAND_INVALID');
|
2020-07-26 22:10:46 +02:00
|
|
|
return message.embed(command.usageEmbed(message, true));
|
2020-05-07 01:26:16 +02:00
|
|
|
}
|
|
|
|
//list module's commands
|
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
const commands = mod.components.filter((c) => c.type === 'command');
|
2020-05-07 01:26:16 +02:00
|
|
|
let text = '';
|
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
for(const command of commands.values()) {
|
2020-07-28 12:11:20 +02:00
|
|
|
text += command.disabled ? `~~${command.name}~~\n` : `${command.name}\n`; //TODO: Denote disabled commands somehow
|
2020-05-07 01:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const embed = {
|
|
|
|
author: {
|
|
|
|
name: message.format('C_COMMANDS_TITLE'),
|
2020-05-21 12:47:58 +02:00
|
|
|
icon_url: this.client.user.avatarURL() //eslint-disable-line camelcase
|
2020-05-07 01:26:16 +02:00
|
|
|
},
|
2020-05-21 12:47:58 +02:00
|
|
|
description: `${message.format('C_COMMANDS')}\n${message.format('C_COMMANDS_TEMPLATE', { mod: mod.name, text })}`,
|
2020-05-07 01:26:16 +02:00
|
|
|
footer: {
|
|
|
|
text: message.format('C_COMMANDS_FOOTER')
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return message.embed(embed);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_listCommands(message) {
|
|
|
|
|
2020-05-21 12:47:58 +02:00
|
|
|
const fields = [];
|
2020-05-07 01:26:16 +02:00
|
|
|
const sortedModules = this.client.registry.components
|
2020-05-21 12:47:58 +02:00
|
|
|
.filter((c) => c.type === 'module')
|
2020-05-07 01:26:16 +02:00
|
|
|
.sort((a, b) => {
|
2020-05-21 12:47:58 +02:00
|
|
|
const filter = (c) => c.type === 'command';
|
2020-05-25 13:13:34 +02:00
|
|
|
return b.components.filter(filter).size - a.components.filter(filter).size;
|
2020-05-07 01:26:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
for (const mod of sortedModules.values()) {
|
2020-05-21 12:47:58 +02:00
|
|
|
const field = {
|
2020-05-07 01:26:16 +02:00
|
|
|
name: mod.id,
|
|
|
|
value: '',
|
|
|
|
inline: true
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const command of mod.components.values()) {
|
2020-05-25 13:13:34 +02:00
|
|
|
if (command.type !== 'command'
|
|
|
|
|| command.restricted && !this.client._options.bot.owners.includes(message.author.id)
|
|
|
|
|| !command.archivable) continue;
|
2021-06-09 22:18:46 +02:00
|
|
|
field.value += command.disabled ? `~~${command.name}~~\n` : `${command.name}\n`;
|
2020-05-07 01:26:16 +02:00
|
|
|
}
|
|
|
|
if (field.value) fields.push(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
const embed = {
|
|
|
|
author: {
|
|
|
|
name: message.format('C_COMMANDS_TITLE'),
|
2020-05-21 12:47:58 +02:00
|
|
|
icon_url: this.client.user.avatarURL() //eslint-disable-line camelcase
|
2020-05-07 01:26:16 +02:00
|
|
|
},
|
|
|
|
description: message.format('C_COMMANDS'),
|
|
|
|
fields,
|
|
|
|
footer: {
|
|
|
|
text: message.format('C_COMMANDS_FOOTER')
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return message.embed(embed);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CommandsCommand;
|