From: Matthias H Date: Thu, 20 Feb 2014 01:14:25 +0000 (+0100) Subject: [plugins] fixed oxford only, all others are broken. X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=1b6e5e788b8ad6dc910710498eb22d2d8cbdf869;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git [plugins] fixed oxford only, all others are broken. Removed the broken dicts except for oxford, renamed the plugin. --- diff --git a/data/rbot/plugins/dict.rb b/data/rbot/plugins/dict.rb deleted file mode 100644 index 9b8e2139..00000000 --- a/data/rbot/plugins/dict.rb +++ /dev/null @@ -1,250 +0,0 @@ -# encoding: UTF-8 -#-- vim:sw=2:et -#++ -# -# :title: Dictionary lookup plugin for rbot -# -# Author:: Giuseppe "Oblomov" Bilotta -# Copyright:: (C) 2006-2007 Giuseppe Bilotta -# License:: GPL v2 -# -# Provides a link to the definition of a word in one of the supported -# dictionaries. Currently available are -# * the Oxford dictionary for (British) English -# * the De Mauro/Paravia dictionary for Italian -# * the Chambers dictionary for English (accepts both US and UK) -# * the Littré dictionary for French -# -# Other plugins can use this one to check if a given word is valid in italian -# or english or french by using the is_italian?, is_british?, is_english?, -# is_french? methods -# -# TODO: cache results and reuse them if get_cached returns a cache copy - -DEMAURO_LEMMA = /(.*?)(?: - (.*?))<\/anchor>/ -CHAMBERS_LEMMA = /

(.*?)<\/span> (.*?)<\/span>(.*?)<\/p>/ - -class DictPlugin < Plugin - Config.register Config::IntegerValue.new('dict.hits', - :default => 3, - :desc => "Number of hits to return from a dictionary lookup") - 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") - - def demauro_filter(s) - # check if it's a page we can handle - loc = Utils.check_location(s, @dmurlrx) - # the location might be not good, but we might still be able to handle the - # page - if !loc and s[:text] !~ //m) - hits = @bot.config['dict.hits'] - n = 0 - entries[0...hits].map { |ar| - n += 1 - m.reply(("#{Bold}#{n}#{Bold} %s" % ar).ircify_html, :overlong => :truncate) - } - end - - def is_french?(word) - return littre(nil, :word => word, :justcheck => true) - end - -end - -plugin = DictPlugin.new -plugin.map 'demauro :word', :action => 'demauro', :thread => true -plugin.map 'oxford *word', :action => 'oxford', :thread => true -plugin.map 'chambers *word', :action => 'chambers', :thread => true -plugin.map 'littre *word', :action => 'littre', :thread => true - diff --git a/data/rbot/plugins/oxford.rb b/data/rbot/plugins/oxford.rb new file mode 100644 index 00000000..99041713 --- /dev/null +++ b/data/rbot/plugins/oxford.rb @@ -0,0 +1,62 @@ +# encoding: UTF-8 +#-- vim:sw=2:et +#++ +# +# :title: Oxford Dictionary lookup plugin for rbot +# +# Author:: Giuseppe "Oblomov" Bilotta +# Copyright:: (C) 2006-2007 Giuseppe Bilotta +# License:: GPL v2 +# + +class OxfordPlugin < Plugin + Config.register Config::IntegerValue.new('oxford.hits', + :default => 3, + :desc => "Number of hits to return from a dictionary lookup") + Config.register Config::IntegerValue.new('oxford.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 + @oxurl = "http://www.oxforddictionaries.com/definition/english/%s" + end + + def help(plugin, topic="") + 'oxford : check for on the oxford english dictionary.' + end + + def oxford(m, params) + justcheck = params[:justcheck] + + word = params[:word].join + [word, word + "_1"].each { |check| + url = @oxurl % CGI.escape(check) + if params[:british] + url << "?view=uk" + end + h = @bot.httputil.get(url, :max_redir => 5) + if h + defs = h.split("") + defs = defs[1..-1].map {|d| d.split("")[0]} + if defs.size == 0 + return false if justcheck + m.reply "#{word} not found" + return false + end + m.reply("#{word}: #{url}") unless justcheck + defn = defs[0] + m.reply("#{Bold}%s#{Bold}: %s" % [word, defn.ircify_html(:nbsp => :space)], :overlong => :truncate) + return true + end + } + end + + def is_british?(word) + return oxford(nil, :word => word, :justcheck => true, :british => true) + end +end + +plugin = OxfordPlugin.new +plugin.map 'oxford *word', :action => 'oxford', :threaded => true +