diff options
author | Dmitry Kim <dmitry point kim at gmail point com> | 2007-03-30 23:44:02 +0000 |
---|---|---|
committer | Dmitry Kim <dmitry point kim at gmail point com> | 2007-03-30 23:44:02 +0000 |
commit | b11c3c4042b03e36639370002ecf86c44f7ddde4 (patch) | |
tree | 05a35024a2d56c7e3d313317376a17cb7c41a99f /data/rbot/plugins/fish.rb | |
parent | b73d6c7dc6554e1c6eb6abce68350ed2c13191b8 (diff) |
*** (httputil) major rework, new caching implementation, unified request
processing
+ (httputil) post support, partial request support, other features
- (httputil) removed partial_body() and get_cached() [merged into get()]
* (plugins/, utils) minimal changes to accomodate for the new http_utils
* (utils, ircbot) moved utils initialization into utils.rb
* (tube.rb) (partially) accomodate for upstream site layout changes
Diffstat (limited to 'data/rbot/plugins/fish.rb')
-rw-r--r-- | data/rbot/plugins/fish.rb | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/data/rbot/plugins/fish.rb b/data/rbot/plugins/fish.rb index 8c115f90..d7dda52b 100644 --- a/data/rbot/plugins/fish.rb +++ b/data/rbot/plugins/fish.rb @@ -30,39 +30,40 @@ class BabelPlugin < Plugin return end - http = @bot.httputil.get_proxy(URI.parse("http://babelfish.altavista.com")) - headers = { - "content-type" => "application/x-www-form-urlencoded; charset=utf-8", - 'accept-charset' => 'utf-8' + "content-type" => "application/x-www-form-urlencoded; charset=utf-8" } - http.start {|http| - resp = http.post(query, data, headers) - - if (resp.code == "200") - lines = Array.new - resp.body.each_line do |l| - lines.push l + begin + resp = @bot.httputil.get_response('http://babelfish.altavista.com'+query, + :method => :post, + :body => data, + :headers => headers) + rescue Exception => e + m.reply "http error: #{e.message}" + return end - l = lines.join(" ") - debug "babelfish response: #{l}" + if (resp.code == "200") + lines = Array.new + resp.body.each_line { |l| lines.push l } + + l = lines.join(" ") + debug "babelfish response: #{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 + 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 answer - return + m.reply "couldn't parse babelfish response html :(" + else + m.reply "couldn't talk to babelfish :(" end - m.reply "couldn't parse babelfish response html :(" - else - m.reply "couldn't talk to babelfish :(" - end - } end end plugin = BabelPlugin.new |