diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-26 22:13:46 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-26 22:13:46 +0000 |
commit | b8373f3006a02084e58979bd021e8a76b5662ff6 (patch) | |
tree | 360ee8f99b0a2d22df073ca0cbdd97f503dfa7bd /rbot/plugins | |
parent | 5d5d9df1a4825fad5ef045cfc0b21b16e5e2bcc7 (diff) |
switch the fish plugin to use the new map mechanism
Diffstat (limited to 'rbot/plugins')
-rw-r--r-- | rbot/plugins/fish.rb | 65 |
1 files changed, 26 insertions, 39 deletions
diff --git a/rbot/plugins/fish.rb b/rbot/plugins/fish.rb index 35b141ef..57aaafc2 100644 --- a/rbot/plugins/fish.rb +++ b/rbot/plugins/fish.rb @@ -6,27 +6,13 @@ class BabelPlugin < Plugin 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>. Languages: en, fr, de, it, pt, es, nl" end - def privmsg(m) - + def translate(m, params) langs = ["en", "fr", "de", "it", "pt", "es", "nl"] - + trans_from = params[:fromlang] ? params[:fromlang] : 'en' + trans_to = params[:tolang] ? params[:tolang] : 'en' + trans_text = params[:phrase].to_s + query = "/babelfish/tr" - if(m.params =~ /^to\s+(\S+)\s+(.*)/) - trans_from = "en" - trans_to = $1 - trans_text = $2 - elsif(m.params =~ /^from\s+(\S+)\s+(.*)/) - trans_from = $1 - trans_to = "en" - trans_text = $2 - elsif(m.params =~ /^(\S+)\s+(\S+)\s+(.*)/) - trans_from = $1 - trans_to = $2 - trans_text = $3 - else - m.reply "incorrect usage: " + help(m.plugin) - return - end lang_match = langs.join("|") unless(trans_from =~ /^(#{lang_match})$/ && trans_to =~ /^(#{lang_match})$/) m.reply "invalid language: valid languagess are: #{langs.join(' ')}" @@ -48,27 +34,28 @@ class BabelPlugin < Plugin http.start {|http| resp = http.post(query, data, {"content-type", "application/x-www-form-urlencoded"}) - - if (resp.code == "200") - #puts resp.body - resp.body.each_line {|l| - if(l =~ /^\s+<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div>/) - answer = $1 - # cache the answer - if(answer.length > 0) - @registry["#{trans_pair}/#{data_text}"] = answer - end - m.reply answer - return - end - } - m.reply "couldn't parse babelfish response html :(" - else - m.reply "couldn't talk to babelfish :(" - end - } + + if (resp.code == "200") + resp.body.each_line do |l| + if(l =~ /^\s+<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div>/) + answer = $1 + # cache the answer + if(answer.length > 0) + @registry["#{trans_pair}/#{data_text}"] = answer + end + m.reply answer + return + end + end + m.reply "couldn't parse babelfish response html :(" + else + m.reply "couldn't talk to babelfish :(" + end + } end end plugin = BabelPlugin.new -plugin.register("translate") +plugin.map 'translate to :tolang *phrase' +plugin.map 'translate from :fromlang *phrase' +plugin.map 'translate :fromlang :tolang *phrase' |