-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.js
102 lines (94 loc) · 3.84 KB
/
help.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const { stripIndents, oneLine } = require('common-tags');
const Command = require('../base');
const disambiguation = require('../../util').disambiguation;
module.exports = class HelpCommand extends Command {
constructor(client) {
super(client, {
name: 'help',
group: 'util',
memberName: 'help',
aliases: ['commands'],
description: 'Displays a list of available commands, or detailed information for a specified command.',
details: oneLine`
The command may be part of a command name or a whole command name.
If it isn't specified, all available commands will be listed.
`,
examples: ['help', 'help prefix'],
guarded: true,
args: [
{
key: 'command',
prompt: 'Which command would you like to view the help for?',
type: 'string',
default: ''
}
]
});
}
async run(msg, args) { // eslint-disable-line complexity
const groups = this.client.registry.groups;
const commands = this.client.registry.findCommands(args.command, false, msg);
const showAll = args.command && args.command.toLowerCase() === 'all';
if(args.command && !showAll) {
if(commands.length === 1) {
let help = stripIndents`
${oneLine`
__Command **${commands[0].name}**:__ ${commands[0].description}
${commands[0].guildOnly ? ' (Usable only in servers)' : ''}
`}
**Format:** ${msg.anyUsage(`${commands[0].name}${commands[0].format ? ` ${commands[0].format}` : ''}`)}
`;
if(commands[0].aliases.length > 0) help += `\n**Aliases:** ${commands[0].aliases.join(', ')}`;
help += `\n${oneLine`
**Group:** ${commands[0].group.name}
(\`${commands[0].groupID}:${commands[0].memberName}\`)
`}`;
if(commands[0].details) help += `\n**Details:** ${commands[0].details}`;
if(commands[0].examples) help += `\n**Examples:**\n${commands[0].examples.join('\n')}`;
const messages = [];
try {
messages.push(await msg.direct(help));
if(msg.channel.type !== 'dm') messages.push(await msg.reply('Sent you a DM with information.'));
} catch(err) {
messages.push(await msg.reply('Unable to send you the help DM. You probably have DMs disabled.'));
}
return messages;
} else if(commands.length > 1) {
return msg.reply(disambiguation(commands, 'commands'));
} else {
return msg.reply(
`Unable to identify command. Use ${msg.usage(
null, msg.channel.type === 'dm' ? null : undefined, msg.channel.type === 'dm' ? null : undefined
)} to view the list of all commands.`
);
}
} else {
const messages = [];
try {
messages.push(await msg.direct(stripIndents`
${oneLine`
To run a command in ${msg.guild || 'any server'},
use ${Command.usage('command', msg.guild ? msg.guild.commandPrefix : null, this.client.user)}.
For example, ${Command.usage('prefix', msg.guild ? msg.guild.commandPrefix : null, this.client.user)}.
`}
To run a command in this DM, simply use ${Command.usage('command', null, null)} with no prefix.
Use ${this.usage('<command>', null, null)} to view detailed information about a specific command.
Use ${this.usage('all', null, null)} to view a list of *all* commands, not just available ones.
__**${showAll ? 'All commands' : `Available commands in ${msg.guild || 'this DM'}`}**__
${(showAll ? groups : groups.filter(grp => grp.commands.some(cmd => cmd.isUsable(msg))))
.map(grp => stripIndents`
__${grp.name}__
${(showAll ? grp.commands : grp.commands.filter(cmd => cmd.isUsable(msg)))
.map(cmd => `**${cmd.name}:** ${cmd.description}`).join('\n')
}
`).join('\n\n')
}
`, { split: true }));
if(msg.channel.type !== 'dm') messages.push(await msg.reply('Sent you a DM with information.'));
} catch(err) {
messages.push(await msg.reply('Unable to send you the help DM. You probably have DMs disabled.'));
}
return messages;
}
}
};