diff --git a/commands/command.py b/commands/command.py index a9c9a62..a0ec2cc 100644 --- a/commands/command.py +++ b/commands/command.py @@ -9,6 +9,7 @@ Includes: - CmdAcademy: Show overview of all 4 wings - CmdSmell: Use atmosphere data for scents - CmdListen: Use atmosphere data for sounds + - CmdWho: Show who is currently online """ from evennia.commands.command import Command as BaseCommand @@ -365,3 +366,71 @@ class CmdListen(BaseCommand): self.caller.msg(f"\n The mood here is: {atmo['mood']}") else: self.caller.msg("You listen carefully but hear nothing unusual.") + + +class CmdWho(BaseCommand): + """ + Show who is currently online at the Academy. + + Usage: + @who + who + + Displays connected players, their locations, and session info. + """ + key = "@who" + aliases = ["who"] + locks = "cmd:all()" + help_category = "Academy" + + def func(self): + from evennia.accounts.models import AccountDB + import time + + online = AccountDB.objects.filter(db_is_connected=True).order_by('db_key') + count = online.count() + + msg = [] + msg.append("|c" + "=" * 44 + "|n") + msg.append(f"|c TIMMY ACADEMY - Who is Online ({count})|n") + msg.append("|c" + "=" * 44 + "|n") + + if count == 0: + msg.append("\n The Academy halls are empty.") + else: + for account in online: + # Get the character this account is puppeting + char = None + try: + sessions = account.sessions.all() + for sess in sessions: + puppet = sess.puppet + if puppet: + char = puppet + break + except Exception: + pass + + name = account.db_key + location = char.location.key if char and char.location else "(nowhere)" + idle = "" + try: + last_cmd = account.db_last_cmd_timestamp + if last_cmd: + idle_secs = time.time() - last_cmd + if idle_secs < 60: + idle = "active" + elif idle_secs < 300: + idle = f"{int(idle_secs // 60)}m idle" + else: + idle = f"{int(idle_secs // 60)}m idle" + except Exception: + idle = "?" + + msg.append(f"\n |w{name}|n") + msg.append(f" at |c{location}|n") + if idle: + msg.append(f" [{idle}]") + + msg.append("\n|c" + "=" * 44 + "|n") + self.caller.msg("\n".join(msg)) diff --git a/commands/default_cmdsets.py b/commands/default_cmdsets.py index f148e2c..75bccc2 100644 --- a/commands/default_cmdsets.py +++ b/commands/default_cmdsets.py @@ -18,7 +18,7 @@ from evennia import default_cmds from commands.command import ( CmdExamine, CmdRooms, CmdStatus, CmdMap, CmdAcademy, - CmdSmell, CmdListen, + CmdSmell, CmdListen, CmdWho, ) @@ -45,6 +45,7 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): self.add(CmdAcademy) self.add(CmdSmell) self.add(CmdListen) + self.add(CmdWho) class AccountCmdSet(default_cmds.AccountCmdSet):