#-- vim:sw=2:et:ft=ruby
GOOGLE_SEARCH = "http://www.google.com/search?oe=UTF-8&q="
GOOGLE_WAP_SEARCH = "http://www.google.com/m/search?hl=en&q="
GOOGLE_WAP_LINK = /(.*?)<\/a>/im
GOOGLE_CALC_RESULT = %r{
| (?:)?(.+)(?:)? | }
GOOGLE_DEF_RESULT = %r{ (Web definitions for .*?)
(.*?)
(.*?)\s-\s+ e
m.reply "error googling for #{what}"
return
end
results = wml.scan(GOOGLE_WAP_LINK)
if results.length == 0
m.reply "no results found for #{what}"
return
end
single ||= (results.length==1)
urls = Array.new
results = results[0...hits].map { |res|
n = res[0]
t = Utils.decode_html_entities res[2].gsub(filter, '').strip
u = URI.unescape res[1]
urls.push(u)
single ? u : "#{n}. #{Bold}#{t}#{Bold}: #{u}"
}.join(" | ")
# If we return a single, full result, change the output to a more compact representation
if single
m.reply "Result for %s: %s -- %s" % [what, results, Utils.get_first_pars(urls, first_pars)], :overlong => :truncate
return
end
m.reply "Results for #{what}: #{results}", :split_at => /\s+\|\s+/
return unless first_pars > 0
Utils.get_first_pars urls, first_pars, :message => m
end
end
plugin = GentooSearchPlugin.new
#plugin.map "? *words", :action => 'gentoo_search', :threaded => true