aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core/help.js
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2018-03-11 07:41:17 +0100
committermarzavec <admin@marzavec.com>2018-03-11 07:41:26 +0100
commit7d8220d838f82f7ad1ffedbcbd3b955aef6d71a2 (patch)
treec73d26f8d6e3b2c7af23e4afcd55ea7ceccf3596 /server/src/commands/core/help.js
parentMerge pull request #1 from MinusGix/master (diff)
downloadhackchat-7d8220d838f82f7ad1ffedbcbd3b955aef6d71a2.tar.gz
hackchat-7d8220d838f82f7ad1ffedbcbd3b955aef6d71a2.zip
stabilized modules and server cmd field
Diffstat (limited to '')
-rw-r--r--server/src/commands/core/help.js45
1 files changed, 32 insertions, 13 deletions
diff --git a/server/src/commands/core/help.js b/server/src/commands/core/help.js
index 17478d0..7b5237c 100644
--- a/server/src/commands/core/help.js
+++ b/server/src/commands/core/help.js
@@ -4,19 +4,38 @@
'use strict';
+const stripIndents = require('common-tags').stripIndents;
+
exports.run = async (core, server, socket, data) => {
- let reply = `Help usage: { cmd: 'help', type: 'categories'} or { cmd: 'help', type: 'commandname'}`;
-
- if (typeof data.type === 'undefined') {
- //
- } else {
- if (data.type == 'categories') {
- let categories = core.commands.categories();
- // TODO: bad output, fix this
- reply = `Command Categories:\n${categories}`;
- } else {
- // TODO: finish this module later
- }
+ // 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({
@@ -28,6 +47,6 @@ exports.run = async (core, server, socket, data) => {
// optional parameters are marked, all others are required
exports.info = {
name: 'help', // actual command name
- usage: 'help ([type:categories] | [type:command])',
+ usage: 'help ([ type:categories] | [category:<category name> | command:<command name> ])',
description: 'Outputs information about the servers current protocol'
};