summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-04-06 20:59:04 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-04-06 20:59:04 +0000
commit550754633ba85f5bd633dc81aeee686ead45774d (patch)
tree7ebb17a1aed04fcfb55a430d6cdaa088344d66ab /data/rbot
parent11cf84a26f2e3f1db3a59f24625c2e2f4a1d0259 (diff)
fish plugin: use get instead of get_response and resp.body.each_line
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/fish.rb43
1 files changed, 18 insertions, 25 deletions
diff --git a/data/rbot/plugins/fish.rb b/data/rbot/plugins/fish.rb
index 25816024..76555a34 100644
--- a/data/rbot/plugins/fish.rb
+++ b/data/rbot/plugins/fish.rb
@@ -55,41 +55,34 @@ class BabelPlugin < Plugin
query = "/babelfish/tr"
begin
- resp = @bot.httputil.get_response('http://babelfish.altavista.com'+query,
- :method => :post,
- :body => data,
- :headers => headers)
+ body = @bot.httputil.get('http://babelfish.altavista.com'+query,
+ :method => :post,
+ :body => data,
+ :headers => headers)
rescue Exception => e
m.reply "http error: #{e.message}"
return
end
- if (resp.code == "200")
- lines = Array.new
- resp.body.each_line { |l| lines.push l }
-
- l = lines.join(" ")
- debug "babelfish response: #{l}"
-
- case l
- when /^\s+<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div><\/td>\s*<\/tr>/m
- answer = $1.gsub(/\s*[\r\n]+\s*/,' ')
- # cache the answer
- if(answer.length > 0)
- @registry["#{trans_pair}/#{data_text}"] = answer
- 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}"
+ case body
+ when nil
+ m.reply "couldn't talk to babelfish :("
+ when /^\s+<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div><\/td>\s*<\/tr>/m
+ answer = $1.gsub(/\s*[\r\n]+\s*/,' ')
+ # cache the answer
+ if(answer.length > 0)
+ @registry["#{trans_pair}/#{data_text}"] = answer
end
+ m.reply answer
+ return
+ when /^\s+<option value="#{trans_pair}"\s+SELECTED>/
+ m.reply "couldn't parse babelfish response html :("
else
- m.reply "couldn't talk to babelfish :("
+ m.reply "babelfish doesn't support translation from #{trans_from} to #{trans_to}"
end
end
end
+
plugin = BabelPlugin.new
plugin.map 'translate to :tolang *phrase'
plugin.map 'translate from :fromlang *phrase'