X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ffish.rb;h=57bbefd06761b2717dd61446b5bd65fbbf4415c8;hb=a7bcb8ab77dd2f6e5f5297d33dcbca53b8f841b7;hp=76555a347b764075b61aa97c975fab92938e4a76;hpb=550754633ba85f5bd633dc81aeee686ead45774d;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/fish.rb b/data/rbot/plugins/fish.rb index 76555a34..57bbefd0 100644 --- a/data/rbot/plugins/fish.rb +++ b/data/rbot/plugins/fish.rb @@ -13,9 +13,14 @@ class BabelPlugin < Plugin :desc => "Default language to translate to") def help(plugin, topic="") - from = @bot.config['translate.default_from'] - to = @bot.config['translate.default_to'] - "translate to => translate from #{from} to , translate from => translate to #{to} from , translate => translate from to . If is an http url, translates the referenced webpage and returns the 1st content paragraph. Languages: #{LANGS.join(', ')}" + case topic + when 'cache' + "translate cache [view|clear] => view or clear the translate cache contents" + else + from = @bot.config['translate.default_from'] + to = @bot.config['translate.default_to'] + "translate to => translate from #{from} to , translate from => translate to #{to} from , translate => translate from to . If is an http url, translates the referenced webpage and returns the 1st content paragraph. Languages: #{LANGS.join(', ')}. Other topics: cache" + end end def translate(m, params) @@ -81,10 +86,36 @@ class BabelPlugin < Plugin m.reply "babelfish doesn't support translation from #{trans_from} to #{trans_to}" end end + + def cache_mgmt(m, params) + cmd = params[:cmd].intern + case cmd + when :view + cache = [] + @registry.each { |key, val| + cache << "%s => %s" % [key, val] + } + m.reply "translate cache: #{cache.inspect}" + when :clear + keys = [] + @registry.each { |key, val| + keys << key + } + keys.each { |key| + @registry.delete(key) + } + cache_mgmt(m, :cmd => 'view') + end + end + end plugin = BabelPlugin.new + +plugin.default_auth('cache', false) + plugin.map 'translate to :tolang *phrase' plugin.map 'translate from :fromlang *phrase' +plugin.map 'translate cache :cmd', :action => :cache_mgmt, :auth_path => 'cache!', :requirements => { :cmd => /view|clear/ } plugin.map 'translate :fromlang :tolang *phrase'