Permalink
Browse files

Added goog i'm feeling lucky method

  • Loading branch information...
1 parent f7f8d8c commit f2897b5f70fea92ce150e836ca50bee27cc82151 @hemanth committed Nov 4, 2010
Showing with 6 additions and 8 deletions.
  1. +6 −8 rgbot.rb
View
@@ -4,19 +4,18 @@
class L33ty
-
def initialize(bot_name,bot_password)
@bot = bot_name
@pass = bot_password
@jabber = Jabber::Simple.new(@bot+'@gmail.com',@pass)
end
-
- def invoke(msg)
+
+ def invoke(msg)
restricted_methods=['main','invoke','deliver']
meth=msg.body.split()[0]
self.send(meth,msg) if self.respond_to?(meth) and !restricted_methods.include?(meth)
end
-
+
def deliver(msg,res)
@jabber.deliver(msg.from.node+"@gmail.com",res)
end
@@ -26,11 +25,10 @@ def l33t(msg)
end
def goog(msg)
-
-
-
+ gurl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="+URI.escape(msg.body, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
+ self.deliver(msg,JSON.parse(Net::HTTP.get_response(URI.parse(gurl)).body)['responseData']['results'][0]['url'])
end
-
+
def main
while (true) do
@jabber.received_messages do |msg|

0 comments on commit f2897b5

Please sign in to comment.