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