Skip to content

Commit

Permalink
Truncate help command list to just command names if too long
Browse files Browse the repository at this point in the history
  • Loading branch information
zajrik committed Feb 10, 2017
1 parent ce1980e commit 4a699c6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/lib/command/base/Help.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,30 @@ export default class Help extends Command

if (!args[0])
{
output += `Available commands in ${dm ? 'this DM' : message.channel}\n\`\`\`ldif\n`;
const preText = `Available commands in ${dm ? 'this DM' : message.channel}\n\`\`\`ldif\n`;
const postText = `\`\`\`Use \`<prefix>help <command>\` ${this.bot.selfbot ? '' : `or \`${
mentionName} help <command>\` `}for more information.\n\n`;

const usableCommands = this.bot.commands[dm
? 'filterDMUsable' : 'filterGuildUsable'](this.bot, message)
.filter(c => !c.hidden);

const widest = usableCommands.map(c => c.name.length).reduce((a, b) => Math.max(a, b));
output += usableCommands.map(c =>
let commandList = usableCommands.map(c =>
`${padRight(c.name, widest + 1)}: ${c.description}`).sort().join('\n');

output += `\`\`\`Use \`<prefix>help <command>\` ${this.bot.selfbot ? '' : `or \`${
mentionName} help <command>\` `}for more information.\n\n`;
output = preText + commandList + postText;
if (output.length >= 1024)
{
commandList = '';
let mappedCommands = usableCommands.map(c => padRight(c.name, widest + 2)).sort();
for (let i = 0; i <= mappedCommands.length; i++)
{
commandList += mappedCommands[i];
if ((i + 1) % 3 === 0) commandList += '\n';
}
output = preText + commandList + postText;
}
}
else
{
Expand Down

0 comments on commit 4a699c6

Please sign in to comment.