require 'thread'
require 'etc'
+require 'date'
require 'fileutils'
require 'logger'
$daemonize = false unless $daemonize
$dateformat = "%Y/%m/%d %H:%M:%S"
-$logger = Logger.new($stderr)
+$logger = Logger.new(STDERR)
$logger.datetime_format = $dateformat
$logger.level = $cl_loglevel if defined? $cl_loglevel
$logger.level = 0 if $debug
+$logger_stderr = $logger
$log_queue = Queue.new
$log_thread = nil
# 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 rescue '?'
- end
+ message = message.kind_of?(String) ? message : (message.pretty_inspect rescue '?')
qmsg = Array.new
- str.each_line { |l|
+ message.each_line { |l|
qmsg.push [level, l.chomp, who]
who = ' ' * who.size
}
- if level == Logger::Severity::ERROR or level == Logger::Severity::FATAL and not $daemonize
- $stderr.puts str
+ if level >= Logger::Severity::WARN and not $daemonize
+ qmsg.each do |l|
+ $logger_stderr.add(*l)
+ end
end
$log_queue.push qmsg
end
rawlog(Logger::Severity::FATAL, message, who_pos)
end
-debug "debug test"
-log "log test"
-warning "warning test"
-error "error test"
-fatal "fatal test"
-
# The following global is used for the improved signal handling.
$interrupted = 0
# Main bot class, which manages the various components, receives messages,
# handles them or passes them to plugins, and contains core functionality.
class Bot
- COPYRIGHT_NOTICE = "(c) Tom Gilbert and the rbot development team"
- SOURCE_URL = "http://ruby-rbot.org"
+ COPYRIGHT_NOTICE = "(c) Giuseppe Bilotta and the rbot development team"
+ SOURCE_URL = "https://ruby-rbot.org"
# the bot's Auth data
attr_reader :auth
# loads and opens new registry databases, used by the plugins
attr_accessor :registry_factory
+ # web service
+ attr_accessor :webservice
+
# server we are connected to
# TODO multiserver
def server
# File.umask 0000 # Ensure sensible umask. Adjust as needed.
end
- logger = Logger.new(@logfile,
- @config['log.keep'],
- @config['log.max_size']*1024*1024)
- logger.datetime_format= $dateformat
- logger.level = @config['log.level']
- logger.level = $cl_loglevel if defined? $cl_loglevel
- logger.level = 0 if $debug
+ unless $debug
+ logger = Logger.new(@logfile,
+ @config['log.keep'],
+ @config['log.max_size']*1024*1024)
+ logger.datetime_format= $dateformat
+ logger.level = @config['log.level']
+ logger.level = $cl_loglevel if defined? $cl_loglevel
+ logger.level = 0 if $debug
- restart_logger(logger)
+ restart_logger(logger)
+ end
log_session_start
end
end
- # call the save method for all of the botmodules
- def save
+ # call the save method for all or the specified botmodule
+ #
+ # :botmodule ::
+ # optional botmodule to save
+ def save(botmodule=nil)
@save_mutex.synchronize do
- @plugins.save
+ @plugins.save(botmodule)
end
end
- # call the rescan method for all of the botmodules
- def rescan
+ # call the rescan method for all or just the specified botmodule
+ #
+ # :botmodule ::
+ # instance of the botmodule to rescan
+ def rescan(botmodule=nil)
debug "\tstopping timer..."
@timer.stop
@save_mutex.synchronize do
- @lang.rescan
- @plugins.rescan
+ # @lang.rescan
+ @plugins.rescan(botmodule)
end
@timer.start
end