]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/ircbot.rb
ircbot: clean up ping timings on connect
[user/henk/code/ruby/rbot.git] / lib / rbot / ircbot.rb
index abf64618a80107c8792c49f802cb70a03e607814..6c8d6332b38e16177709f0cd45655741909ee588 100644 (file)
@@ -135,6 +135,12 @@ $interrupted = 0
 
 # these first
 require 'rbot/rbotconfig'
+begin
+  require 'rubygems'
+rescue LoadError
+  log "rubygems unavailable"
+end
+
 require 'rbot/load-gettext'
 require 'rbot/config'
 require 'rbot/config-compat'
@@ -205,11 +211,16 @@ class Bot
     @client.user
   end
 
-  # bot User in the client/server connection
+  # bot nick in the client/server connection
   def nick
     myself.nick
   end
 
+  # bot channels in the client/server connection
+  def channels
+    myself.channels
+  end
+
   # nick wanted by the bot. This defaults to the irc.nick config value,
   # but may be overridden by a manual !nick command
   def wanted_nick
@@ -457,11 +468,6 @@ class Bot
       exit 2
     end
 
-    # Time at which the last PING was sent
-    @last_ping = nil
-    # Time at which the last line was RECV'd from the server
-    @last_rec = nil
-
     @startup_time = Time.new
 
     begin
@@ -778,7 +784,7 @@ class Bot
       missing = Dir.chdir(template_dir) { Dir.glob('*/**') } - Dir.chdir(@botclass) { Dir.glob('*/**') }
       missing.map do |f|
         dest = File.join(@botclass, f)
-        FileUtils.mkdir_p(File.dirname dest)
+        FileUtils.mkdir_p(File.dirname(dest))
         FileUtils.cp File.join(template_dir, f), dest
       end
     else
@@ -803,17 +809,17 @@ class Bot
     Dir.mkdir(plugdir_local) unless File.exist?(plugdir_local)
 
     @plugins.clear_botmodule_dirs
-    @plugins.add_botmodule_dir(File.join(Config::coredir, 'utils'))
-    @plugins.add_botmodule_dir(Config::coredir)
+    @plugins.add_core_module_dir(File.join(Config::coredir, 'utils'))
+    @plugins.add_core_module_dir(Config::coredir)
     if FileTest.directory? plugdir_local
-      @plugins.add_botmodule_dir(plugdir_local)
+      @plugins.add_plugin_dir(plugdir_local)
     else
       warning "local plugin location #{plugdir_local} is not a directory"
     end
 
     @config['plugins.path'].each do |_|
         path = _.sub(/^\(default\)/, plugdir_default)
-        @plugins.add_botmodule_dir(path)
+        @plugins.add_plugin_dir(path)
     end
   end
 
@@ -895,6 +901,9 @@ class Bot
 
   # connect the bot to IRC
   def connect
+    # make sure we don't have any spurious ping checks running
+    # (and initialize the vars if this is the first time we connect)
+    stop_server_pings
     begin
       quit if $interrupted > 0
       @socket.connect
@@ -972,7 +981,7 @@ class Bot
       rescue Errno::ETIMEDOUT, Errno::ECONNABORTED, TimeoutError, SocketError => e
         error "network exception: #{e.pretty_inspect}"
         quit_msg = e.to_s
-      rescue ServerError
+      rescue ServerError => e
         # received an ERROR from the server
         quit_msg = "server ERROR: " + e.message
         too_fast = e.message.index("reconnect too fast")
@@ -1241,7 +1250,9 @@ class Bot
 
   # totally shutdown and respawn the bot
   def restart(message=nil)
-    message = "restarting, back in #{@config['server.reconnect_wait']}..." if (!message || message.empty?)
+    message = _("restarting, back in %{wait}...") % {
+      :wait => @config['server.reconnect_wait']
+    } if (!message || message.empty?)
     shutdown(message)
     sleep @config['server.reconnect_wait']
     begin