Skip to content

Instantly share code, notes, and snippets.

@kyleknighted
Created May 18, 2012 19:25
Show Gist options
  • Save kyleknighted/2727191 to your computer and use it in GitHub Desktop.
Save kyleknighted/2727191 to your computer and use it in GitHub Desktop.
Hubot Random Bouncebreak.com Image
# Bounce Break script
#
# bounce me - Send a random bouncebreak.com image
htmlparser = require "htmlparser"
module.exports = (robot) ->
robot.respond /(bounce|bouncebreak)( me)?/i, (msg) ->
bounceBreakCall msg, (image_url) ->
msg.send image_url
bounceBreakRegexp = /img src="(http:\/\/i.imgur.com\/[^"]+)"/
bounceBreakCall = (msg, cb) ->
msg.http("http://bouncebreak.tumblr.com/rss")
.get() (err, res, body) ->
handler = new htmlparser.RssHandler (error, dom) ->
return if error || !dom
item_length = dom.items.length
item = dom.items[Math.floor(Math.random() * (item_length - 1))]
match = item.description.match(bounceBreakRegexp)
cb match[1] if match
try
parser = new htmlparser.Parser(handler)
parser.parseComplete(body)
catch ex
msg.send "Erm, something went EXTREMELY wrong - #{ex}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment