]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/dict.rb
lastfm plugin: command to compactly display next events in a requested location
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / dict.rb
index 4e1bb7216dee29d0008032b7fcce23065893fbf5..d486e97b3c3c292b90530afbc785ce8907b238d7 100644 (file)
@@ -1,16 +1,21 @@
-# vim: set sw=2 et:\r
+#-- vim:sw=2:et\r
+#++\r
 #\r
-# dict plugin: provides a link to the definition of a word in one of the supported\r
+# :title: Dictionary lookup plugin for rbot\r
+#\r
+# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>\r
+# Copyright:: (C) 2006-2007 Giuseppe Bilotta\r
+# License:: GPL v2\r
+#\r
+# Provides a link to the definition of a word in one of the supported\r
 # dictionaries. Currently available are\r
 #   * the Oxford dictionary for (British) English\r
 #   * the De Mauro/Paravia dictionary for Italian\r
 #   * the Chambers dictionary for English (accepts both US and UK)\r
 #\r
-# other plugins can use this one to check if a given word is valid in italian\r
+# Other plugins can use this one to check if a given word is valid in italian\r
 # or english by using the is_italian?/is_british?/is_english? methods\r
 #\r
-# Author: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>\r
-#\r
 # TODO: cache results and reuse them if get_cached returns a cache copy\r
 \r
 require 'uri'\r
@@ -52,9 +57,10 @@ class DictPlugin < Plugin
 \r
     word = params[:word].downcase\r
     url = @dmwapurl % URI.escape(word)\r
-    xml = @bot.httputil.get_cached(url)\r
+    xml = nil\r
+    info = @bot.httputil.get_response(url) rescue nil\r
+    xml = info.body if info\r
     if xml.nil?\r
-      info = @bot.httputil.last_response\r
       info = info ? " (#{info.code} - #{info.message})" : ""\r
       return false if justcheck\r
       m.reply "An error occurred while looking for #{word}#{info}"\r
@@ -87,7 +93,7 @@ class DictPlugin < Plugin
 \r
     return unless first_pars > 0\r
 \r
-    Utils.get_first_pars urls, first_pars, :http_util => @bot.httputil, :message => m,\r
+    Utils.get_first_pars urls, first_pars, :message => m,\r
       :strip => /^\S+\s+-\s+/\r
 \r
   end\r
@@ -103,7 +109,7 @@ class DictPlugin < Plugin
     word = params[:word].join\r
     [word, word + "_1"].each { |check|\r
       url = @oxurl % URI.escape(check)\r
-      h = @bot.httputil.head(url)\r
+      h = @bot.httputil.head(url, :max_redir => 5)\r
       if h\r
         m.reply("#{word} found: #{url}") unless justcheck\r
         return true\r
@@ -123,10 +129,11 @@ class DictPlugin < Plugin
 \r
     word = params[:word].to_s.downcase\r
     url = @chambersurl % URI.escape(word)\r
-    xml = @bot.httputil.get_cached(url)\r
+    xml = nil\r
+    info = @bot.httputil.get_response(url) rescue nil\r
+    xml = info.body if info\r
     case xml\r
     when nil\r
-      info = @bot.httputil.last_response\r
       info = info ? " (#{info.code} - #{info.message})" : ""\r
       return false if justcheck\r
       m.reply "An error occurred while looking for #{word}#{info}"\r