From fdb2d8d9f1fb0262324f10985aabc99d911797c2 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 6 Apr 2007 20:10:37 +0000 Subject: fish plugin: default from/to translation languages can now be configured. The plugin also tries to detect if a failure to translate was because the from/to pair is not supported by the site --- data/rbot/plugins/fish.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'data/rbot/plugins') diff --git a/data/rbot/plugins/fish.rb b/data/rbot/plugins/fish.rb index 68e6d29c..52f30d69 100644 --- a/data/rbot/plugins/fish.rb +++ b/data/rbot/plugins/fish.rb @@ -4,13 +4,24 @@ Net::HTTP.version_1_2 class BabelPlugin < Plugin LANGS = %w{en fr de it pt es nl ru zh zt el ja ko} + + BotConfig.register BotConfigEnumValue.new('translate.default_from', + :values => LANGS, :default => 'en', + :desc => "Default language to translate from") + BotConfig.register BotConfigEnumValue.new('translate.default_to', + :values => LANGS, :default => 'en', + :desc => "Default language to translate to") + def help(plugin, topic="") - "translate to => translate from english to , translate from => translate to english from , translate => translate from to . If is an http url, translates the referenced webpage and returns the 1st content paragraph. Languages: #{LANGS.join(', ')}" + 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(', ')}" end + def translate(m, params) langs = LANGS - trans_from = params[:fromlang] ? params[:fromlang] : 'en' - trans_to = params[:tolang] ? params[:tolang] : 'en' + trans_from = params[:fromlang] ? params[:fromlang] : @bot.config['translate.default_from'] + trans_to = params[:tolang] ? params[:tolang] : @bot.config['translate.default_to'] trans_text = params[:phrase].to_s lang_match = langs.join("|") @@ -60,7 +71,8 @@ class BabelPlugin < Plugin l = lines.join(" ") debug "babelfish response: #{l}" - if(l =~ /^\s+
(.*)<\/div>/) + case l + when /^\s+
(.*)<\/div>/ answer = $1 # cache the answer if(answer.length > 0) @@ -68,8 +80,11 @@ class BabelPlugin < Plugin end m.reply answer return + when /^\s+