]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Wed Jul 20 23:30:01 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
authorTom Gilbert <tom@linuxbrit.co.uk>
Thu, 21 Jul 2005 11:03:46 +0000 (11:03 +0000)
committerTom Gilbert <tom@linuxbrit.co.uk>
Thu, 21 Jul 2005 11:03:46 +0000 (11:03 +0000)
  * Move some core plugins to use the new httputil
* fix wserver's redirection handling for relative (i.e. broken) redirects
* fix tube plugin's html parsing

ChangeLog
rbot/plugins/fish.rb
rbot/plugins/freshmeat.rb
rbot/plugins/google.rb
rbot/plugins/slashdot.rb
rbot/plugins/url.rb
rbot/plugins/wserver.rb
rbotconf/conf.rbot

index e53f1f64ad9423f9e52700339a1810c58c4fe995..1c4dcd581da211a0fc987b6dfdd9430a3386da60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jul 20 23:30:01 BST 2005  Tom Gilbert <tom@linuxbrit.co.uk>
+
+  * Move some core plugins to use the new httputil
+       * fix wserver's redirection handling for relative (i.e. broken) redirects
+       * fix tube plugin's html parsing
+
 Wed Jul 20 01:18:06 BST 2005  Tom Gilbert <tom@linuxbrit.co.uk>
 
        * Add new httputil object to the bot object, to be used by plugins etc
index ab84ff16fbc45e93518539f6539d960a36d29e88..35b141ef4fe7fa6267408f31f943034d82375d02 100644 (file)
@@ -8,16 +8,6 @@ class BabelPlugin < Plugin
   end
   def privmsg(m)
 
-    proxy_host = nil
-    proxy_port = nil
-
-    if(ENV['http_proxy'])
-      if(ENV['http_proxy'] =~ /^http:\/\/(.+):(\d+)$/)
-        proxy_host = $1
-        proxy_port = $2
-      end
-    end
-    
     langs = ["en", "fr", "de", "it", "pt", "es", "nl"]
 
     query = "/babelfish/tr"
@@ -53,7 +43,7 @@ class BabelPlugin < Plugin
       return
     end
 
-    http = Net::HTTP.new("babelfish.altavista.com", 80, proxy_host, proxy_port)
+    http = @bot.httputil.get_proxy(URI.parse("http://babelfish.altavista.com"))
 
     http.start {|http|
       resp = http.post(query, data, {"content-type",
index 63eaf4c6323607f2860eb1d17369cbe8c161dfd7..420c1bcba0dae5e3c31f0d07f775b4835df69dae 100644 (file)
@@ -25,7 +25,7 @@ class FreshmeatPlugin < Plugin
   def search_freshmeat(m, search, max=4)
     max = 8 if max > 8
     begin
-      xml = Utils.http_get("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{URI.escape(search)}")
+      xml = @bot.httputil.get(URI.parse("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{URI.escape(search)}"))
     rescue URI::InvalidURIError, URI::BadURIError => e
       m.reply "illegal search string #{search}"
       return
@@ -70,7 +70,7 @@ class FreshmeatPlugin < Plugin
   
   def freshmeat(m, max=4)
     max = 8 if max > 8
-    xml = Utils.http_get("http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml")
+    xml = @bot.httputil.get(URI.parse("http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml"))
     unless xml
       m.reply "freshmeat news parse failed"
       return
index 2e9aacba683c7f87a324be6e5c4fb33c1eb67f42..cd96f23c73d3c63ab46a166361ce725a14ca9991 100644 (file)
@@ -27,7 +27,7 @@ class GooglePlugin < Plugin
       end
     end
 
-    http = Net::HTTP.new("www.google.com", 80, proxy_host, proxy_port)
+    http = @bot.httputil.get_proxy(URI.parse("http://www.google.com"))
 
     begin
       http.start {|http|
index bc0a047edcfbdc3e7f855b32039b48db7a11ecc9..38005bde436a5c400baac36d43d5a1970d17f394 100644 (file)
@@ -24,7 +24,7 @@ class SlashdotPlugin < Plugin
   
   def search_slashdot(m, search, max=4)
     begin
-      xml = Utils.http_get("http://slashdot.org/search.pl?content_type=rss&query=#{URI.escape(search)}")
+      xml = @bot.httputil.get(URI.parse("http://slashdot.org/search.pl?content_type=rss&query=#{URI.escape(search)}"))
     rescue URI::InvalidURIError, URI::BadURIError => e
       m.reply "illegal search string #{search}"
       return
@@ -51,7 +51,7 @@ class SlashdotPlugin < Plugin
   end
   
   def slashdot(m, max=4)
-    xml = Utils.http_get("http://slashdot.org/slashdot.xml")
+    xml = @bot.httputil.get(URI.parse("http://slashdot.org/slashdot.xml"))
     unless xml
       m.reply "slashdot news parse failed"
       return
index 631c6e1190d7c1f0635c01c677998e7ab8b38cd9..ed82d1c19b745461a7792a3d04521425810f8d69 100644 (file)
@@ -12,8 +12,8 @@ class UrlPlugin < Plugin
     return unless m.kind_of?(PrivMessage)
     return if m.address?
     # TODO support multiple urls in one line
-    if m.message =~ /(f|ht)tp:\/\//
-      if m.message =~ /((f|ht)tp:\/\/.*?)(?:\s+|$)/
+    if m.message =~ /(f|ht)tps?:\/\//
+      if m.message =~ /((f|ht)tps?:\/\/.*?)(?:\s+|$)/
         url = Url.new(m.target, m.sourcenick, Time.new, $1)
         list = @registry[m.target]
         debug "#{list.length} urls so far"
index eb4effaffc6f0a7940372f332e74f61644614929..e1fe10bd341f1eafc675659c566612c3d4db8793 100644 (file)
@@ -12,22 +12,9 @@ class WserverPlugin < Plugin
       return
     end
 
-    proxy_host = nil
-    proxy_port = nil
-
-    if(ENV['http_proxy'])
-      if(ENV['http_proxy'] =~ /^http:\/\/(.+):(\d+)$/)
-        hh = $1
-        pp = $2
-        unless(m.params =~ /\.db\.com/ || m.params =~ /\.deuba\.com/)
-          proxy_host = hh
-          proxy_port = pp
-        end
-      end
-    end
-
     redirect_count = 0
     hostname = m.params.dup
+    hostname = "http://#{hostname}" unless hostname =~ /:\/\//
     begin
       if(redirect_count > 3)
         m.reply "cowardly refusing to follow more than 3 redirects"
@@ -45,47 +32,41 @@ class WserverPlugin < Plugin
         m.reply "incorrect usage: " + help(m.plugin)
         return
       end
-      if(uri.scheme == "https")
-        m.reply "#{uri.scheme} not supported"
-        return
-      end
         
-      host = uri.host ? uri.host : hostname
-      port = uri.port ? uri.port : 80
-      path = '/'
-      if(uri.scheme == "http")
-        path = uri.path if uri.path
-      end
-    
-      http = Net::HTTP.new(host, port, proxy_host, proxy_port)
+      http = @bot.httputil.get_proxy(uri)
       http.open_timeout = 5
       
       http.start {|http|
-        resp = http.head(path)
-        result = host
+        resp = http.head('/')
         server = resp['Server']
         if(server && server.length > 0)
-          m.reply "#{host} is running #{server}"
+          m.reply "#{uri.host} is running #{server}"
         else
-          m.reply "couldn't tell what #{host} is running"
+          m.reply "couldn't tell what #{uri.host} is running"
         end
         
         if(resp.code == "302" || resp.code == "301") 
-          if(host != URI.parse(resp['location']).host)
-            m.reply "#{host} redirects to #{resp['location']}"
-            raise resp['location']
+          newloc = resp['location']
+          newuri = URI.parse(newloc)
+          # detect and ignore incorrect redirects (to relative paths etc)
+          if (newuri.host != nil)
+            if(uri.host != newuri.host)
+              m.reply "#{uri.host} redirects to #{newuri.scheme}://#{newuri.host}"
+              raise resp['location']
+            end
           end
         end
       }
     rescue TimeoutError => err
-      m.reply "timed out connecting to #{host}:#{port} :("
+      m.reply "timed out connecting to #{uri.host}:#{uri.port} :("
       return
     rescue RuntimeError => err
       redirect_count += 1
       hostname = err.message
       retry
     rescue StandardError => err
-      m.reply "couldn't connect to #{host}:#{port} :("
+      puts err
+      m.reply "couldn't connect to #{uri.host}:#{uri.port} :("
       return
     end
   end
index d1a152fa8e14d2838438f7adb5a6c13e9450a8c4..8c6020d094c1b1d69309dff83c3ba42b2a46778f 100644 (file)
@@ -3,7 +3,7 @@ SENDQ_DELAY = 2.0
 SENDQ_BURST = 4
 NICK = rbot
 USER = rbot
-JOIN_CHANNELS = #giblet
+JOIN_CHANNELS = #rbot
 PORT = 6667
 LANGUAGE = english
 KEYWORD_LISTEN = false