forked from github/hubot-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclojure.coffee
More file actions
33 lines (30 loc) · 860 Bytes
/
Copy pathclojure.coffee
File metadata and controls
33 lines (30 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Description:
# Evaluate one line of Clojure script
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot clojure|clj <script> - Evaluate one line of Clojure script
#
# Author:
# jingweno
module.exports = (robot) ->
robot.respond /(clojure|clj)\s+(.*)/i, (msg)->
script = encodeURIComponent(msg.match[2])
msg.http("http://tryclj.com/eval.json?expr=#{script}")
.get() (err, res, body) ->
switch res.statusCode
when 200
result = JSON.parse(body)
if result.error
msg.reply result.message
else
outputs = result.result.split("\n")
for output in outputs
msg.reply output
else
msg.reply "Unable to evaluate script: #{script}. Request returned with the status code: #{res.statusCode}"