$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
}
@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
# 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
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