5 GOOGLE_WAP_LINK = /<a accesskey="(\d)" href=".*?u=(.*?)">(.*?)<\/a>/im
7 class SearchPlugin < Plugin
8 def help(plugin, topic="")
9 "google <string> => search google for <string>"
13 what = params[:words].to_s
14 searchfor = URI.escape what
16 url = "http://www.google.com/wml/search?q=#{searchfor}"
20 wml = @bot.httputil.get(url)
22 m.reply "error googling for #{what}"
25 results = wml.scan(GOOGLE_WAP_LINK)
26 if results.length == 0
27 m.reply "no results found for #{what}"
30 results = results[0...3].map { |res|
31 "#{res[0]}. #{Bold}#{Utils.decode_html_entities res[2].strip}#{Bold}: #{URI.unescape res[1].strip}"
34 m.reply "Results for #{what}: #{results}"
38 plugin = SearchPlugin.new
40 plugin.map "search *words", :action => 'google'
41 plugin.map "google *words", :action => 'google'