]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
dict plugin: options to set number of hits and first_pars which will be displayed...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 6 Feb 2007 16:56:27 +0000 (16:56 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 6 Feb 2007 16:56:27 +0000 (16:56 +0000)
data/rbot/plugins/dict.rb
data/rbot/plugins/search.rb

index a948fd06befc2bbfa2bc18f1642efb6aa680b982..d23df81f319a28935b9bcfe9989c3913590fe8a0 100644 (file)
@@ -18,6 +18,13 @@ require 'uri'
 DEMAURO_LEMMA = /<anchor>(.*?)(?: - (.*?))<go href="lemma.php\?ID=(\d+)"\/><\/anchor>/\r
 \r
 class DictPlugin < Plugin\r
+  BotConfig.register BotConfigIntegerValue.new('dict.hits',\r
+    :default => 3,\r
+    :desc => "Number of hits to return from a dictionary lookup")\r
+  BotConfig.register BotConfigIntegerValue.new('dict.first_par',\r
+    :default => 0,\r
+    :desc => "When set to n > 0, the bot will return the first paragraph from the first n dictionary hits")\r
+\r
   def initialize\r
     super\r
     @dmurl = "http://www.demauroparavia.it/"\r
@@ -68,14 +75,19 @@ class DictPlugin < Plugin
     return true if justcheck\r
     text += ": "\r
     n = 0\r
-    text += entries[0...5].map { |ar|\r
+    hits = @bot.config['dict.hits']\r
+    text += entries[0...hits].map { |ar|\r
       n += 1\r
       urls << @dmwaplemma % ar[2]\r
       "#{n}. #{Bold}#{ar[0]}#{Bold} - #{ar[1].gsub(/<\/?em>/,'')}: #{@dmurl}#{ar[2]}"\r
     }.join(" | ")\r
     m.reply text\r
 \r
-    Utils.get_first_pars urls, 5, :http_util => @bot.httputil, :message => m\r
+    first_pars = @bot.config['dict.first_par']\r
+\r
+    return unless first_pars > 0\r
+\r
+    Utils.get_first_pars urls, first_pars, :http_util => @bot.httputil, :message => m\r
 \r
   end\r
 \r
index a10853bf868ac6ec1e7ca2b7802715e33da872a2..becfafc2368eb9717ee87ba60f5eec6d80d11a25 100644 (file)
@@ -74,6 +74,8 @@ class SearchPlugin < Plugin
 
     first_pars = params[:firstpar] || @bot.config['google.first_par']
 
+    return unless first_pars > 0
+
     Utils.get_first_pars urls, first_pars, :http_util => @bot.httputil, :message => m
 
   end