-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava-repl.coffee
45 lines (41 loc) · 1.32 KB
/
java-repl.coffee
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
34
35
36
37
38
39
40
41
42
43
44
45
# Description
# Hubot reads, evaluates, prints and makes you loop java expressions
#
# Configuration:
# LIST_OF_ENV_VARS_TO_SET
#
# Commands:
# hubot hello - <what the respond trigger does>
# orly - <what the hear trigger does>
#
# Notes:
# <optional notes required for the script>
#
# Author:
# Tyler Hoersch <[email protected]>
module.exports = (robot) ->
robot.respond /(java) (me)? (.*)/i, (msg) ->
expression = urlFormEncode(msg.match[3])
create_url = "http://www.javarepl.com/create"
execute_url = "http://www.javarepl.com/execute"
msg.http(create_url)
.header("Content-Type", "application/x-www-form-urlencoded")
.post("") (err, res, body) ->
if err
msg.reply "RUH ROH! Errors!", inspect(err)
return
jsonBody = JSON.parse(body)
id = jsonBody.id
data = "id=#{id}&expression=#{expression}"
msg.http(execute_url)
.header("Content-Type", "application/x-www-form-urlencoded")
.post(data) (err, res, body) ->
if err
msg.reply "RUH ROH! Errors!", inspect(err)
return
jsonBody = JSON.parse(body)
msg.send jsonBody.logs[0].message
urlFormEncode = (str) ->
escape(str)
.replace(new RegExp('\\+','g'),'%2B')
.replace(new RegExp('%20','g'),'+')