diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-09-12 21:50:02 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-09-12 21:50:02 +0200 |
commit | e544dadd545d4cd7f145d802109957fd8f866b41 (patch) | |
tree | f42e784d94ca88738506d737722789a2ed88e0ec /data | |
parent | 4ff73e4ef177a4bc07e90fd3133874e326448640 (diff) |
search plugin: cleanup and fix results Array vs String mismatch
Diffstat (limited to 'data')
-rw-r--r-- | data/rbot/plugins/search.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/data/rbot/plugins/search.rb b/data/rbot/plugins/search.rb index 95b88a0c..e7712f77 100644 --- a/data/rbot/plugins/search.rb +++ b/data/rbot/plugins/search.rb @@ -91,11 +91,14 @@ class SearchPlugin < 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| @@ -108,20 +111,22 @@ class SearchPlugin < Plugin :sep => (single ? " -- " : ": "), :b => Bold, :t => t, :u => u } - }.join(" | ") + } 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 |