]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
search: add command 'lucky'
authorRaine Virta <rane@kapsi.fi>
Tue, 24 Feb 2009 17:17:54 +0000 (19:17 +0200)
committerRaine Virta <rane@kapsi.fi>
Wed, 25 Feb 2009 23:09:20 +0000 (01:09 +0200)
Sometimes you just wish to google the first hit and have a clutter free
output showing only the url.

data/rbot/plugins/search.rb

index a7ac64cb78427e9ee41a32d58ee74cd4c275a23f..542f7cba2ec2306494eb1a24725b32dfcd9f8611 100644 (file)
@@ -96,6 +96,11 @@ class SearchPlugin < Plugin
       single ? u : "#{n}. #{Bold}#{t}#{Bold}: #{u}"
     }.join(" | ")
 
+    if params[:lucky]
+      m.reply urls.first
+      return
+    end
+
     # 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
@@ -110,6 +115,11 @@ class SearchPlugin < Plugin
 
   end
 
+  def lucky(m, params)
+    params.merge!(:lucky => true)
+    google(m, params)
+  end
+
   def gcalc(m, params)
     what = params[:words].to_s
     searchfor = CGI.escape(what)
@@ -224,6 +234,7 @@ plugin = SearchPlugin.new
 
 plugin.map "search *words", :action => 'google', :threaded => true
 plugin.map "google *words", :action => 'google', :threaded => true
+plugin.map "lucky *words", :action => 'lucky', :threaded => true
 plugin.map "gcount *words", :action => 'gcount', :threaded => true
 plugin.map "gcalc *words", :action => 'gcalc', :threaded => true
 plugin.map "gdef *words", :action => 'gdef', :threaded => true