diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 15:59:13 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 15:59:13 +0000 |
commit | 21949774b91eaec6ecde4eaa8ad121e2c0a36b87 (patch) | |
tree | 41a7601e168018ac203bad7ca8d7f9f82515bc28 /rbot/plugins/fish.rb | |
parent | 51cf09ec02d089bfdd80e5f728cfc92a234dc437 (diff) |
rearrange repo for packaging
Diffstat (limited to 'rbot/plugins/fish.rb')
-rw-r--r-- | rbot/plugins/fish.rb | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/rbot/plugins/fish.rb b/rbot/plugins/fish.rb deleted file mode 100644 index 57aaafc2..00000000 --- a/rbot/plugins/fish.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'net/http' -require 'uri/common' -Net::HTTP.version_1_2 - -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 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" - lang_match = langs.join("|") - unless(trans_from =~ /^(#{lang_match})$/ && trans_to =~ /^(#{lang_match})$/) - m.reply "invalid language: valid languagess are: #{langs.join(' ')}" - return - end - - data_text = URI.escape trans_text - trans_pair = "#{trans_from}_#{trans_to}" - data = "lp=#{trans_pair}&doit=done&intl=1&tt=urltext&urltext=#{data_text}" - - # check cache for previous lookups - if @registry.has_key?("#{trans_pair}/#{data_text}") - m.reply @registry["#{trans_pair}/#{data_text}"] - return - end - - http = @bot.httputil.get_proxy(URI.parse("http://babelfish.altavista.com")) - - http.start {|http| - resp = http.post(query, data, {"content-type", - "application/x-www-form-urlencoded"}) - - 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.map 'translate to :tolang *phrase' -plugin.map 'translate from :fromlang *phrase' -plugin.map 'translate :fromlang :tolang *phrase' - |