UNPKG

hubot-command-mapper

Version:
28 lines (27 loc) 1.07 kB
export default function createHelpCommand() { return { name: "help", alias: ["?", "/?", "--help"], execute: (context, helpMsgPrefix, noHelpMsg) => { const botName = "@" + (context.robot.alias || context.robot.name); let helpCommands = context.robot .helpCommands() .filter(cmd => cmd.startsWith("hubot " + context.tool.name)) .map(cmd => cmd.replace(/hubot/g, botName)); helpCommands.sort(); if (helpCommands.length === 0) { if (noHelpMsg) { context.res.reply(noHelpMsg); return; } context.res.reply(`the tool _${context.tool.name}_ has no help.`); return; } if (!helpMsgPrefix) { helpMsgPrefix = `the tool _${context.tool.name}_ has the following commands:\n- `; } let msg = helpMsgPrefix + helpCommands.join("\n- "); context.res.reply(msg); } }; }