From a7bcb8ab77dd2f6e5f5297d33dcbca53b8f841b7 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 6 Apr 2007 21:22:27 +0000 Subject: [PATCH] fish plugin: minimal cache management --- data/rbot/plugins/fish.rb | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) 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' -- 2.32.0.93.g670b81a890