X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fsearch.rb;h=da6881f4d1de3a4d3114e7d7eb8b461f21e5316e;hb=d8cc9bae30308fdaa767d2d4b9a070d1d5b6a2d5;hp=e94d915baf58759b31a221030e9bce988d76bb11;hpb=5ad543d921116629dcfb9abc9bf25bdfbd53dbfd;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/search.rb b/data/rbot/plugins/search.rb index e94d915b..da6881f4 100644 --- a/data/rbot/plugins/search.rb +++ b/data/rbot/plugins/search.rb @@ -64,6 +64,10 @@ class SearchPlugin < Plugin hits = params[:hits] || @bot.config['google.hits'] + first_pars = params[:firstpar] || @bot.config['google.first_par'] + + single = (hits == 1 and first_pars == 1) + begin wml = @bot.httputil.get(url) raise unless wml @@ -82,12 +86,16 @@ class SearchPlugin < Plugin t = Utils.decode_html_entities res[2].gsub(filter, '').strip u = URI.unescape res[1] urls.push(u) - "#{n}. #{Bold}#{t}#{Bold}: #{u}" + single ? u : "#{n}. #{Bold}#{t}#{Bold}: #{u}" }.join(" | ") - m.reply "Results for #{what}: #{results}", :split_at => /\s+\|\s+/ + # 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)] + return + end - first_pars = params[:firstpar] || @bot.config['google.first_par'] + m.reply "Results for #{what}: #{results}", :split_at => /\s+\|\s+/ return unless first_pars > 0