diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 15:59:13 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 15:59:13 +0000 |
commit | 21949774b91eaec6ecde4eaa8ad121e2c0a36b87 (patch) | |
tree | 41a7601e168018ac203bad7ca8d7f9f82515bc28 /data/rbot/plugins/google.rb | |
parent | 51cf09ec02d089bfdd80e5f728cfc92a234dc437 (diff) |
rearrange repo for packaging
Diffstat (limited to 'data/rbot/plugins/google.rb')
-rw-r--r-- | data/rbot/plugins/google.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/data/rbot/plugins/google.rb b/data/rbot/plugins/google.rb new file mode 100644 index 00000000..cd96f23c --- /dev/null +++ b/data/rbot/plugins/google.rb @@ -0,0 +1,51 @@ +require 'net/http' +require 'uri/common' + +Net::HTTP.version_1_2 + +class GooglePlugin < Plugin + def help(plugin, topic="") + "search <string> => search google for <string>" + end + def privmsg(m) + unless(m.params && m.params.length > 0) + m.reply "incorrect usage: " + help(m.plugin) + return + end + searchfor = URI.escape m.params + + query = "/search?q=#{searchfor}&btnI=I%27m%20feeling%20lucky" + result = "not found!" + + proxy_host = nil + proxy_port = nil + + if(ENV['http_proxy']) + if(ENV['http_proxy'] =~ /^http:\/\/(.+):(\d+)$/) + proxy_host = $1 + proxy_port = $2 + end + end + + http = @bot.httputil.get_proxy(URI.parse("http://www.google.com")) + + begin + http.start {|http| + resp = http.get(query) + if resp.code == "302" + result = resp['location'] + end + } + rescue => e + p e + if e.response && e.response['location'] + result = e.response['location'] + else + result = "error!" + end + end + m.reply "#{m.params}: #{result}" + end +end +plugin = GooglePlugin.new +plugin.register("search") |