X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fircbot.rb;h=739aaadee49c7075f45180bf2cde707b7244d328;hb=c7c670947b9ec9129412e05fc7934531c9d132ba;hp=b954e3b5c63c2306b0668f03a3a947c3fef0321b;hpb=c10364437a7182bbb731627169dafce67b01a912;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index b954e3b5..739aaade 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -7,6 +7,7 @@ require 'thread' require 'etc' +require 'date' require 'fileutils' require 'logger' @@ -18,6 +19,7 @@ $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 @@ -56,19 +58,16 @@ def rawlog(level, message=nil, who_pos=1) # 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 @@ -163,7 +162,7 @@ module Irc # 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" + COPYRIGHT_NOTICE = "(c) Giuseppe Bilotta and the rbot development team" SOURCE_URL = "http://ruby-rbot.org" # the bot's Auth data attr_reader :auth @@ -202,6 +201,9 @@ class Bot # 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 @@ -435,7 +437,7 @@ class Bot }, :desc => "Percentage of IRC penalty to consider when sending messages to prevent being disconnected for excess flood. Set to 0 to disable penalty control.") Config.register Config::StringValue.new('core.db', - :default => default_db, + :default => default_db, :store_default => true, :wizard => true, :validate => Proc.new { |v| Registry::formats.include? v }, :requires_restart => true, @@ -504,6 +506,7 @@ class Bot end @registry_factory = Registry.new @config['core.db'] + @registry_factory.migrate_registry_folder(path) @logfile = @config['log.file'] if @logfile.class!=String || @logfile.empty? @@ -1394,20 +1397,26 @@ class Bot 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