X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fircbot.rb;h=271d0d70ea358d9590872fed932c377bfa37b119;hb=dc37f783e46f0c75ba92e18463f7626fb3adfc20;hp=167cc0bcedcc1ab16575ee682dec5bea1729cc3a;hpb=8946b90f0efaee6f38a53c5e8db1cb29ba1b398c;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 167cc0bc..271d0d70 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 @@ -121,8 +122,8 @@ class IrcBot exit 2 end - #botclass = "#{Etc.getpwnam(Etc.getlogin).dir}/.rbot" unless botclass - botclass = "#{ENV['HOME']}/.rbot" unless botclass + botclass = "#{Etc.getpwuid(Process::Sys.geteuid)[:dir]}/.rbot" unless botclass + #botclass = "#{ENV['HOME']}/.rbot" unless botclass @botclass = botclass.gsub(/\/$/, "") unless FileTest.directory? botclass @@ -301,7 +302,7 @@ class IrcBot } @client[:unknown] = proc {|data| #debug "UNKNOWN: #{data[:serverstring]}" - log data[:serverstring], ":unknown" + log data[:serverstring], ".unknown" } end @@ -438,6 +439,7 @@ class IrcBot def log(message, where="server") message.chomp! stamp = Time.now.strftime("%Y/%m/%d %H:%M:%S") + where.gsub!(/[:!?$*()\/\\<>|"']/, "_") unless(@logs.has_key?(where)) @logs[where] = File.new("#{@botclass}/logs/#{where}", "a") @logs[where].sync = true @@ -598,6 +600,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