diff --git a/package.json b/package.json index b6dd7ae..b0941e5 100644 --- a/package.json +++ b/package.json @@ -33,14 +33,13 @@ "grunt-release": "^0.14.0", "hubot": "^3.0.0", "hubot-mock-adapter-v3": "^1.0.0", - "hubot-test-helper": "^1.8.1", "matchdep": "^0.1.2", "mocha": "^3.0.2", "nyc": "^11.0.3", - "semantic-release": "^6.3.6", "sinon": "^1.4.2", "sinon-chai": "^2.8.0", - "standard": "^10.0.2" + "standard": "^10.0.2", + "semantic-release": "^6.3.6" }, "main": "index.coffee", "scripts": { diff --git a/src/help.js b/src/help.js index 323bad3..33ee91c 100644 --- a/src/help.js +++ b/src/help.js @@ -58,6 +58,8 @@ const helpContents = (name, commands) => `\ ` module.exports = (robot) => { + const replyInPrivate = process.env.HUBOT_HELP_REPLY_IN_PRIVATE + robot.respond(/help(?:\s+(.*))?$/i, (msg) => { let cmds = getHelpCommands(robot) const filter = msg.match[1] @@ -72,9 +74,9 @@ module.exports = (robot) => { const emit = cmds.join('\n') - if (process.env.HUBOT_HELP_REPLY_IN_PRIVATE && msg.message && msg.message.user && msg.message.user.name && msg.message.user.name !== msg.message.room) { - msg.reply('I just replied to you in private.') - return msg.sendPrivate(emit) + if (replyInPrivate && msg.message && msg.message.user && msg.message.user.name && msg.message.user.name !== msg.message.room) { + msg.reply('replied to you in private!') + return robot.send({ room: msg.message.user.name }, emit) } else { return msg.send(emit) } diff --git a/test/help_message_visibility_test.js b/test/help_message_visibility_test.js deleted file mode 100644 index 8d598eb..0000000 --- a/test/help_message_visibility_test.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict' - -/* global describe, beforeEach, afterEach, it, context */ - -const chai = require('chai') -const expect = chai.expect - -chai.use(require('sinon-chai')) - -const Helper = require('hubot-test-helper') - -const helper = new Helper('../src/help.js') - -describe('help', () => describe('message visibility', () => { - beforeEach(function () { - this.timeout(5000) - this.room = helper.createRoom() - }) - - afterEach(function () { - this.room.destroy() - }) - - context('when HUBOT_HELP_REPLY_IN_PRIVATE is unset', () => it('replies in the same room', function (done) { - this.room.user.say('john', '@hubot help help').then(() => { - expect(this.room.messages).to.eql([ - ['john', '@hubot help help'], - ['hubot', 'hubot help - Displays all of the help commands that this bot knows about.\nhubot help - Displays all help commands that match .'] - ]) - }).then(done, done) - })) -})) - -describe('help', () => describe('message visibility', () => { - beforeEach(function () { - process.env.HUBOT_HELP_REPLY_IN_PRIVATE = true - this.room = helper.createRoom() - }) - - afterEach(function () { - delete process.env.HUBOT_HELP_REPLY_IN_PRIVATE - this.room.destroy() - }) - - context('when HUBOT_HELP_REPLY_IN_PRIVATE is set', () => it('replies in a private message', function (done) { - this.room.user.say('john', '@hubot help help').then(() => { - expect(this.room.messages).to.eql([ - ['john', '@hubot help help'], - ['hubot', '@john I just replied to you in private.'] - ]) - expect(this.room.privateMessages).to.eql({ - john: [ - ['hubot', 'hubot help - Displays all of the help commands that this bot knows about.\nhubot help - Displays all help commands that match .'] - ] - }) - }).then(done, done) - })) -}))