]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
dict: oxford fix from AndrewNTH
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 24 Oct 2011 08:49:22 +0000 (10:49 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 24 Oct 2011 08:49:22 +0000 (10:49 +0200)
See tracker issue #79

data/rbot/plugins/dict.rb

index c9bfabafadef5fb75491d6590f492d7ec8caa48a..13c15b71c1668ec6fd0fab511dd4d3067fe5523c 100644 (file)
@@ -141,15 +141,20 @@ class DictPlugin < Plugin
         url << "?view=uk"
       end
       h = @bot.httputil.get(url, :max_redir => 5)
-      if h and h.match(/<h2>#{word}<\/h2>(.*)Perform/m)
-        m.reply("#{word} : #{url}") unless justcheck
-        defn = $1
+      if h
+       defs = h.split("<span class=\"definition\">")
+       defs = defs[1..-1].map {|d| d.split("</span>")[0]}
+        if defs.size == 0
+         return false if justcheck
+         m.reply "#{word} not found"
+         return false
+       end
+       m.reply("#{word}: #{url}") unless justcheck
+       defn = defs[0]
         m.reply("#{Bold}%s#{Bold}: %s" % [word, defn.ircify_html(:nbsp => :space)], :overlong => :truncate)
         return true
       end
     }
-    return false if justcheck
-    m.reply "#{word} not found"
   end
 
   def is_british?(word)