diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | rbot/plugins/fish.rb | 12 | ||||
-rw-r--r-- | rbot/plugins/freshmeat.rb | 4 | ||||
-rw-r--r-- | rbot/plugins/google.rb | 2 | ||||
-rw-r--r-- | rbot/plugins/slashdot.rb | 4 | ||||
-rw-r--r-- | rbot/plugins/url.rb | 4 | ||||
-rw-r--r-- | rbot/plugins/wserver.rb | 51 | ||||
-rw-r--r-- | rbotconf/conf.rbot | 2 |
8 files changed, 31 insertions, 54 deletions
@@ -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 diff --git a/rbot/plugins/fish.rb b/rbot/plugins/fish.rb index ab84ff16..35b141ef 100644 --- a/rbot/plugins/fish.rb +++ b/rbot/plugins/fish.rb @@ -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", diff --git a/rbot/plugins/freshmeat.rb b/rbot/plugins/freshmeat.rb index 63eaf4c6..420c1bcb 100644 --- a/rbot/plugins/freshmeat.rb +++ b/rbot/plugins/freshmeat.rb @@ -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 diff --git a/rbot/plugins/google.rb b/rbot/plugins/google.rb index 2e9aacba..cd96f23c 100644 --- a/rbot/plugins/google.rb +++ b/rbot/plugins/google.rb @@ -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| diff --git a/rbot/plugins/slashdot.rb b/rbot/plugins/slashdot.rb index bc0a047e..38005bde 100644 --- a/rbot/plugins/slashdot.rb +++ b/rbot/plugins/slashdot.rb @@ -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 diff --git a/rbot/plugins/url.rb b/rbot/plugins/url.rb index 631c6e11..ed82d1c1 100644 --- a/rbot/plugins/url.rb +++ b/rbot/plugins/url.rb @@ -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" diff --git a/rbot/plugins/wserver.rb b/rbot/plugins/wserver.rb index eb4effaf..e1fe10bd 100644 --- a/rbot/plugins/wserver.rb +++ b/rbot/plugins/wserver.rb @@ -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 diff --git a/rbotconf/conf.rbot b/rbotconf/conf.rbot index d1a152fa..8c6020d0 100644 --- a/rbotconf/conf.rbot +++ b/rbotconf/conf.rbot @@ -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 |