X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fbotuser.rb;h=defb3a47afa9b119f7cbaeb626d41dce29d2cbc2;hb=43864ec494a9c2538934690f32eacb8bfb5cc921;hp=d61926b81906607e3b0b2fb5f607568f1fa9366a;hpb=a5dcd5aee95ea6190107d4466c84af9e5cf22e1b;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb index d61926b8..defb3a47 100644 --- a/lib/rbot/botuser.rb +++ b/lib/rbot/botuser.rb @@ -182,6 +182,9 @@ class Bot # def permit?(str) cmd = str.to_irc_auth_command + # TODO user-configurable list of always-allowed commands, + # for admins that want to set permissions -* for everybody + return true if cmd.command == :login allow = nil cmd.path.reverse.each { |k| if @perm.has_key?(k) @@ -237,9 +240,6 @@ class Bot attr_reader :password attr_reader :netmasks attr_reader :perm - # Please remember to #set_changed() the Auth.manager - # when modifying data - attr_reader :data attr_writer :login_by_mask attr_writer :transient @@ -270,7 +270,7 @@ class Bot # Make the BotUser permanent def make_permanent(name) - raise TypError, "permanent already" if permanent? + raise TypeError, "permanent already" if permanent? @username = BotUser.sanitize_username(name) @transient = false reset_autologin @@ -317,14 +317,11 @@ class Bot raise "must provide a usable mask for transient BotUser #{@username}" if @transient and @netmasks.empty? @perm = {} - - # @data = AuthNotifyingHash.new - @data = {} end # Inspection def inspect - str = "<#{self.class}:#{'0x%08x' % self.object_id}" + str = self.__to_s__[0..-2] str << " (transient)" if @transient str << ":" str << " @username=#{@username.inspect}" @@ -332,11 +329,6 @@ class Bot str << " @perm=#{@perm.inspect}" str << " @login_by_mask=#{@login_by_mask}" str << " @autologin=#{@autologin}" - if @data.empty? - str << " no data" - else - str << " data for #{@data.keys.join(', ')}" - end str << ">" end @@ -354,7 +346,6 @@ class Bot :perm => @perm, :login_by_mask => @login_by_mask, :autologin => @autologin, - :data => @data } end @@ -393,7 +384,6 @@ class Bot @netmasks.each { |n| Auth.manager.maskdb.add(self, n) } if @autologin end @perm = h[:perm] if h.has_key?(:perm) - @data.replace(h[:data]) if h.has_key?(:data) end # This method sets the password if the proposed new password @@ -614,6 +604,19 @@ class Bot end + class BotUser + # Check if the current BotUser is the default one + def default? + return DefaultBotUserClass === self + end + + # Check if the current BotUser is the owner + def owner? + return BotOwnerClass === self + end + end + + # This is the ManagerClass singleton, used to manage # Irc::User/Irc::Bot::Auth::BotUser connections and everything # @@ -807,8 +810,9 @@ class Bot # BotUser (if any) it's logged in as # def make_permanent(user, name) + buname = BotUser.sanitize_username(name) # TODO merge BotUser instead? - raise "there's already a BotUser called #{name}" if include?(name) + raise "there's already a BotUser called #{name}" if include?(buname) tuser = nil case user @@ -822,7 +826,7 @@ class Bot return nil unless tuser raise TypeError, "#{tuser} is not transient" unless tuser.transient? - tuser.make_permanent(name) + tuser.make_permanent(buname) @allbotusers[tuser.username.to_sym] = tuser return tuser @@ -904,44 +908,6 @@ end def botuser Irc::Bot::Auth.manager.irc_to_botuser(self) end - - # Bot-specific data can be stored with Irc::Users. This is - # internally obtained by storing data to the associated BotUser, - # but this is a detail plugin writers shouldn't care about. - # bot_data(:key) can be used to retrieve a particular data set. - # This method is intended for data retrieval, and if the retrieved - # data is modified directly there is no guarantee the changes will - # be saved back. Use #set_bot_data() for that. - # - def bot_data(key=nil) - return self.botuser.data if key.nil? - return self.botuser.data[key] - end - - # This method is used to store bot-specific data for the receiver. - # If no block is passed, _value_ is stored for the key _key_; - # if a block is passed, it will be called with the previous - # _key_ value as parameter, and its return value will be stored - # as the new value. If _value_ is present in the block form, it - # will be used to initialize _key_ if it's missing - # - def set_bot_data(key,value=nil,&block) - if not block_given? - self.botuser.data[key]=value - Irc::Bot::Auth.manager.set_changed - return value - end - if value and not bot_data.has_key?(key) - set_bot_data(key, value) - end - r = value - begin - r = yield bot_data(key) - ensure - Irc::Bot::Auth.manager.set_changed - end - return r - end end end