diff --git a/docs/api/lib/commands.md b/docs/api/lib/commands.md
index 587e8c7e..3b8da90d 100644
--- a/docs/api/lib/commands.md
+++ b/docs/api/lib/commands.md
@@ -111,7 +111,7 @@ Shut the bot up until manually restarted
### commands~cmdHelp(command)
-Reply with help test top the command !help
+Reply with help to the command !help
**Kind**: inner method of [commands](#module_commands)
diff --git a/lib/commands.js b/lib/commands.js
index a393a1b8..2f29a609 100644
--- a/lib/commands.js
+++ b/lib/commands.js
@@ -144,10 +144,36 @@ exports.parseCommands = function parseCommands(post, topic, callback) {
* @returns {string} command list for posting
*/
function getCommandHelps() {
- const cmds = Object.keys(internals.commands),
+ const cmds = {},
+ topics = {},
result = ['Registered commands:'];
- cmds.sort();
- cmds.forEach((cmd) => result.push(cmd + ': ' + internals.commands[cmd].help));
+ let keys = {};
+ Object.keys(internals.commands).map((key) => {
+ keys[key] = 1;
+ });
+ Object.keys(internals.helpMessages).map((key) => {
+ keys[key] = 1;
+ });
+ Object.keys(keys).map((key) => {
+ if (internals.commands[key]) {
+ cmds[key] = internals.commands[key].help;
+ if (internals.helpMessages[key]) {
+ cmds[key] += ' *';
+ }
+ } else {
+ topics[key] = 'Extended help topic';
+ }
+ });
+ keys = Object.keys(cmds);
+ keys.sort();
+ keys.forEach((cmd) => result.push(cmd + ': ' + cmds[cmd]));
+ keys = Object.keys(topics);
+ if (keys.length) {
+ result.push('');
+ result.push('Help Topics:');
+ keys.sort();
+ keys.forEach((topic) => result.push(topic + ': ' + topics[topic]));
+ }
return result.join('\n');
}
@@ -197,7 +223,7 @@ function cmdShutUp(command) {
}
/**
- * Reply with help test top the command !help
+ * Reply with help to the command !help
*
* @param {command} command help command
*/
@@ -210,13 +236,13 @@ function cmdHelp(command) {
ext = command.args.join(' ');
}
if (ext && internals.helpMessages[ext]) {
- const txt = 'Extended help for `' + ext + '`\n\n' + internals.helpMessages[ext] +
+ const txt = 'Help topic for `' + ext + '`\n\n' + internals.helpMessages[ext] +
'\n\nIssue the `help` command without any parameters to see all available commands';
browser.createPost(command.post.topic_id, command.post.post_number, txt, () => 0);
return;
}
- const help = internals.getCommandHelps() + '\n\nMore details may be available by passing a command name as ' +
- 'the first parameter to `help`';
+ const help = internals.getCommandHelps() + '\n\n\* Help topic available.\n\nIssue the `help` command with an ' +
+ 'available help topic as a parameter to read additonal help';
browser.createPost(command.post.topic_id, command.post.post_number, help, () => 0);
}
@@ -277,6 +303,7 @@ function registerHelp(command, helptext, callback) {
if (!helptext || typeof helptext !== 'string') {
return callback(new Error('helptext must be provided'));
}
+ command = command.toLowerCase();
if (internals.helpMessages[command]) {
internals.events.emit('logWarning', 'Overwriting existing extended help for: `' + command + '`!');
}
diff --git a/test/lib/commands/statusTest.js b/test/lib/commands/statusTest.js
index 3478e446..de7d1d19 100644
--- a/test/lib/commands/statusTest.js
+++ b/test/lib/commands/statusTest.js
@@ -138,7 +138,7 @@ describe('status', () => {
});
describe('memoryUsage', () => {
it('should return the correct values', () => {
- const expected = 'Memory usage: 1 kB free out of 2 kB';
+ const expected = 'Memory usage: 1 KB free out of 2 KB';
sandbox.stub(os, 'freemem', () => 1024);
sandbox.stub(os, 'totalmem', () => 2048);
expect(status.internals.memoryUsage()).to.be.equal(expected);
diff --git a/test/lib/commandsTest.js b/test/lib/commandsTest.js
index c2bbfef9..f236c98b 100644
--- a/test/lib/commandsTest.js
+++ b/test/lib/commandsTest.js
@@ -158,6 +158,7 @@ describe('commands', () => {
let sandbox, events;
beforeEach(() => {
commands.internals.commands = {};
+ commands.internals.helpMessages = {};
sandbox = sinon.sandbox.create();
clock = sandbox.useFakeTimers();
events = {
@@ -183,8 +184,8 @@ describe('commands', () => {
});
it('should post expected text', () => {
const expected = 'Registered commands:\nhelp: print command help listing\n' +
- 'shutup: tell me to shutup\n\nMore details may be available by passing ' +
- 'a command name as the first parameter to `help`';
+ 'shutup: tell me to shutup\n\n* Help topic available.\n\nIssue the `help`' +
+ ' command with an available help topic as a parameter to read additonal help';
commands.internals.commands.help = {
help: 'print command help listing'
};
@@ -202,6 +203,57 @@ describe('commands', () => {
browser.createPost.calledWith(15, 75).should.be.true;
browser.createPost.lastCall.args[2].should.equal(expected);
});
+ it('should post expected text with help topics', () => {
+ const expected = 'Registered commands:\nhelp: print command help listing\n\n' +
+ 'Help Topics:\nshutup: Extended help topic\n\n* Help topic available.\n\n' +
+ 'Issue the `help` command with an available help topic as a parameter to ' +
+ 'read additonal help';
+ commands.internals.commands.help = {
+ help: 'print command help listing'
+ };
+ commands.internals.helpMessages.shutup = 'tell me to shutup';
+ cmdHelp({
+ command: 'foobar',
+ post: {
+ 'topic_id': 15,
+ 'post_number': 75
+ }
+ });
+ browser.createPost.callCount.should.equal(1);
+ browser.createPost.calledWith(15, 75).should.be.true;
+ browser.createPost.lastCall.args[2].should.equal(expected);
+ });
+ it('should pass callback to createPost', () => {
+ cmdHelp({
+ command: 'foobar',
+ post: {
+ 'topic_id': 1,
+ 'post_number': 5
+ }
+ });
+ browser.createPost.lastCall.args[3].should.be.a('function');
+ browser.createPost.lastCall.args[3]().should.equal(0);
+ });
+
+ it('should indicate presence of help topic on command', () => {
+ const expected = 'Registered commands:\nhelp: print command help listing *\n\n' +
+ '* Help topic available.\n\nIssue the `help` command with an available help ' +
+ 'topic as a parameter to read additonal help';
+ commands.internals.commands.help = {
+ help: 'print command help listing'
+ };
+ commands.internals.helpMessages.help = 'foobar';
+ cmdHelp({
+ command: 'foobar',
+ post: {
+ 'topic_id': 15,
+ 'post_number': 75
+ }
+ });
+ browser.createPost.callCount.should.equal(1);
+ browser.createPost.calledWith(15, 75).should.be.true;
+ browser.createPost.lastCall.args[2].should.equal(expected);
+ });
it('should pass callback to createPost', () => {
cmdHelp({
command: 'foobar',
@@ -256,7 +308,7 @@ describe('commands', () => {
browser.createPost.lastCall.args[2].should.startWith(expected);
});
it('should post extended help message one word command', () => {
- const expected = 'Extended help for `whosit`\n\nwhosit extended help' +
+ const expected = 'Help topic for `whosit`\n\nwhosit extended help' +
'\n\nIssue the `help` command without any parameters to see all available commands';
commands.internals.helpMessages.whosit = 'whosit extended help';
cmdHelp({
@@ -272,7 +324,7 @@ describe('commands', () => {
browser.createPost.lastCall.args[2].should.equal(expected);
});
it('should post extended help message multi-word command', () => {
- const expected = 'Extended help for `who am i`';
+ const expected = 'Help topic for `who am i`';
commands.internals.helpMessages['who am i'] = 'whosit extended help';
cmdHelp({
command: 'foobar',
@@ -764,13 +816,14 @@ describe('commands', () => {
it('should log registration', () => {
const cmd = 'CMD' + Math.random();
registerHelp(cmd, 'help', spy);
- events.emit.calledWith('logMessage', 'Extended help registered for: ' + cmd).should.be.true;
+ events.emit.calledWith('logMessage', 'Extended help registered for: ' +
+ cmd.toLowerCase()).should.be.true;
});
it('should warn on help overwrite', () => {
const cmd = 'CMD' + Math.random();
- commands.internals.helpMessages[cmd] = 'foo';
+ commands.internals.helpMessages[cmd.toLowerCase()] = 'foo';
registerHelp(cmd, 'help', spy);
- events.emit.calledWith('logWarning', 'Overwriting existing extended help for: `' + cmd +
+ events.emit.calledWith('logWarning', 'Overwriting existing extended help for: `' + cmd.toLowerCase() +
'`!').should.be.true;
});
});
diff --git a/test/plugins/anonymizeTest.js b/test/plugins/anonymizeTest.js
index 8074f8bc..993d7058 100644
--- a/test/plugins/anonymizeTest.js
+++ b/test/plugins/anonymizeTest.js
@@ -121,8 +121,8 @@ describe('anonymize', () => {
const spy = sandbox.stub(browser, 'createPost'),
rawContent = '[quote="SockBot, post:4, topic:3"]Anonymized quote![/quote]Anonymized reply!';
spy.yields(null, {
- topic_id: 5,
- post_number: 6
+ 'topic_id': 5,
+ 'post_number': 6
}); //eslint-disable-line camelcase
anonymize.prepare(undefined, dummyCfg, {
onNotification: () => 0,