Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge forked fixes #46

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
"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",
"semantic-release": "^6.3.6"
"standard": "^10.0.2"
},
"main": "index.coffee",
"scripts": {
Expand Down
8 changes: 3 additions & 5 deletions src/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ 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]
Expand All @@ -74,9 +72,9 @@ module.exports = (robot) => {

const emit = cmds.join('\n')

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)
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)
} else {
return msg.send(emit)
}
Expand Down
57 changes: 57 additions & 0 deletions test/help_message_visibility_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'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.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 <query> - Displays all help commands that match <query>.']
])
}).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 <query> - Displays all help commands that match <query>.']
]
})
}).then(done, done)
}))
}))