Advertisement
leathan

bing.coffee (fixed)

Jun 27th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Description:
  2. #   Returns the URL of the first bing hit for a query
  3. #
  4. # Dependencies:
  5. #   None
  6. #
  7. # Configuration:
  8. #   None
  9. #
  10. # Commands:
  11. #   hubot bing me <query> - Bings <query> & returns 1st result's URL
  12. #
  13. # Author:
  14. #   leathan
  15.  
  16. module.exports = (robot) ->
  17.   robot.hear /^(bing)( me)? (.*)/i, (msg) ->
  18.     bingMe msg, msg.match[3], (url) ->
  19.       msg.send url
  20.  
  21. bingMe = (msg, query, cb) ->
  22.   msg.http('http://www.bing.com/search')
  23.     .query(q: query)
  24.     .get() (err, res, body) ->
  25.       cb body.match(/<li class="b_algo"><h2><a href="([^"]*)"/)?[1] || "Sorry, Bing had zero results for '#{query}'"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement