Add @who command - show connected players with location and idle time

This commit is contained in:
Alexander Whitestone
2026-04-13 04:13:03 -04:00
parent 67cc7240b7
commit d36660e9eb
2 changed files with 71 additions and 1 deletions

View File

@@ -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))