forked from Galactic/galactic-bot
112 lines
3.6 KiB
JavaScript
112 lines
3.6 KiB
JavaScript
const { Command } = require('../../../../interfaces/');
|
|
|
|
class HelpCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'help',
|
|
module: 'information',
|
|
clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS']
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
async execute(message, { params }) {
|
|
|
|
if (!params.length) return message.embed({
|
|
description: message.format('C_HELP')
|
|
});
|
|
|
|
const [ key ] = params;
|
|
if (key.toLowerCase() === 'modhelp') return this._modhelp(message);
|
|
|
|
let [ result ] = this.client.resolver.components(key, 'command');
|
|
if (!result) [ result ] = this.client.resolver.components(key, 'setting');
|
|
if (!result) result = this.client.resolver.componentsByTag(key, 'any', false);
|
|
if (!result) return message.embed({
|
|
description: message.format('C_HELP_404', { component: key })
|
|
});
|
|
|
|
if (result instanceof Array) {
|
|
|
|
const commands = result.filter((c) => c.type === 'command');
|
|
const settings = result.filter((c) => c.type === 'setting');
|
|
|
|
const embed = {
|
|
description: message.format('C_HELP_TAGS', { keyword: key }),
|
|
fields: [
|
|
|
|
]
|
|
};
|
|
|
|
if (commands.length) embed.fields.push({
|
|
name: 'Commands',
|
|
value: commands.map((c) => c.name).join('\n'),
|
|
inline: true
|
|
});
|
|
if (settings.length) embed.fields.push({
|
|
name: 'Settings',
|
|
value: settings.map((s) => s.display).join('\n'),
|
|
inline: true
|
|
});
|
|
|
|
if (!embed.fields.length) embed.description += '\n\n' + message.format('NO_RESULT');
|
|
|
|
return message.embed(embed);
|
|
|
|
}
|
|
|
|
return message.embed(result.usageEmbed(message, true));
|
|
|
|
// //let index = `${result.type.slice(0, 1).toUpperCase()}_${result.name.toUpperCase()}_HELP`;
|
|
// const em = {
|
|
// description: message.format('C_HELP_TEMPLATE', {
|
|
// desc: message.format(result.description),
|
|
// component: result.name.toUpperCase(),
|
|
// text: result.examples.map((ex) => `\`{prefix}${result.type === 'command' ? result.name.toLowerCase() : `settings ${result.name.toLowerCase()}`} ${ex}\``).join('\n')
|
|
// })
|
|
// };
|
|
// if (result.aliases.length) em.fields = [
|
|
// {
|
|
// name: 'Aliases',
|
|
// value: result.aliases.map((al) => al.toLowerCase()).join(', ')
|
|
// }
|
|
// ];
|
|
|
|
// return message.embed(em);
|
|
|
|
}
|
|
|
|
_modhelp(message) {
|
|
|
|
return message.embed({
|
|
title: message.format('MODHELP_TITLE'),
|
|
description: message.format('MODHELP_DESC'),
|
|
fields: [
|
|
{
|
|
name: message.format('MODHELP_FIELD_1_NAME'),
|
|
value: message.format('MODHELP_FIELD_1_VALUE')
|
|
},
|
|
{
|
|
name: message.format('MODHELP_FIELD_2_NAME'),
|
|
value: message.format('MODHELP_FIELD_2_VALUE')
|
|
},
|
|
{
|
|
name: message.format('MODHELP_FIELD_3_NAME'),
|
|
value: message.format('MODHELP_FIELD_3_VALUE')
|
|
},
|
|
{
|
|
name: message.format('MODHELP_FIELD_4_NAME'),
|
|
value: message.format('MODHELP_FIELD_4_VALUE')
|
|
}
|
|
]
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = HelpCommand; |