]> 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 a710a86375d65395accbab83bb51baaa271cc721..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
@@ -267,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
@@ -318,7 +321,7 @@ class Bot
 \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
@@ -601,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
@@ -794,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
@@ -809,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