Permalink
Browse files

Merge pull request #5 from searls/master

google me script
  • Loading branch information...
2 parents df62eba + 796f7be commit a5e6fcf1c01451660f31517c4616d2736fc31627 @atmos atmos committed Oct 26, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 src/scripts/google.coffee
View
@@ -0,0 +1,15 @@
+# Returns the URL of the first google hit for a query
+#
+# google me <query> - Googles <query> & returns 1st result's URL
+
+module.exports = (robot) ->
+ robot.respond /(google)( me)? (.*)/i, (msg) ->
+ googleMe msg, msg.match[3], (url) ->
+ msg.send url
+
+googleMe = (msg, query, cb) ->
+ msg.http('http://www.google.com/search')
+ .query(q: query)
+ .get() (err, res, body) ->
+ cb body.match(/<a href="([^"]*)" class=l>/)?[1] || "Sorry, Google had zero results for '#{query}'"
+

0 comments on commit a5e6fcf

Please sign in to comment.