]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
search plugin: enhance 'lucky' output
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 28 Aug 2009 22:56:22 +0000 (00:56 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 28 Aug 2009 22:56:22 +0000 (00:56 +0200)
'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.

data/rbot/plugins/search.rb

index 595dab3c732625a91144ff7ce995dd5c2ba1e747..5745a24be6c9cf7443c23778347316fdf4319251 100644 (file)
@@ -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