Add is_admin method to Element and User classes
[mudpy.git] / mudpy / misc.py
index fd4e0ac..e737a28 100644 (file)
@@ -184,6 +184,10 @@ class Element:
                 prepend_padding
             )
 
+    def is_admin(self):
+        """Boolean check whether an actor is controlled by an admin owner."""
+        return(self.owner and self.owner.is_admin())
+
     def can_run(self, command):
         """Check if the user can run this command object."""
 
@@ -192,7 +196,7 @@ class Element:
             return(False)
 
         # avatars of administrators can run any command
-        if self.owner and self.owner.account.get("administrator"):
+        if self.is_admin():
             return(True)
 
         # everyone can run non-administrative commands
@@ -995,6 +999,10 @@ class User:
                     avatar, 6)
         return avatars
 
+    def is_admin(self):
+        """Boolean check whether user's account is an admin."""
+        return(self.account.get("administrator", False))
+
 
 def broadcast(message, add_prompt=True):
     """Send a message to all connected users."""
@@ -1049,9 +1057,10 @@ def log(message, level=0):
 
     # display to connected administrators
     for user in universe.userlist:
-        if user.state == "active" and user.account.get(
-           "administrator"
-           ) and user.account.get("loglevel", 0) <= level:
+        if (
+                user.state == "active"
+                and user.is_admin()
+                and user.account.get("loglevel", 0) <= level):
             # iterate over every line in the message
             full_message = ""
             for line in lines: