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 +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Description:
2
+ # Returns a command from commandlinefu.com
3
+ #
4
+ # Dependencies:
5
+ # None
6
+ #
7
+ # Configuration:
8
+ # None
9
+ #
10
+ # Commands:
11
+ # hubot commandlinefu me - returns random command
12
+ # hubot commandlinefu me <command> - random entry for the comand passed
13
+ #
14
+ # Author:
15
+ # aaronott
16
+
17
+ module .exports = (robot ) ->
18
+ robot .respond / commandlinefu(?: me)? * (. * )? / i , (msg ) ->
19
+ query = if msg .match [1 ]
20
+ " matching/#{ msg .match [1 ]} /#{ new Buffer (msg .match [1 ]).toString (' base64' )} /json"
21
+ else
22
+ " random/json"
23
+ command msg, " http://www.commandlinefu.com/commands/#{ query} " , (cmd ) ->
24
+ msg .send cmd
25
+
26
+ command = (msg , uri , cb ) ->
27
+ msg .http (uri)
28
+ .get () (err , res , body ) ->
29
+ # The random call passes back a 302 to redirect to a new page, if this
30
+ # happens we redirect through a recursive function call passing the new
31
+ # location to retrieve
32
+ if res .statusCode == 302
33
+ command msg, res .headers .location , cb
34
+ else
35
+ # choose a random command from the returned list
36
+ cc = msg .random JSON .parse (body)
37
+ cb (" -- #{ cc .summary } \n #{ cc .command } " )
You can’t perform that action at this time.
0 commit comments