X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fdict.rb;h=ca5f25882147c94cb7c268cb5d27e31dda216fa6;hb=9a565bfd48c59ac9c1b37d5afe9b8640889632ff;hp=95d9fe2e08cd9cb7605dbc9a2e2a807a0761e5ac;hpb=47fd0312cf67aab35ba3cfd3ef898f83b09a7f0f;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/dict.rb b/data/rbot/plugins/dict.rb index 95d9fe2e..ca5f2588 100644 --- a/data/rbot/plugins/dict.rb +++ b/data/rbot/plugins/dict.rb @@ -22,10 +22,10 @@ DEMAURO_LEMMA = /(.*?)(?: - (.*?))<\/an CHAMBERS_LEMMA = /

(.*?)<\/span> (.*?)<\/span>(.*?)<\/p>/ class DictPlugin < Plugin - BotConfig.register BotConfigIntegerValue.new('dict.hits', + Config.register Config::IntegerValue.new('dict.hits', :default => 3, :desc => "Number of hits to return from a dictionary lookup") - BotConfig.register BotConfigIntegerValue.new('dict.first_par', + Config.register Config::IntegerValue.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") @@ -73,7 +73,7 @@ class DictPlugin < Plugin entries = xml.scan(DEMAURO_LEMMA) text = word urls = [] - if !entries.assoc(word) and !entries.assoc(word.upcase) + if not entries.transpose.first.grep(/\b#{word}\b/) return false if justcheck text += " not found. Similar words" end @@ -93,7 +93,7 @@ class DictPlugin < Plugin return unless first_pars > 0 Utils.get_first_pars urls, first_pars, :message => m, - :strip => /^\S+\s+-\s+/ + :strip => /^.+?\s+-\s+/ end @@ -108,9 +108,14 @@ class DictPlugin < Plugin word = params[:word].join [word, word + "_1"].each { |check| url = @oxurl % CGI.escape(check) - h = @bot.httputil.head(url, :max_redir => 5) - if h - m.reply("#{word} found: #{url}") unless justcheck + if params[:british] + url << "?view=uk" + end + h = @bot.httputil.get(url, :max_redir => 5) + if h and h.match(%r!

#{word}(?:1)?

!) + m.reply("#{word} : #{url}") unless justcheck + defn = $' + m.reply("#{Bold}%s#{Bold}: %s" % [word, defn.ircify_html(:nbsp => :space)], :overlong => :truncate) return true end } @@ -119,7 +124,7 @@ class DictPlugin < Plugin end def is_british?(word) - return oxford(nil, :word => word, :justcheck => true) + return oxford(nil, :word => word, :justcheck => true, :british => true) end