forked from github/hubot-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animal.coffee
42 lines (36 loc) · 999 Bytes
/
animal.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
# Description:
# Because animals are animals.
#
# Dependencies:
# "htmlparser": "1.7.6"
# "soupselect": "0.2.0"
#
# Configuration:
# None
#
# Commands:
# hubot animal me - Grab a random gif from http://animalsbeingdicks.com/
#
# Author:
# unsay
Select = require("soupselect").select
HtmlParser = require "htmlparser"
module.exports = (robot) ->
robot.respond /animal me/i, (msg) ->
randimalMe msg, (url) ->
msg.send url
randimalMe = (msg, cb) ->
msg.http("http://animalsbeingdicks.com/random")
.get() (err, res, body) ->
console.log res.headers.location
animalMe msg, res.headers.location, (location) ->
cb location
animalMe = (msg, location, cb) ->
msg.http(location)
.get() (err, res, body) ->
handler = new HtmlParser.DefaultHandler()
parser = new HtmlParser.Parser handler
parser.parseComplete body
img = Select handler.dom, "#content .post .entry img"
console.log img
cb img[0].attribs.src