diff options
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/fish.rb | 25 |
1 files changed, 20 insertions, 5 deletions
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 <lang> <string> => translate from english to <lang>, translate from <lang> <string> => translate to english from <lang>, translate <fromlang> <tolang> <string> => translate from <fromlang> to <tolang>. If <string> 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 <lang> <string> => translate from #{from} to <lang>, translate from <lang> <string> => translate to #{to} from <lang>, translate <fromlang> <tolang> <string> => translate from <fromlang> to <tolang>. If <string> 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+<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div>/) + case l + when /^\s+<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div>/ answer = $1 # cache the answer if(answer.length > 0) @@ -68,8 +80,11 @@ class BabelPlugin < Plugin end m.reply answer return + when /^\s+<option value="#{trans_pair}"\s+SELECTED>/ + m.reply "couldn't parse babelfish response html :(" + else + m.reply "babelfish doesn't support translation from #{trans_from} to #{trans_to}" end - m.reply "couldn't parse babelfish response html :(" else m.reply "couldn't talk to babelfish :(" end |