]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/urban.rb
dict.rb plugin: fixes the oxford parser so it doesn't spit out a bunch of extra crap
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / urban.rb
index 6cb166a80cbe436114d980cf5582d10d6cfa01f7..a24ac072091f7ed3d4d75031da89460060d94829 100644 (file)
@@ -13,7 +13,7 @@ class UrbanPlugin < Plugin
 
   def get_def(m, word, n = nil)
     n = n ? n.to_i : 1
-    u = URBAN + CGI.escape(word)
+    u = URBAN + URI.escape(word)
     u += '&skip=' + n.to_s if n
     s = @bot.httputil.get(u)
 
@@ -26,16 +26,16 @@ class UrbanPlugin < Plugin
 
     rv = Array.new
 
-    s.scan(%r{<td class="def_number"[^>]*>(\d+)\.</td>.*?<td class="def_word">(?:<a.*?>)?([^>]+)(?:</a>)?</td>.*?<div class="def_p">.*?<p>(.+?)</p>.*?<p style=".*?>(.+?)</p>}m) do |num, wrd, desc, ex|
-      rv << [num.to_i, wrd, desc, ex]
+    s.scan(%r{<td class='index'[^>]*>.*?(\d+)\..*?</td>.*?<td class='word'>(?:<a.*?>)?([^>]+)(?:</a>)?</td>.*?<div class='definition'>(.+?)</div>.*?<div class='example'>(.+?)</div>}m) do |num, wrd, desc, ex|
+      rv << [num.to_i, wrd.strip, desc.strip, ex.strip]
     end
 
     total ||= rv.size
 
-    return m.reply "#{Bold}#{word}#{Bold} not found" if rv.empty?
+    return m.reply("#{Bold}#{word}#{Bold} not found") if rv.empty?
 
     if notfound
-      suggestions = rv.map { |s| "#{Underline}#{s[1]}#{Underline}" }.join(', ')
+      suggestions = rv.map { |s| Underline + s[1] + Underline }.uniq.join ', '
       m.reply "#{Bold}#{word}#{Bold} not found. maybe you mean #{suggestions}?"
       return
     end