From: Giuseppe Bilotta Date: Tue, 6 Feb 2007 16:56:27 +0000 (+0000) Subject: dict plugin: options to set number of hits and first_pars which will be displayed... X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=f5abcb7eff07f436904ad5d88c0651e197c5914c;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git dict plugin: options to set number of hits and first_pars which will be displayed, similar to the ones found in search --- diff --git a/data/rbot/plugins/dict.rb b/data/rbot/plugins/dict.rb index a948fd06..d23df81f 100644 --- a/data/rbot/plugins/dict.rb +++ b/data/rbot/plugins/dict.rb @@ -18,6 +18,13 @@ require 'uri' DEMAURO_LEMMA = /(.*?)(?: - (.*?))<\/anchor>/ class DictPlugin < Plugin + BotConfig.register BotConfigIntegerValue.new('dict.hits', + :default => 3, + :desc => "Number of hits to return from a dictionary lookup") + BotConfig.register BotConfigIntegerValue.new('dict.first_par', + :default => 0, + :desc => "When set to n > 0, the bot will return the first paragraph from the first n dictionary hits") + def initialize super @dmurl = "http://www.demauroparavia.it/" @@ -68,14 +75,19 @@ class DictPlugin < Plugin return true if justcheck text += ": " n = 0 - text += entries[0...5].map { |ar| + hits = @bot.config['dict.hits'] + text += entries[0...hits].map { |ar| n += 1 urls << @dmwaplemma % ar[2] "#{n}. #{Bold}#{ar[0]}#{Bold} - #{ar[1].gsub(/<\/?em>/,'')}: #{@dmurl}#{ar[2]}" }.join(" | ") m.reply text - Utils.get_first_pars urls, 5, :http_util => @bot.httputil, :message => m + first_pars = @bot.config['dict.first_par'] + + return unless first_pars > 0 + + Utils.get_first_pars urls, first_pars, :http_util => @bot.httputil, :message => m end diff --git a/data/rbot/plugins/search.rb b/data/rbot/plugins/search.rb index a10853bf..becfafc2 100644 --- a/data/rbot/plugins/search.rb +++ b/data/rbot/plugins/search.rb @@ -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