summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/search.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-08-29 00:56:22 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-08-29 00:56:22 +0200
commite63551c50a03a70d32455697112ee72c6006dd19 (patch)
treed9d6bcf84a860f063f9f8285fc90e2fb5a2623d8 /data/rbot/plugins/search.rb
parent7d51d43a4f03a7529f30ed71fa807e9279aec39a (diff)
search plugin: enhance 'lucky' output
'lucky' search only selects the first hit, so set hit to 1 and enable 'single' mode. Also rework the results output, and make a custom 'title -- url' for lucky mode.
Diffstat (limited to 'data/rbot/plugins/search.rb')
-rw-r--r--data/rbot/plugins/search.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/data/rbot/plugins/search.rb b/data/rbot/plugins/search.rb
index 595dab3c..5745a24b 100644
--- a/data/rbot/plugins/search.rb
+++ b/data/rbot/plugins/search.rb
@@ -73,10 +73,11 @@ class SearchPlugin < 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)
@@ -98,11 +99,15 @@ class SearchPlugin < Plugin
t = Utils.decode_html_entities res[2].gsub(filter, '').strip
u = URI.unescape(res[0] || res[1])
urls.push(u)
- single ? u : "#{n}. #{Bold}#{t}#{Bold}: #{u}"
+ "%{n}%{b}%{t}%{b}%{sep}%{u}" % {
+ :n => (single ? "" : "#{n}. "),
+ :sep => (single ? " -- " : ": "),
+ :b => Bold, :t => t, :u => u
+ }
}.join(" | ")
if params[:lucky]
- m.reply urls.first
+ m.reply results.first
return
end