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

Commit c0fbb21

Browse files
committed
modified clojure script into haskell version
1 parent e90774d commit c0fbb21

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/scripts/haskell.coffee

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Description:
2+
# Evaluate one line of Haskell
3+
#
4+
# Dependencies:
5+
# None
6+
#
7+
# Configuration:
8+
# None
9+
#
10+
# Commands:
11+
# hubot haskell <script> - Evaluate one line of Haskell
12+
#
13+
# Author:
14+
# edwardgeorge, slightly modified from code by jingweno
15+
16+
HASKELLJSON=""
17+
18+
module.exports = (robot) ->
19+
robot.respond /(haskell)\s+(.*)/i, (msg)->
20+
script = msg.match[2]
21+
22+
msg.http("http://tryhaskell.org/haskell.json")
23+
.query({method: "eval", expr: script})
24+
.headers(Cookie: "HASKELLJSON=#{HASKELLJSON}")
25+
.get() (err, res, body) ->
26+
switch res.statusCode
27+
when 200
28+
if res.headers["set-cookie"]
29+
HASKELLJSON = res.headers["set-cookie"][0].match(/HASKELLJSON=([-a-z0-9]+);/)[1]
30+
result = JSON.parse(body)
31+
32+
if result.error
33+
msg.reply result.error
34+
else
35+
if result.result
36+
outputs = result.result.split("\n")
37+
for output in outputs
38+
msg.reply output
39+
msg.reply result.type
40+
else
41+
msg.reply "Unable to evaluate script: #{script}. Request returned with the status code: #{res.statusCode}"

0 commit comments

Comments
 (0)