X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fircbot.rb;h=d07c4977aa9542cd94867446950a3e9b65257d95;hb=304cf05b0dd3834a675806b1c828824a473a5b42;hp=91afd94ea41be0e1360693c05bfe16ae67942ac1;hpb=42fd60e6a81e592553cdc6bb3b6011386692dde2;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 91afd94e..d07c4977 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -5,7 +5,8 @@ require 'fileutils' $debug = false unless $debug # print +message+ if debugging is enabled def debug(message=nil) - print "DEBUG: #{message}\n" if($debug && message) + stamp = Time.now.strftime("%Y/%m/%d %H:%M:%S") + print "D: [#{stamp}] #{message}\n" if($debug && message) #yield end @@ -301,16 +302,16 @@ class IrcBot } @client[:unknown] = proc {|data| #debug "UNKNOWN: #{data[:serverstring]}" - log data[:serverstring], ":unknown" + log data[:serverstring], ".unknown" } end # connect the bot to IRC def connect begin + trap("SIGINT") { quit } trap("SIGTERM") { quit } trap("SIGHUP") { quit } - trap("SIGINT") { quit } rescue debug "failed to trap signals, probably running on windows?" end @@ -454,9 +455,9 @@ class IrcBot # disconnect from the server and cleanup all plugins and modules def shutdown(message = nil) begin + trap("SIGINT", "DEFAULT") trap("SIGTERM", "DEFAULT") trap("SIGHUP", "DEFAULT") - trap("SIGINT", "DEFAULT") rescue debug "failed to trap signals, probably running on windows?" end @@ -598,6 +599,8 @@ class IrcBot debug "no PONG from server for #{diff} seconds, reconnecting" begin @socket.shutdown + # TODO + # raise an exception to get back to the mainloop rescue debug "couldn't shutdown connection (already shutdown?)" end