Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 67a4728

Browse files
author
Tom Bell
committed
Merge pull request #968 from minton/rhubot
Add rhubot support to Hubot.
2 parents 219ab24 + 0c3f9bb commit 67a4728

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/scripts/rhubot.coffee

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Description:
2+
# Teach Hubot to play nice with Ruby via rhubot (https://github.com/minton/rhubot)
3+
#
4+
# Dependencies:
5+
# None
6+
#
7+
# Configuration:
8+
# RHUBOT_PATH - Path to Rhubot
9+
# HUBOT_URL - URL to Hubot HTTP router - http://192.168.0.0:8080
10+
#
11+
# Commands:
12+
# rb <cmd> <args> - Runs a Ruby script named <cmd> sending the arguments <args>.
13+
#
14+
# Author:
15+
# @mcminton
16+
17+
sh = require('sh')
18+
scriptPath = process.env.RHUBOT_SCRIPT_PATH
19+
routerPost = "/hubot/rhubot"
20+
httpUrl = process.env.HUBOT_URL + routerPost
21+
22+
module.exports = (robot) ->
23+
robot.hear /rb\s{1}([^\s]+)\s{1}(.+)/i, (msg) ->
24+
script = msg.match[1]
25+
scriptArgs = msg.match[2]
26+
console.log "Running #{script} #{scriptArgs}"
27+
data = ''
28+
spawn = require('child_process').spawn
29+
proc = spawn "ruby", ["#{scriptPath}/rhubot.rb", httpUrl, msg.message.user.room, script, scriptArgs]
30+
me = this
31+
proc.stdout.on 'data', (chunk) ->
32+
data += chunk.toString()
33+
proc.stderr.on 'data', (chunk) ->
34+
msg.send chunk.toString()
35+
proc.stdout.on 'end', () ->
36+
msg.send data.toString()
37+
38+
39+
robot.router.post routerPost, (req, res) ->
40+
user = robot.userForId 'broadcast'
41+
user.room = req.body.room
42+
user.type = 'groupchat'
43+
result = req.body.result
44+
robot.send user, "#{result}"
45+
res.end "O.o"
46+

0 commit comments

Comments
 (0)