Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 32 lines (29 sloc) 0.805 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
# Description:
# None
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot horse - Display a randomly selected insight on the world from Horse_Ebooks
#
# Author:
# lavelle

module.exports = (robot) ->
    robot.respond /horse/i, (msg) ->
        url = 'http://api.twitter.com/1/statuses/user_timeline.json'
        msg
            .http(url)
            .query
                screen_name: 'horse_ebooks'
                count: 10
            .get() (err, res, body) ->
                tweets = JSON.parse(body)

                if tweets? and tweets.length > 0
                    n = Math.floor Math.random() * tweets.length or 0
                    msg.send(tweets[n].text)
                else
                    msg.reply "Couldn't find any insights for you this time"
Something went wrong with that request. Please try again.