]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/urban.rb
plugins: remove excess requires and Net::HTTP.version setups
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / urban.rb
index c77a2e45601f40f5f2c3c226dc48c0b15c37ac24..1a4b9d74e34562d823a7e487cbc8238a2f600fd1 100644 (file)
@@ -1,5 +1,3 @@
-require 'uri'
-
 class UrbanPlugin < Plugin
 
   def help( plugin, topic="")
@@ -11,14 +9,15 @@ class UrbanPlugin < Plugin
     n = params[:n].nil? ? 1 : params[:n].to_i rescue 1
 
     if words.empty?
-      uri = URI.parse( "http://www.urbandictionary.com/random.php" )
-      @bot.httputil.head(uri) { |redir|
-        words = URI.unescape(redir.match(/define.php\?term=(.*)$/)[1]) rescue nil
-      }
+      resp = @bot.httputil.head('http://www.urbandictionary.com/random.php',
+                               :max_redir => -1)
+      if resp.code == "302" && (loc = resp['location'])
+        words = URI.unescape(loc.match(/define.php\?term=(.*)$/)[1]) rescue nil
+      end
     end
     # we give a very high 'skip' because this will allow us to get the number of definitions by retrieving the previous definition
-    uri = URI.parse("http://www.urbanwap.com/search.php?term=#{URI.escape words}&skip=65536")
-    page = @bot.httputil.get_cached(uri)
+    uri = "http://www.urbanwap.com/search.php?term=#{URI.escape words}&skip=65536"
+    page = @bot.httputil.get(uri)
     if page.nil?
       m.reply "Couldn't retrieve an urban dictionary definition of #{words}"
       return
@@ -38,8 +37,8 @@ class UrbanPlugin < Plugin
       n = numdefs
     end
     if n < numdefs
-      uri = URI.parse("http://www.urbanwap.com/search.php?term=#{URI.escape words}&skip=#{n-1}")
-      page = @bot.httputil.get_cached(uri)
+      uri = "http://www.urbanwap.com/search.php?term=#{URI.escape words}&skip=#{n-1}"
+      page = @bot.httputil.get(uri)
       if page.nil?
         case n % 10
         when 1
@@ -77,7 +76,7 @@ class UrbanPlugin < Plugin
   end
 
   def uotd(m, params)
-    home = @bot.httputil.get_cached("http://www.urbanwap.com/")
+    home = @bot.httputil.get("http://www.urbanwap.com/")
     if home.nil?
       m.reply "Couldn't get the urban dictionary word of the day"
       return
@@ -85,7 +84,7 @@ class UrbanPlugin < Plugin
     home.match(/Word of the Day: <a href="(.*?)">.*?<\/a>/)
     wotd = $1
     debug "Urban word of the day: #{wotd}"
-    page = @bot.httputil.get_cached(wotd)
+    page = @bot.httputil.get(wotd)
     if page.nil?
       m.reply "Couldn't get the urban dictionary word of the day"
     else