diff --git a/bing.coffee b/bing.coffee index 5d743c3..c2b2c31 100644 --- a/bing.coffee +++ b/bing.coffee @@ -1,26 +1,50 @@ - # Description: -# Returns the URL of the first bing hit for a query +# Find the latest Bitcoin price in specified currency # # Dependencies: -# None +# "cheerio": "" # # Configuration: # None # # Commands: -# hubot bing me - Bings & returns 1st result's URL +# hubot bitcoin price (in) # # Author: -# Brandon Satrom +# Fred Wu + +cheerio = require('cheerio') module.exports = (robot) -> - robot.respond /(bing)( me)? (.*)/i, (msg) -> - bingMe msg, msg.match[3], (url) -> - msg.send url + robot.respond /bitcoin price\s(in\s)?(.*)/i, (msg) -> + currency = msg.match[2].trim().toUpperCase() + bitcoinPrice(msg, currency) -bingMe = (msg, query, cb) -> - msg.http('http://www.bing.com/search') - .query(q: query) +bitcoinPrice = (msg, currency) -> + msg + .send "Looking up... sit tight..." + msg + .http("http://bitcoinprices.com/") .get() (err, res, body) -> - cb body.match(/