Haha-Yes/commands/utility/help.js

105 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-12-30 01:20:24 +01:00
const { Command } = require('discord-akairo');
const { prefix } = require('../../config.json');
class HelpCommand extends Command {
constructor() {
super('help', {
aliases: ['help', 'halp', 'h'],
category: 'utility',
clientPermissions: ['EMBED_LINKS'],
args: [
{
id: 'command',
type: 'commandAlias',
prompt: {
start: 'Which command do you need help with?',
retry: 'Please provide a valid command.',
optional: true
2019-01-19 18:26:09 +01:00
},
match: 'rest'
2018-12-30 01:20:24 +01:00
}
],
description: {
content: 'Displays a list of commands or information about a command.',
usage: '[command]',
2018-12-30 01:57:32 +01:00
examples: ['', 'say', 'tag']
2018-12-30 01:20:24 +01:00
}
});
}
exec(message, { command }) {
if (!command) return this.execCommandList(message);
const description = Object.assign({
content: 'No description available.',
usage: '',
examples: [],
fields: []
}, command.description);
const embed = this.client.util.embed()
2019-11-02 00:54:40 +01:00
.setColor(message.member.displayHexColor)
2019-03-30 04:58:31 +01:00
.setTitle(`\`${prefix[0]}${command.aliases[0]} ${description.usage}\``)
.addField('Description', description.content)
2019-10-12 14:06:36 +02:00
.setFooter(`All the available prefix: ${prefix.join(' | ')}`);
2018-12-30 01:20:24 +01:00
for (const field of description.fields) embed.addField(field.name, field.value);
if (description.examples.length) {
2019-03-30 04:58:31 +01:00
const text = `${prefix[0]}${command.aliases[0]}`;
2018-12-30 01:20:24 +01:00
embed.addField('Examples', `\`${text} ${description.examples.join(`\`\n\`${text} `)}\``, true);
}
if (command.aliases.length > 1) {
embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true);
}
if (command.userPermissions) {
embed.addField('User permission', `\`${command.userPermissions.join('` `')}\``, true);
}
if (command.clientPermissions) {
embed.addField('Bot permission', `\`${command.clientPermissions.join('` `')}\``, true);
}
2018-12-30 01:20:24 +01:00
return message.util.send({ embed });
}
async execCommandList(message) {
const embed = this.client.util.embed()
2019-11-02 00:54:40 +01:00
.setColor(message.member.displayHexColor)
2018-12-30 01:20:24 +01:00
.addField('Command List',
[
'This is a list of commands.',
2019-03-30 04:58:31 +01:00
`To view details for a command, do \`${prefix[0]}help <command>\`.`
2019-03-30 04:58:42 +01:00
])
2019-10-12 14:06:36 +02:00
.setFooter(`All the available prefix: ${prefix.join(' | ')}`);
2018-12-30 01:20:24 +01:00
for (const category of this.handler.categories.values()) {
const title = {
general: '📝\u2000General',
2019-11-08 12:54:18 +01:00
fun: '🎉\u2000Fun',
minigame: '🕹\u2000Minigames (WIP)',
images: '🖼\u2000Images',
utility: '🔩\u2000Utility',
admin: '⚡\u2000Admin',
2018-12-30 01:20:24 +01:00
}[category.id];
if (title) embed.addField(title, `\`${category.map(cmd => cmd.aliases[0]).join('` `')}\``);
}
const shouldReply = message.guild && message.channel.permissionsFor(this.client.user).has('SEND_MESSAGES');
try {
await message.author.send({ embed });
if (shouldReply) return message.util.reply('I\'ve sent you a DM with the command list.');
} catch (err) {
if (shouldReply) return message.util.send({ embed });
2018-12-30 01:20:24 +01:00
}
return undefined;
}
}
module.exports = HelpCommand;