diff options
author | Neel Kamath <neelkamath@protonmail.com> | 2018-05-13 12:33:22 +0200 |
---|---|---|
committer | Neel Kamath <neelkamath@protonmail.com> | 2018-05-13 12:33:22 +0200 |
commit | 343157350f627b9495184246a90033a1c41f1a2c (patch) | |
tree | e8688471fbee2bdcd5834abcb559ea1694eecadf /server/src/commands/core/help.js | |
parent | Use the 'use strict' directive when needed (diff) | |
download | hackchat-343157350f627b9495184246a90033a1c41f1a2c.tar.gz hackchat-343157350f627b9495184246a90033a1c41f1a2c.zip |
Re-add module documentation
Diffstat (limited to '')
-rw-r--r-- | server/src/commands/core/help.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/server/src/commands/core/help.js b/server/src/commands/core/help.js new file mode 100644 index 0000000..7f63d3d --- /dev/null +++ b/server/src/commands/core/help.js @@ -0,0 +1,49 @@ +/* + Description: Outputs the current command module list or command categories +*/ + +const stripIndents = require('common-tags').stripIndents; + +exports.run = async (core, server, socket, data) => { + // verify passed arguments + let typeDt = typeof data.type; + let catDt = typeof data.category; + let cmdDt = typeof data.command; + if (typeDt !== 'undefined' && typeDt !== 'string' ) { + return; + } else if (catDt !== 'undefined' && catDt !== 'string' ) { + return; + } else if (cmdDt !== 'undefined' && cmdDt !== 'string' ) { + return; + } + + // set default reply + let reply = stripIndents`Help usage: + Show all categories -> { cmd: 'help', type: 'categories' } + Show all commands in category -> { cmd: 'help', category: '<category name>' } + Show specific command -> { cmd: 'help', command: '<command name>' }`; + + if (typeDt !== 'undefined') { + let categories = core.commands.categories().sort(); + reply = `Command Categories:\n${categories.map(c => `- ${c.replace('../src/commands/', '')}`).join('\n')}`; + } else if (catDt !== 'undefined') { + let catCommands = core.commands.all('../src/commands/' + data.category).sort((a, b) => a.info.name.localeCompare(b.info.name)); + reply = `${data.category} commands:\n${catCommands.map(c => `- ${c.info.name}`).join('\n')}`; + } else if (cmdDt !== 'undefined') { + let command = core.commands.get(data.command); + reply = stripIndents` + Usage: ${command.info.usage || command.info.name} + Description: ${command.info.description || '¯\_(ツ)_/¯'}`; + } + + server.reply({ + cmd: 'info', + text: reply + }, socket); +}; + +exports.info = { + name: 'help', + usage: 'help ([ type:categories] | [category:<category name> | command:<command name> ])', + description: 'Outputs information about the servers current protocol' +};
\ No newline at end of file |