]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/ircbot.rb
debug logging: don't raise on SecurityError
[user/henk/code/ruby/rbot.git] / lib / rbot / ircbot.rb
index d95eb18dad94bb2edd8d3b678d2a04ed5b66d72b..cd073b327448f6a054889bea2869c051b8337f36 100644 (file)
@@ -39,26 +39,29 @@ class Exception
 end
 
 def rawlog(level, message=nil, who_pos=1)
-  call_stack = caller
-  if call_stack.length > who_pos
-    who = call_stack[who_pos].sub(%r{(?:.+)/([^/]+):(\d+)(:in .*)?}) { "#{$1}:#{$2}#{$3}" }
-  else
-    who = "(unknown)"
-  end
-  # Output each line. To distinguish between separate messages and multi-line
-  # messages originating at the same time, we blank #{who} after the first message
-  # is output.
-  # Also, we output strings as-is but for other objects we use pretty_inspect
-  case message
-  when String
-    str = message
-  else
-    str = message.pretty_inspect
+  begin
+    call_stack = caller
+    if call_stack.length > who_pos
+      who = call_stack[who_pos].sub(%r{(?:.+)/([^/]+):(\d+)(:in .*)?}) { "#{$1}:#{$2}#{$3}" }
+    else
+      who = "(unknown)"
+    end
+    # Output each line. To distinguish between separate messages and multi-line
+    # messages originating at the same time, we blank #{who} after the first message
+    # is output.
+    # Also, we output strings as-is but for other objects we use pretty_inspect
+    case message
+    when String
+      str = message
+    else
+      str = message.pretty_inspect
+    end
+    str.each_line { |l|
+      $logger.add(level, l.chomp, who)
+      who.gsub!(/./," ")
+    }
+  rescue SecurityError
   end
-  str.each_line { |l|
-    $logger.add(level, l.chomp, who)
-    who.gsub!(/./," ")
-  }
 end
 
 def log_session_start
@@ -575,8 +578,7 @@ class Bot
     @client[:notice] = proc { |data|
       message = NoticeMessage.new(self, server, data[:source], data[:target], data[:message])
       # pass it off to plugins that want to hear everything
-      @plugins.delegate "listen", message
-      @plugins.delegate "notice", message
+      @plugins.irc_delegate "notice", message
     }
     @client[:motd] = proc { |data|
       m = MotdMessage.new(self, server, data[:source], data[:target], data[:motd])
@@ -999,7 +1001,7 @@ class Bot
         debug "Sending quit message"
         @socket.emergency_puts "QUIT :#{message}"
         debug "Logging quits"
-        delegate_sent('QUIT', @bot.myself, message)
+        delegate_sent('QUIT', myself, message)
         debug "Flushing socket"
         @socket.flush
       rescue SocketError => e