Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 32 lines (30 sloc) 0.885 kb
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
# Description:
# Show random octocat
#
# Dependencies:
# "xml2js": "0.1.14"
#
# Configuration:
# None
#
# Commands:
# hubot octocat me - a randomly selected octocat
# hubot octocat bomb me <number> - octocat-splosion!
#
# Author:
# joshuaflanagan

xml2js = require('xml2js')

module.exports = (robot) ->
  robot.respond /octocat\s*(?:me)?$/i, (msg) ->
    show_octocats msg, 1
  robot.respond /octocat\s+(?:bomb)\s*(?:me)?\s*(\d+)?/i, (msg) ->
    count = msg.match[1] || 5
    show_octocats msg, count
show_octocats = (msg, count) ->
  msg.http('http://feeds.feedburner.com/Octocats')
    .query(format: 'xml')
    .get() (err, res, body) ->
      parser = new xml2js.Parser()
      parser.parseString body, (err, result) ->
        octocats = (r["content"]["div"]["a"]["img"]["@"]["src"] for r in result["entry"])
        msg.send msg.random octocats for i in [1..count]
Something went wrong with that request. Please try again.