This repository was archived by the owner on Jun 8, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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 } "
You can’t perform that action at this time.
0 commit comments