]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/ircbot.rb
Utils.safe_save does a 'safe' saving (save to tempfile, move tempfile to new location)
[user/henk/code/ruby/rbot.git] / lib / rbot / ircbot.rb
index d83a5fe4152c780d1b9dadc8f1aef855c48a61a3..ac7aa8291ca372a9fe4b8db26f46312688134126 100644 (file)
@@ -346,7 +346,8 @@ class IrcBot
 
     @httputil = Utils::HttpUtil.new(self)
 
-    @lang = Language::Language.new(@config['core.language'])
+    @plugins = nil
+    @lang = Language::Language.new(self, @config['core.language'])
 
     begin
       @auth = Auth::authmanager
@@ -408,8 +409,9 @@ class IrcBot
     }
     @client[:privmsg] = proc { |data|
       m = PrivMessage.new(self, server, data[:source], data[:target], data[:message])
-      debug "Message target is #{data[:target].inspect}"
-      debug "Bot is #{myself.inspect}"
+      # debug "Message source is #{data[:source].inspect}"
+      # debug "Message target is #{data[:target].inspect}"
+      # debug "Bot is #{myself.inspect}"
 
       # TODO use the new Netmask class
       # @config['irc.ignore_users'].each { |mask| return if Irc.netmaskmatch(mask,m.source) }
@@ -605,7 +607,7 @@ class IrcBot
       rescue SystemExit
         log_session_end
         exit 0
-      rescue Errno::ETIMEDOUT, TimeoutError, SocketError => e
+      rescue Errno::ETIMEDOUT, Errno::ECONNABORTED, TimeoutError, SocketError => e
         error "network exception: #{e.class}: #{e}"
         debug e.backtrace.join("\n")
       rescue BDB::Fatal => e
@@ -809,7 +811,9 @@ class IrcBot
       debug "Saving"
       save
       debug "Cleaning up"
-      @plugins.cleanup
+      @save_mutex.synchronize do
+        @plugins.cleanup
+      end
       # debug "Closing registries"
       # @registry.close
       debug "Cleaning up the db environment"
@@ -848,8 +852,10 @@ class IrcBot
 
   # call the rescan method for all of the botmodules
   def rescan
-    @lang.rescan
-    @plugins.rescan
+    @save_mutex.synchronize do
+      @lang.rescan
+      @plugins.rescan
+    end
   end
 
   # channel:: channel to join
@@ -878,6 +884,11 @@ class IrcBot
       sendq "MODE #{channel} #{mode} #{target}", channel, 2
   end
 
+  # kicking a user
+  def kick(channel, user, msg)
+      sendq "KICK #{channel} #{user} :#{msg}", channel, 2
+  end
+
   # m::     message asking for help
   # topic:: optional topic help is requested for
   # respond to online help requests