Admin /help Command — Design
Goal
Add an admin-only /help slash command to the chat that shows available commands as a system notice. Build a command registry so /help auto-generates from registered commands.
Key Decisions
- Admin-only dispatch: Only
isOwnerconnections trigger command handling. Non-admin users typing/helpor any/commandhave their message sent as regular chat text — no error, no hint that commands exist. - Server-side registry: Commands are registered in a central registry.
/helpiterates the registry to build its output. - System notice display: The help output renders as a styled system notice in the chat, visible only to the admin (not broadcast).
- New
HELPserver message type: Carries an array of{ name, description }so the client can render it cleanly.
Architecture
Command Registry (api/src/commands.ts)
interface Command { name: string; description: string; handler: (ws: WebSocket, args: string, chatRoom: ChatRoom) => void;}- Exports a
commandsarray and adispatch(text, ws, chatRoom)function. dispatchis only called whenisOwneris true.- Built-in commands:
/help,/unblock <ip>.
Dispatch Flow
In handleChatMessage:
- If
info.isOwnerand text starts with/→ calldispatch(text, ws, chatRoom) - If dispatch returns
true(command matched) → return early - Otherwise → treat as normal message
Server Message Type
New HELP type added to SERVER_MESSAGE_TYPE and ServerMessage union:
interface ServerHelpMessage { type: "help"; commands: Array<{ name: string; description: string }>;}Client Handling
In chat-client.ts, handle help message type by calling appendNotice() with formatted command list.
Files Changed
| File | Change |
|---|---|
api/src/commands.ts | New — command registry with /help and /unblock |
api/src/chat-room.ts | Replace hardcoded /unblock regex with registry dispatch |
api/src/types.ts | Add HELP message type + ServerHelpMessage |
app/src/components/Chat/chat-client.ts | Handle help messages, render as notice |
Example Output
When admin types /help:
Available commands: /help — Show this help message /unblock <ip> — Unblock a user by IP address