Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 31 lines (28 sloc) 0.802 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
# Description:
# Pokemon fun!
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# pokefact - get a random pokefact!
#
# Author:
# eliperkins

module.exports = (robot) ->

  robot.respond /pokefact/i, (msg) ->
    msg.http('https://api.twitter.com/1/statuses/user_timeline.json')
      .query(screen_name: 'pokefacts', count: 100)
      .get() (err, res, body) ->
        tweets = JSON.parse(body)
        msg.send tweets.length
        if tweets? and tweets.length > 0
          tweet = msg.random tweets
          while(tweet.text.toLowerCase().indexOf('#pokefact') == -1)
            tweet = msg.random tweets
          msg.send "PokeFACT: " + tweet.text.replace(/\#pokefact/i, "");
        else
          msg.reply "Couldn't find a PokeFACT"
Something went wrong with that request. Please try again.