X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fircbot.rb;h=f15cb351807aa18f06c993fb2da13d49e4f1a23e;hb=fdf1bc954352f19818f5f9f1c86643a2f8ef40c6;hp=e2f3f28e3c5c886bfadf9b63137fdc2eac868e61;hpb=6f5528a63b44e610a3d25d7fe583399163d7d2da;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index e2f3f28e..f15cb351 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -102,6 +102,7 @@ $interrupted = 0 require 'rbot/rbotconfig' require 'rbot/load-gettext' require 'rbot/config' +require 'rbot/config-compat' # require 'rbot/utils' require 'rbot/irc' @@ -123,7 +124,7 @@ module Irc # 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://linuxbrit.co.uk/rbot" + SOURCE_URL = "http://ruby-rbot.org" # the bot's Auth data attr_reader :auth @@ -177,6 +178,38 @@ class Bot myself.nick end + # bot inspection + # TODO multiserver + def inspect + ret = self.to_s[0..-2] + ret << ' version=' << $version.inspect + ret << ' botclass=' << botclass.inspect + ret << ' lang="' << lang.language + if defined?(GetText) + ret << '/' << locale + end + ret << '"' + ret << ' nick=' << nick.inspect + ret << ' server=' + if server + ret << (server.to_s + (socket ? + ' [' << socket.server_uri.to_s << ']' : '')).inspect + unless server.channels.empty? + ret << " channels=" + ret << server.channels.map { |c| + "%s%s" % [c.modes_of(nick).map { |m| + server.prefix_for_mode(m) + }, c.name] + }.inspect + end + else + ret << '(none)' + end + ret << ' plugins=' << plugins.inspect + ret << ">" + end + + # create a new Bot with botclass +botclass+ def initialize(botclass, params = {}) # Config for the core bot @@ -337,9 +370,9 @@ class Bot unless botclass and not botclass.empty? # We want to find a sensible default. - # * On POSIX systems we prefer ~/.rbot for the effective uid of the process - # * On Windows (at least the NT versions) we want to put our stuff in the - # Application Data folder. + # * On POSIX systems we prefer ~/.rbot for the effective uid of the process + # * On Windows (at least the NT versions) we want to put our stuff in the + # Application Data folder. # We don't use any particular O/S detection magic, exploiting the fact that # Etc.getpwuid is nil on Windows if Etc.getpwuid(Process::Sys.geteuid) @@ -460,7 +493,7 @@ class Bot @lang = Language.new(self, @config['core.language']) begin - @auth = Auth::authmanager + @auth = Auth::manager @auth.bot_associate(self) # @auth.load("#{botclass}/botusers.yaml") rescue Exception => e @@ -621,7 +654,7 @@ class Bot @plugins.delegate("listen", m) @plugins.delegate("join", m) - sendq "WHO #{data[:channel]}", data[:channel], 2 + sendq("WHO #{data[:channel]}", data[:channel], 2) if m.address? } @client[:part] = proc {|data| m = PartMessage.new(self, server, data[:source], data[:channel], data[:message]) @@ -1009,12 +1042,16 @@ class Bot def disconnect(message=nil) message = @lang.get("quit") if (!message || message.empty?) if @socket.connected? - debug "Clearing socket" - @socket.clearq - debug "Sending quit message" - @socket.emergency_puts "QUIT :#{message}" - debug "Flushing socket" - @socket.flush + begin + debug "Clearing socket" + @socket.clearq + debug "Sending quit message" + @socket.emergency_puts "QUIT :#{message}" + debug "Flushing socket" + @socket.flush + rescue SocketError => e + error "error while disconnecting socket: #{e.pretty_inspect}" + end debug "Shutting down socket" @socket.shutdown end @@ -1202,15 +1239,15 @@ class Bot def irclogprivmsg(m) if(m.action?) if(m.private?) - irclog "* [#{m.source}(#{m.sourceaddress})] #{m.message}", m.source + irclog "* [#{m.source}(#{m.sourceaddress})] #{m.logmessage}", m.source else - irclog "* #{m.source} #{m.message}", m.target + irclog "* #{m.source} #{m.logmessage}", m.target end else if(m.public?) - irclog "<#{m.source}> #{m.message}", m.target + irclog "<#{m.source}> #{m.logmessage}", m.target else - irclog "[#{m.source}(#{m.sourceaddress})] #{m.message}", m.source + irclog "[#{m.source}(#{m.sourceaddress})] #{m.logmessage}", m.source end end end @@ -1247,18 +1284,18 @@ class Bot def irclogpart(m) if(m.address?) debug "left channel #{m.channel}" - irclog "@ Left channel #{m.channel} (#{m.message})", m.channel + irclog "@ Left channel #{m.channel} (#{m.logmessage})", m.channel else - irclog "@ #{m.source} left channel #{m.channel} (#{m.message})", m.channel + irclog "@ #{m.source} left channel #{m.channel} (#{m.logmessage})", m.channel end end def irclogkick(m) if(m.address?) debug "kicked from channel #{m.channel}" - irclog "@ You have been kicked from #{m.channel} by #{m.source} (#{m.message})", m.channel + irclog "@ You have been kicked from #{m.channel} by #{m.source} (#{m.logmessage})", m.channel else - irclog "@ #{m.target} has been kicked from #{m.channel} by #{m.source} (#{m.message})", m.channel + irclog "@ #{m.target} has been kicked from #{m.channel} by #{m.source} (#{m.logmessage})", m.channel end end