]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
- (utils.rb) removed http_get, since it's obsoleted
authorDmitry Kim <dmitry point kim at gmail point com>
Fri, 30 Mar 2007 07:52:44 +0000 (07:52 +0000)
committerDmitry Kim <dmitry point kim at gmail point com>
Fri, 30 Mar 2007 07:52:44 +0000 (07:52 +0000)
+ (utils.rb) added @@bot class variable
* (utils.rb) get_first_pars should return a value
* (plugins) no need to pass http_util to the Utils.get_first_pars

data/rbot/plugins/dict.rb
data/rbot/plugins/search.rb
lib/rbot/core/utils/utils.rb
lib/rbot/ircbot.rb

index 149233d3b0871a0b39ea0ee00c1088e6859e1821..504a9d7beaadb8f0e5e09d53bff038c09de64a94 100644 (file)
@@ -92,7 +92,7 @@ class DictPlugin < Plugin
 \r
     return unless first_pars > 0\r
 \r
-    Utils.get_first_pars urls, first_pars, :http_util => @bot.httputil, :message => m,\r
+    Utils.get_first_pars urls, first_pars, :message => m,\r
       :strip => /^\S+\s+-\s+/\r
 \r
   end\r
index 3b7d682684f7a6f3be3dfcd9a3e6f55858c4ded0..221071cb57d36e3fdf8d851476390e31e22ad029 100644 (file)
@@ -87,7 +87,7 @@ class SearchPlugin < Plugin
 
     return unless first_pars > 0
 
-    Utils.get_first_pars urls, first_pars, :http_util => @bot.httputil, :message => m
+    Utils.get_first_pars urls, first_pars, :message => m
 
   end
 
index 5dd4bea10e6c7aa095acf3b59d230db3ecb4c9aa..8be0f170febd3776fc5cd5e94af16cc956cc370e 100644 (file)
@@ -316,6 +316,18 @@ module ::Irc
     SEC_PER_MNTH = SEC_PER_DAY * 30
     SEC_PER_YR = SEC_PER_MNTH * 12
 
+    @@bot = nil unless defined? @@bot
+    @@safe_save_dir = nil unless defined?(@@safe_save_dir)
+
+    def Utils.bot
+      @@bot
+    end
+
+    def Utils.bot=(b)
+      @@bot = b
+      @@safe_save_dir = "#{@@bot.botclass}/safe_save"
+    end
+
     def Utils.secs_to_string_case(array, var, string, plural)
       case var
       when 1
@@ -371,11 +383,6 @@ module ::Irc
     end
 
 
-    @@safe_save_dir = nil unless defined?(@@safe_save_dir)
-    def Utils.set_safe_save_dir(str)
-      @@safe_save_dir = str.dup
-    end
-
     def Utils.safe_save(file)
       raise 'No safe save directory defined!' if @@safe_save_dir.nil?
       basename = File.basename(file)
@@ -386,45 +393,6 @@ module ::Irc
       File.rename(temp.path, file)
     end
 
-
-    # returns a string containing the result of an HTTP GET on the uri
-    def Utils.http_get(uristr, readtimeout=8, opentimeout=4)
-
-      # ruby 1.7 or better needed for this (or 1.6 and debian unstable)
-      Net::HTTP.version_1_2
-      # (so we support the 1_1 api anyway, avoids problems)
-
-      uri = URI.parse uristr
-      query = uri.path
-      if uri.query
-        query += "?#{uri.query}"
-      end
-
-      proxy_host = nil
-      proxy_port = nil
-      if(ENV['http_proxy'] && proxy_uri = URI.parse(ENV['http_proxy']))
-        proxy_host = proxy_uri.host
-        proxy_port = proxy_uri.port
-      end
-
-      begin
-        http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port)
-        http.open_timeout = opentimeout
-        http.read_timeout = readtimeout
-
-        http.start {|http|
-          resp = http.get(query)
-          if resp.code == "200"
-            return resp.body
-          end
-        }
-      rescue => e
-        # cheesy for now
-        error "Utils.http_get exception: #{e.inspect}, while trying to get #{uristr}"
-        return nil
-      end
-    end
-
     def Utils.decode_html_entities(str)
       if $we_have_html_entities_decoder
         return HTMLEntities.decode_entities(str)
@@ -544,13 +512,14 @@ module ::Irc
     def Utils.get_first_pars(urls, count, opts={})
       idx = 0
       msg = opts[:message]
+      retval = Array.new
       while count > 0 and urls.length > 0
         url = urls.shift
         idx += 1
 
         # FIXME what happens if some big file is returned? We should share
         # code with the url plugin to only retrieve partial file content!
-        xml = opts[:http_util].get_cached(url)
+        xml = self.bot.httputil.get_cached(url)
         if xml.nil?
           debug "Unable to retrieve #{url}"
           next
@@ -565,7 +534,9 @@ module ::Irc
         end
         msg.reply "[#{idx}] #{par}", :overlong => :truncate if msg
         count -=1
+        retval.push(par)
       end
+      return retval
     end
 
 
index 58cbb46d688723293bf284ab0259a6687a08c2da..93d65200eb678a4e922283209723680c7661d1c6 100644 (file)
@@ -452,7 +452,7 @@ class Bot
 
     @plugins.scan
 
-    Utils.set_safe_save_dir("#{botclass}/safe_save")
+    Utils.bot = self
     @httputil = Utils::HttpUtil.new(self)
 
     # Channels where we are quiet