diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2009-10-18 01:50:40 +0000 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2009-10-18 01:50:40 +0000 |
commit | 8025cddaf006a62b03c95a20e04faf877394c824 (patch) | |
tree | 643d9fafa3aa6af77fa3237435a0372a8e67a4e2 /gentoo-search.rb | |
parent | Dupe the change from the master plugins. (diff) | |
download | rbot-gentoo-8025cddaf006a62b03c95a20e04faf877394c824.tar.gz rbot-gentoo-8025cddaf006a62b03c95a20e04faf877394c824.tar.bz2 rbot-gentoo-8025cddaf006a62b03c95a20e04faf877394c824.zip |
Bug #286552: Google changed their WAP url and broke stuff. Port this from the main rbot fixes.
Diffstat (limited to 'gentoo-search.rb')
-rw-r--r-- | gentoo-search.rb | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/gentoo-search.rb b/gentoo-search.rb index 9644c19..46cc8f2 100644 --- a/gentoo-search.rb +++ b/gentoo-search.rb @@ -1,10 +1,7 @@ #-- 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 accesskey="(\d)" href=".*?u=(.*?)">(.*?)<\/a>/im -GOOGLE_CALC_RESULT = %r{<img src=/images/calc_img\.gif(?: width=40 height=30 alt="")?></td><td> </td><td nowrap>(?:<h2 class=r>)?<font size=\+1><b>(.+)</b>(?:</h2>)?</td>} -GOOGLE_DEF_RESULT = %r{<p> (Web definitions for .*?)<br/>(.*?)<br/>(.*?)\s-\s+<a href} +GOOGLE_WAP_LINK = /<a href="(?:.*?u=(.*?)|(http:\/\/.*?))">(.*?)<\/a>/im class GentooSearchPlugin < Plugin def listen(m) @@ -38,10 +35,11 @@ class GentooSearchPlugin < Plugin url = GOOGLE_WAP_SEARCH + site + searchfor hits = params[:hits] || @bot.config['google.hits'] + hits = 1 if params[:lucky] first_pars = params[:firstpar] || @bot.config['google.first_par'] - single = (hits == 1 and first_pars == 1) + single = params[:lucky] || (hits == 1 and first_pars == 1) begin wml = @bot.httputil.get(url) @@ -51,27 +49,41 @@ class GentooSearchPlugin < Plugin 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 + n = 0 results = results[0...hits].map { |res| - n = res[0] - t = Utils.decode_html_entities res[2].gsub(filter, '').strip - u = URI.unescape res[1] + n += 1 + t = res[2].ircify_html(:img => "[%{src} %{alt} %{dimensions}]").strip + u = URI.unescape(res[0] || res[1]) urls.push(u) - single ? u : "#{n}. #{Bold}#{t}#{Bold}: #{u}" - }.join(" | ") + "%{n}%{b}%{t}%{b}%{sep}%{u}" % { + :n => (single ? "" : "#{n}. "), + :sep => (single ? " -- " : ": "), + :b => Bold, :t => t, :u => u + } + } + + if params[:lucky] + m.reply results.first + return + end + + result_string = results.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 + m.reply "Result for %s: %s -- %s" % [what, result_string, Utils.get_first_pars(urls, first_pars)], :overlong => :truncate return end - m.reply "Results for #{what}: #{results}", :split_at => /\s+\|\s+/ + m.reply "Results for #{what}: #{result_string}", :split_at => /\s+\|\s+/ return unless first_pars > 0 |