Skip to content
This repository
Tom Bell tombell
file 25 lines (23 sloc) 0.614 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
# Description:
# Returns the URL of the first bing hit for a query
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot bing me <query> - Bings <query> & returns 1st result's URL
#
# Author:
# Brandon Satrom

module.exports = (robot) ->
  robot.respond /(bing)( me)? (.*)/i, (msg) ->
    bingMe msg, msg.match[3], (url) ->
      msg.send url

bingMe = (msg, query, cb) ->
  msg.http('http://www.bing.com/search')
    .query(q: query)
    .get() (err, res, body) ->
      cb body.match(/<div class="sb_tlst"><h3><a href="([^"]*)"/)?[1] || "Sorry, Bing had zero results for '#{query}'"
Something went wrong with that request. Please try again.