5 GOOGLE_WAP_LINK = /<a accesskey="(\d)" href=".*?u=(.*?)">(.*?)<\/a>/im
7 class SearchPlugin < Plugin
8 def help(plugin, topic="")
11 "search <string> => search google for <string>"
13 "google <string> => search google for <string>"
15 "wp [<code>] <string> => search for <string> on Wikipedia. You can select a national <code> to only search the national Wikipedia"
17 "search <string> (or: google <string>) => search google for <string> | wp <string> => search for <string> on Wikipedia"
22 what = params[:words].to_s
23 searchfor = URI.escape what
25 site = "site:#{params[:site]}+"
30 url = "http://www.google.com/wml/search?q=#{site}#{searchfor}"
34 wml = @bot.httputil.get(url)
36 m.reply "error googling for #{what}"
39 results = wml.scan(GOOGLE_WAP_LINK)
40 if results.length == 0
41 m.reply "no results found for #{what}"
44 results = results[0...3].map { |res|
45 "#{res[0]}. #{Bold}#{Utils.decode_html_entities res[2].strip}#{Bold}: #{URI.unescape res[1].strip}"
48 m.reply "Results for #{what}: #{results}"
51 def wikipedia(m, params)
53 site = "#{lang.nil? ? '' : lang + '.'}wikipedia.org"
55 return google(m, params)
59 plugin = SearchPlugin.new
61 plugin.map "search *words", :action => 'google'
62 plugin.map "google *words", :action => 'google'
63 plugin.map "wp :lang *words", :action => 'wikipedia', :requirements => { :lang => /^\w\w\w?$/ }
64 plugin.map "wp *words", :action => 'wikipedia'