# The following global is used for the improved signal handling.
$interrupted = 0
-require 'rbot/load-gettext'
-
# these first
require 'rbot/rbotconfig'
+require 'rbot/load-gettext'
require 'rbot/config'
# require 'rbot/utils'
@registry = BotRegistry.new self
- @timer = Timer::Timer.new(1.0) # only need per-second granularity
+ @timer = Timer.new
@save_mutex = Mutex.new
if @config['core.save_every'] > 0
@save_timer = @timer.add(@config['core.save_every']) { save }
@logs = Hash.new
@plugins = nil
- @lang = Language::Language.new(self, @config['core.language'])
+ @lang = Language.new(self, @config['core.language'])
begin
@auth = Auth::authmanager
begin
quit if $interrupted > 0
connect
- @timer.start
quit_msg = nil
while @socket.connected?
sendq "TOPIC #{where} :#{topic}", where, 2
end
- def disconnect(message = nil)
- message = @lang.get("quit") if (message.nil? || message.empty?)
+ def disconnect(message=nil)
+ message = @lang.get("quit") if (!message || message.empty?)
if @socket.connected?
debug "Clearing socket"
@socket.clearq
end
# disconnect from the server and cleanup all plugins and modules
- def shutdown(message = nil)
+ def shutdown(message=nil)
@quit_mutex.synchronize do
- debug "Shutting down:"
+ debug "Shutting down: #{message}"
## No we don't restore them ... let everything run through
# begin
# trap("SIGINT", "DEFAULT")
# debug "failed to restore signals: #{e.inspect}\nProbably running on windows?"
# end
debug "\tdisconnecting..."
- disconnect
+ disconnect(message)
+ debug "\tstopping timer..."
+ @timer.stop
debug "\tsaving ..."
save
debug "\tcleaning up ..."
@save_mutex.synchronize do
@plugins.cleanup
end
- debug "\tstopping timers ..."
- @timer.stop
+ # debug "\tstopping timers ..."
+ # @timer.stop
# debug "Closing registries"
# @registry.close
debug "\t\tcleaning up the db environment ..."
end
# totally shutdown and respawn the bot
- def restart(message = false)
- msg = message ? message : "restarting, back in #{@config['server.reconnect_wait']}..."
- shutdown(msg)
+ def restart(message=nil)
+ message = "restarting, back in #{@config['server.reconnect_wait']}..." if (!message || message.empty?)
+ shutdown(message)
sleep @config['server.reconnect_wait']
begin
# now we re-exec
# call the rescan method for all of the botmodules
def rescan
+ debug "\tstopping timer..."
+ @timer.stop
@save_mutex.synchronize do
@lang.rescan
@plugins.rescan
end
+ @timer.start
end
# channel:: channel to join
topic = nil if topic == ""
case topic
when nil
- helpstr = "help topics: "
+ helpstr = _("help topics: ")
helpstr += @plugins.helptopics
- helpstr += " (help <topic> for more info)"
+ helpstr += _(" (help <topic> for more info)")
else
unless(helpstr = @plugins.help(topic))
- helpstr = "no help for topic #{topic}"
+ helpstr = _("no help for topic %{topic}") % { :topic => topic }
end
end
return helpstr
secs_up = Time.new - @startup_time
uptime = Utils.secs_to_string secs_up
# return "Uptime #{uptime}, #{@plugins.length} plugins active, #{@registry.length} items stored in registry, #{@socket.lines_sent} lines sent, #{@socket.lines_received} received."
- return "Uptime #{uptime}, #{@plugins.length} plugins active, #{@socket.lines_sent} lines sent, #{@socket.lines_received} received."
+ return (_("Uptime %{up}, %{plug} plugins active, %{sent} lines sent, %{recv} received.") %
+ {
+ :up => uptime, :plug => @plugins.length,
+ :sent => @socket.lines_sent, :recv => @socket.lines_received
+ })
end
# We want to respond to a hung server in a timely manner. If nothing was received