Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

/admin shows today's peak viewers and joins per hour for the last 24 h, owner only, kept under FORGE_APP_DATA across a restart #414

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/399-admin-shows-today-s-peak-viewers-and-joi → main 5 commits fork 3 threads · 3 unresolved

  • Merged. smith/399-admin-shows-today-s-peak-viewers-and-joi was merged into main as 40cb8df.

Review

Sign in to review this change.
10 files changed +194 −3
Software/README.md +1
@@ -567,6 +567,7 @@ reaches it as the owner.
567567 or from the **Admin** tab that only the owner sees:
568568
569569 - **Reports** (owner and moderators; `/admin` is open to a moderator who holds a forge identity) lists the open chat reports, newest first, each with **Remove** (take the line down for everyone), **Mute** (mute its author for good) and **Dismiss** (close the reports, nothing else). Each closes the line's reports and is written to the admin log. `/delete` and `/mute` from either door close them too.
570 - **Visitors** (owner only; a moderator's page has no such section, anyone else gets the 404) shows today's peak viewers and joins per hour for the last 24 hours, oldest first, as a text chart with no script. In the terminal the owner types `/visitors` for the same two numbers (anyone else is refused). Counts only, no names or addresses: the lobby counts every `/live` connect and disconnect and keeps them in `$FORGE_APP_DATA/so101/visitors.json` (saved at most once a minute and on close), so they survive a restart; the peak is per day and the hours roll off after 24.
570571 - **Table height** (-100..100 mm, `tableOffsetMm`) is a number field under Table height on `/admin`:
571572 Save sends `PUT /settings` and shows the saved value or the server's error.
572573 - **Pause the queue** for maintenance. The driver's turn ends (unless it is
Software/so101/bench/fake-serve.ts +1
@@ -52,6 +52,7 @@ const lobby = new Lobby({
5252 local,
5353 chatFile: join(dir, "chat.json"),
5454 adminFile: join(dir, "admin.json"),
55 countsFile: join(dir, "visitors.json"),
5556 turnsFile: join(dir, "turns.json"),
5657 wordsFile: join(dir, "words.json"),
5758 reportsFile: join(dir, "reports.json"),
Software/so101/src/admin-page.ts +13
@@ -53,6 +53,9 @@ th, td { text-align: right; padding: .3rem .5rem; border-bottom: 1px solid var(-
5353 th:first-child, td:first-child { text-align: left; }
5454 th { color: var(--dim); font-weight: 600; }
5555 .scroll { overflow-x: auto; }
56 .bars li { grid-template-columns: 3.5rem 1fr; gap: .5rem; overflow-wrap: normal; font-family: ui-monospace, monospace; border: 0; padding: 0; }
outdated

5rem + 1fr + the inherited 1rem gap leaves too little at 360px for the bar; shrink the label column and add overflow-wrap: normal here so the bar does not break mid-run.

57 .bars li span:nth-child(2) { color: var(--blue); }
58 .bars li b { color: var(--fg); font-weight: 600; }
5659 .inline { display: inline; margin: 0; }
5760 .empty { color: var(--dim); }
5861 @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@@ -146,6 +149,8 @@ export interface AdminPage {
146149 /** Mutes and bans in force, each with a button to lift it. */
147150 muted?: readonly Target[];
148151 banned?: readonly Target[];
152 /** Owner only: today's peak and joins per hour for the last 24 hours, oldest first. */
153 visitors?: { peak: number; hours: readonly number[] };
149154 done?: Done | null;
150155 error?: string | null;
151156 }
@@ -217,6 +222,13 @@ const inForce = (kind: "mute" | "ban", list: readonly Target[], canLift: (name:
217222 : "";
218223 };
219224
225 /** Today's peak and a 24-bar text chart, oldest first, the last row the current hour; no script, nothing from a person. */
226 const visitorsSection = (v: { peak: number; hours: readonly number[] }): string => {
outdated

Repeat of █ is read aloud char by char. Wrap the bars in <span aria-hidden="true"> and keep ${n} in a separate span; 30 blocks also overflows 360px — use ~16.

227 const max = Math.max(1, ...v.hours);
228 const bars = v.hours.map((n, i) => `<li><span>${i === 23 ? "now" : `-${23 - i}h`}</span><span><span aria-hidden="true">${"█".repeat(Math.round((n / max) * 16))}</span> <b>${n}</b></span></li>`).join("");
229 return `<section aria-labelledby="visitors"><h2 id="visitors">Visitors</h2><p>Peak viewers today: <b>${v.peak}</b></p><ol class="bars" aria-label="Joins per hour, last 24 hours, oldest first">${bars}</ol></section>`;
230 };
231
220232 export function renderAdmin(p: AdminPage): string {
221233 const s = p.settings;
222234 const d = p.snapshot.driver;
@@ -261,6 +273,7 @@ ${p.canEdit ? `<section aria-labelledby="table"><h2 id="table">Table height</h2>
261273 <div class="grid"><label>Table height<small>mm above the model's floor, -100 to 100; the safe zone keeps the arm above it</small><input id="table-mm" type="number" inputmode="numeric" min="-100" max="100" step="1"></label></div>
262274 <div class="save"><button type="button" class="go" id="table-save">Save</button> <button type="button" id="table-here">The arm rests on the table now</button> <span id="table-note" role="status"></span></div>
263275 </section>` : ""}
276 ${p.canEdit && p.visitors ? visitorsSection(p.visitors) : ""}
264277 <section aria-labelledby="health"><h2 id="health">Health</h2>${health(p.health ?? [])}</section>
265278 <section aria-labelledby="mods"><h2 id="mods">Moderators</h2>${mods}</section>
266279 <section aria-labelledby="moderation"><h2 id="moderation">Moderation</h2>${inForce("mute", p.muted ?? [], canLift)}${inForce("ban", p.banned ?? [], canLift)}${actions}</section>
Software/so101/src/admin-routes.ts +1 −1
@@ -44,7 +44,7 @@ export function serveAdminPage(lobby: Lobby, req: IncomingMessage, res: ServerRe
4444 return null;
4545 }
4646 const show = (status: number, done: Done | null, error: string | null) =>
47 html(status, renderAdmin({ who, canEdit, settings: lobby.admin.settings, snapshot: lobby.turns.snapshot(), log: lobby.admin.log, removed: lobby.chat.removed, muted: lobby.chat.mutedList(), banned: lobby.accounts.bans(), health: lobby.reports.rows(), reports: lobby.lineReports.list(), done, error }), canEdit);
47 html(status, renderAdmin({ who, canEdit, settings: lobby.admin.settings, snapshot: lobby.turns.snapshot(), log: lobby.admin.log, removed: lobby.chat.removed, muted: lobby.chat.mutedList(), banned: lobby.accounts.bans(), health: lobby.reports.rows(), reports: lobby.lineReports.list(), visitors: canEdit ? { peak: lobby.visitors.peakToday(), hours: lobby.visitors.joinsPerHour() } : undefined, done, error }), canEdit);
4848 if (req.method === "GET" || req.method === "HEAD") {
4949 const done = url.searchParams.get("done");
5050 show(200, done && Object.hasOwn(DONE, done) ? (done as Done) : null, null);
Software/so101/src/admin-visitors.test.ts added +96
@@ -0,0 +1,96 @@
1 import { afterEach, expect, test } from "bun:test";
2 import { mkdtempSync, rmSync } from "node:fs";
3 import { tmpdir } from "node:os";
4 import { join } from "node:path";
5 import WebSocket from "ws";
6 import { sign } from "./identity.ts";
7 import { Lobby } from "./lobby.ts";
8 import { startRelay, type RunningRelay } from "./relay.ts";
9
10 const KEY = "k".repeat(64);
11 const later = Date.now() + 600_000;
12 const as = (name: string, role: "user" | "admin") => {
13 const identity = `id-${name}|${name}|${role}|${later}`;
14 return { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) };
15 };
16 const owner = as("trevato", "admin");
17
18 const sockets: WebSocket[] = [];
19 let dir = "";
20 let relay: RunningRelay | undefined;
21 let lobby: Lobby | undefined;
22 afterEach(async () => {
23 for (const s of sockets.splice(0)) s.terminate();
24 await relay?.close();
25 lobby?.close();
26 if (dir) rmSync(dir, { recursive: true, force: true });
27 dir = "";
28 relay = lobby = undefined;
29 });
30
31 async function boot() {
32 dir ||= mkdtempSync(join(tmpdir(), "so101-admin-visitors-"));
33 lobby = new Lobby({ identityKey: KEY, adminFile: join(dir, "admin.json"), countsFile: join(dir, "visitors.json") });
34 relay = await startRelay({ port: 0, simulation: "http://127.0.0.1:1", lobby });
35 return `http://127.0.0.1:${relay.port}`;
36 }
37
38 type Msg = Record<string, unknown>;
39
40 /** Open a socket and wait for its hello; `ask` sends a frame and resolves with the first frame of that type. */
41 async function open(base: string, headers: Record<string, string> = {}) {
42 const ws = new WebSocket(`${base.replace("http", "ws")}/live`, { headers });
43 sockets.push(ws);
44 const heard: Msg[] = [];
45 const waiting: Array<[string, (m: Msg) => void]> = [];
46 ws.on("message", (d) => {
47 const m = JSON.parse(String(d)) as Msg;
48 heard.push(m);
49 for (const w of [...waiting]) if (w[0] === m.type) (waiting.splice(waiting.indexOf(w), 1), w[1](m));
50 });
51 await new Promise((ok, no) => (ws.once("open", ok), ws.once("error", no)));
52 const ask = (frame: Msg, type: string) => new Promise<Msg>((ok) => (waiting.push([type, ok]), ws.send(JSON.stringify(frame))));
53 return { ws, ask };
54 }
55
56 /** n visitors at once, all gone before it returns. */
57 async function visit(base: string, n: number) {
58 const seats = await Promise.all(Array.from({ length: n }, () => open(base)));
59 await Promise.all(seats.map(({ ws }) => new Promise((ok) => (ws.once("close", ok), ws.close()))));
60 }
61
62 test("the owner sees the peak and 24 bars; a moderator and a plain user do not; the counts survive a restart", async () => {
63 let base = await boot();
64 const mod = as("bob", "user");
65 await fetch(`${base}/admin`, { method: "POST", headers: { ...owner, "content-type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ action: "mod-add", name: "bob" }), redirect: "manual" });
66 await visit(base, 3);
67 const html = await (await fetch(`${base}/admin`, { headers: owner })).text();
68 expect(html).toContain("Peak viewers today: <b>");
69 expect(html.match(/<li><span>(now|-\d+h)<\/span>/g)?.length).toBe(24);
70 expect(html).toContain('<span aria-hidden="true">');
71 expect(html).not.toMatch(/█{17}/);
72 const peak = Number(/Peak viewers today: <b>(\d+)/.exec(html)![1]);
73 expect(peak).toBe(3);
74 expect(await (await fetch(`${base}/admin`, { headers: mod })).text()).not.toContain("Peak viewers");
75 expect((await fetch(`${base}/admin`, { headers: as("eve", "user") })).status).toBe(404);
76
77 await relay!.close();
78 lobby!.close();
79 base = await boot();
80 const after = await (await fetch(`${base}/admin`, { headers: owner })).text();
81 expect(after).toContain(`Peak viewers today: <b>${peak}</b>`);
82 expect(lobby!.visitors.joinsPerHour().reduce((a, b) => a + b, 0)).toBe(3);
83 });
84
85 test("over /live only the owner can ask for the peak and joins per hour", async () => {
86 const base = await boot();
87 await visit(base, 2);
88 await fetch(`${base}/admin`, { method: "POST", headers: { ...owner, "content-type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ action: "mod-add", name: "bob" }), redirect: "manual" });
89 const seen = await (await open(base, owner)).ask({ type: "visitors" }, "visitors");
90 expect(seen.peak).toBe(2);
91 expect((seen.hours as number[]).length).toBe(24);
92 for (const headers of [as("bob", "user"), as("eve", "user"), {}]) {
93 const r = await (await open(base, headers)).ask({ type: "visitors" }, "error");
94 expect(r.error).toBe(Object.keys(headers).length ? "only the owner can do that" : "join to take part");
95 }
96 });
Software/so101/src/fake-serve.test.ts +13 −1
@@ -1,5 +1,6 @@
11 import { afterEach, expect, test } from "bun:test";
2 import { existsSync, mkdtempSync, rmSync } from "node:fs";
2 import WebSocket from "ws";
3 import { existsSync, readFileSync, mkdtempSync, rmSync } from "node:fs";
34 import { tmpdir } from "node:os";
45 import { join } from "node:path";
56
@@ -42,6 +43,17 @@ test("fake-serve listens on PORT and HOST and keeps its data under FORGE_APP_DAT
4243 expect(existsSync(join(dir, "so101", "poses.json"))).toBe(true);
4344 }, 20_000);
4445
46 test("the visitor counts are kept as visitors.json under FORGE_APP_DATA", async () => {
47 dir = mkdtempSync(join(tmpdir(), "so101-appdata-"));
48 const { port } = await start({ PORT: "0", HOST: "127.0.0.1", FORGE_APP_DATA: dir, FORGE_APP_ENV: "", FORGE_APP_IDENTITY_KEY: "" });
49 const ws = new WebSocket(`ws://127.0.0.1:${port}/live`);
50 await new Promise((ok, no) => (ws.once("open", ok), ws.once("error", no)));
51 const file = join(dir, "so101", "visitors.json");
52 for (let i = 0; i < 50 && !existsSync(file); i++) await Bun.sleep(100);
53 ws.close();
54 expect(JSON.parse(readFileSync(file, "utf8")).peak).toBe(1);
55 }, 20_000);
56
4557 test("on the forge, an anonymous visitor watches but cannot command the arm", async () => {
4658 dir = mkdtempSync(join(tmpdir(), "so101-appdata-"));
4759 const { port, line } = await start({ PORT: "0", HOST: "127.0.0.1", FORGE_APP_DATA: dir, FORGE_APP_ENV: "preview", FORGE_APP_IDENTITY_KEY: "a key" });
Software/so101/src/lobby.ts +48
@@ -17,6 +17,7 @@
1717 * {"type": "settings", "set": {…}} owner: any of src/admin.ts's settings
1818 * {"type": "crew", "settings": {"enabled", "rules", "maxPerMinute"}} owner: the moderator's settings
1919 * {"type": "removed"} owner: the latest removed lines, answered with {"type": "removed", "lines": [...]}
20 * {"type": "visitors"} owner: today's peak and joins per hour, answered with {"type": "visitors", "peak", "hours": [24 numbers, oldest first]}
2021 * {"type": "restore", "id": 12} owner: put back a removed line, or one the crew hid
2122 * {"type": "dismiss", "id": 12} owner: dismiss a mute suggestion
2223 * {"type": "hosts", "hosts": ["…"]} owner: hostnames chat may link to; any other link is refused
@@ -36,6 +37,7 @@
3637 * `publish`es to everyone: the arm's status, so a page needs this one socket for the pose, the chat and the queue.
3738 */
3839
40 import { readFileSync, renameSync, writeFileSync } from "node:fs";
3941 import { randomBytes } from "node:crypto";
4042 import { dirname, join } from "node:path";
4143 import type { IncomingMessage } from "node:http";
@@ -52,6 +54,7 @@ import { ChatRules } from "./chat-rules.ts";
5254 import { Reports } from "./reports.ts";
5355 import { WordFilter } from "./word-filter.ts";
5456 import { identify, LOCAL, type Person, type Who } from "./identity.ts";
57 import { VisitorCounts } from "./visitor-counts.ts";
5558 import { Turns, type TurnEvent } from "./turns.ts";
5659 import { parseReport, ViewerReports } from "./viewer-reports.ts";
5760
@@ -75,6 +78,8 @@ export interface LobbyOptions {
7578 hostsFile?: string;
7679 /** The chat reports' file; none keeps them in memory. */
7780 reportsFile?: string;
81 /** The visitor counts' file (peak, joins per hour); none keeps them in memory. */
82 countsFile?: string;
7883 /** The admin settings' file; none keeps them in memory. */
7984 adminFile?: string;
8085 /** The line and the current turn's file; none keeps them in memory. */
@@ -124,6 +129,11 @@ export class Lobby {
124129 /** Chat lines people reported, for the owner and moderators. */
125130 readonly lineReports: Reports;
126131 readonly local: boolean;
132 /** Counts only: today's peak and joins per hour, for the owner's /admin. */
133 readonly visitors: VisitorCounts;
134 private readonly countsFile: string | undefined;
135 private countsSaved = 0;
136 private countsTimer: ReturnType<typeof setTimeout> | undefined;
127137 readonly moderator: Moderator | undefined;
128138 private readonly key: string;
129139 private readonly wss = new WebSocketServer({ noServer: true, maxPayload: MAX_FRAME });
@@ -156,6 +166,14 @@ export class Lobby {
156166 this.filter = new WordFilter(options.wordsFile);
157167 this.rules = new ChatRules(options.hostsFile ?? (options.wordsFile ? join(dirname(options.wordsFile), "hosts.json") : undefined));
158168 this.reports = new ViewerReports(this.now);
169 this.visitors = new VisitorCounts(this.now);
170 this.countsFile = options.countsFile;
171 if (this.countsFile) {
172 try {
173 this.visitors.restore(JSON.parse(readFileSync(this.countsFile, "utf8")));
174 } catch {}
175 this.visitors.clearHere();
176 }
159177 this.lineReports = new Reports(options.reportsFile);
160178 this.silentMs = options.silentMs ?? 15_000;
161179 this.moderator = options.moderator;
@@ -304,6 +322,8 @@ export class Lobby {
304322 close(): void {
305323 clearInterval(this.pinger);
306324 clearTimeout(this.presenceTimer);
325 clearTimeout(this.countsTimer);
326 this.saveCounts();
307327 for (const s of this.seats) s.ws.terminate();
308328 this.wss.close();
309329 this.turns.dispose();
@@ -315,6 +335,8 @@ export class Lobby {
315335 const seat: Seat = { ws, who, from, verified, heard: Date.now() };
316336 if (!who) seat.guest = this.claim(id);
317337 this.seats.add(seat);
338 this.visitors.joined();
339 this.countsChanged();
318340 this.presenceChanged();
319341 if (who) this.turns.connect(who.id);
320342 this.send(seat, this.hello(seat));
@@ -354,6 +376,8 @@ export class Lobby {
354376 });
355377 ws.on("close", () => {
356378 this.seats.delete(seat);
379 this.visitors.left();
380 this.countsChanged();
357381 if (seat.guest) this.release(seat.guest.id);
358382 this.presenceChanged();
359383 this.reports.drop(seat);
@@ -484,6 +508,8 @@ export class Lobby {
484508 return;
485509 case "removed":
486510 return this.send(seat, { type: "removed", lines: this.chat.removed.slice(0, 20).map((r) => ({ id: r.message.id, by: r.by.name, from: r.message.from?.name ?? null, text: r.message.text })) });
511 case "visitors":
512 return this.send(seat, { type: "visitors", peak: this.visitors.peakToday(), hours: this.visitors.joinsPerHour() });
487513 case "restore": {
488514 if (!this.restoreLine(who, m.id)) this.send(seat, { type: "error", error: "that line is not in the log" });
489515 return;
@@ -750,6 +776,28 @@ export class Lobby {
750776 return { type: "presence", here: this.seats.size, signedIn: people.size, watching };
751777 }
752778
779 private saveCounts(): void {
780 if (!this.countsFile) return;
781 this.countsSaved = Date.now();
782 try {
783 writeFileSync(`${this.countsFile}.tmp`, JSON.stringify(this.visitors));
784 renameSync(`${this.countsFile}.tmp`, this.countsFile);
785 } catch (err) {
786 console.error(`lobby: counts not saved: ${err instanceof Error ? err.message : String(err)}`);
787 }
788 }
789
790 /** Saves at most once a minute: now if the last save is old enough, else when the minute is up. */
791 private countsChanged(): void {
792 if (!this.countsFile || this.countsTimer) return;
793 const wait = Math.max(0, this.countsSaved + 60_000 - Date.now());
794 this.countsTimer = setTimeout(() => {
795 this.countsTimer = undefined;
796 this.saveCounts();
797 }, wait);
798 this.countsTimer.unref?.();
799 }
800
753801 /** Who is here, for a "who" answer: a signed-in person once however many tabs, a guest by name and colour. No address or id. */
754802 private people(): Array<{ name: string; colour?: string; guest: boolean; role: "driving" | "queued" | "watching" }> {
755803 const out: Array<{ name: string; colour?: string; guest: boolean; role: "driving" | "queued" | "watching" }> = [];
Software/so101/src/terminal.test.ts +8
@@ -144,6 +144,14 @@ describe("terminal table", () => {
144144 expect(refused).toEqual({ status: 403, error: "admins only" });
145145 });
146146
147 test("/visitors sends the frame and the answer prints the peak and 24 hours as text", () => {
148 expect(typed(emptyRoom(), "/visitors")).toEqual({ send: { type: "visitors" } });
149 const hours = Array.from({ length: 24 }, (_, i) => i);
150 const [line] = hear(emptyRoom(), { type: "visitors", peak: 7, hours });
151 expect(line).toBe(`peak viewers today 7 · joins per hour, oldest first: ${hours.join(" ")}`);
152 expect(hear(emptyRoom(), { type: "error", error: "only the owner can do that" })).toEqual(["error: only the owner can do that"]);
153 });
154
147155 test("/health asks the reader, prints a line per viewer as text, or the refusal; without a reader it says so", async () => {
148156 expect(typed(emptyRoom(), "/health")).toEqual({ health: true });
149157 const row = { viewer: "v1", name: "al\x1b[31mice", rttP50: 40, rttP95: 90, sentPerS: 30, droppedPerS: 2, camFps: 14.5, frameAgeMs: 120, stalls: 1, reconnects: 2 };
Software/so101/src/terminal.ts +8 −1
@@ -26,6 +26,7 @@
2626 * /reports owner or moderator: the reported lines, newest first (they also hear of each new one)
2727 * /dismiss #<id> owner or moderator: close that line's reports and nothing else (Lobby.dismissReported; it is logged)
2828 * /removed owner: the latest removed chat lines, with their numbers and who removed them
29 * /visitors owner: today's peak viewers and joins per hour for the last 24 h (the counts /admin shows)
2930 * /restore #<n> owner: put a removed line back for everyone (Lobby.restoreLine; it is logged)
3031 * /table here admin: put the table under the arm's lowest link now (POST /settings/table-here)
3132 * /table <mm> admin: set the table offset, -100..100 mm (PUT /settings tableOffsetMm)
@@ -175,7 +176,7 @@ const said = (room: Room, m: unknown): string => {
175176 return from ? `${tag}${plain(from.name)}: ${plain(message?.text)}` : `· ${plain(message?.text)}`;
176177 };
177178
178 export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /table here|<mm> (owner) · /mute <who> /unmute <who> (owner, moderator) · /delete <who|#id> (owner, moderator) · /report <who|#id> · /reports /dismiss #<id> (owner, moderator) · /removed /restore #<id> (owner) · /health (owner, moderator) · /machine [off] · /who · /quit";
179 export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /table here|<mm> (owner) · /mute <who> /unmute <who> (owner, moderator) · /delete <who|#id> (owner, moderator) · /report <who|#id> · /reports /dismiss #<id> (owner, moderator) · /removed /restore #<id> /visitors (owner) · /health (owner, moderator) · /machine [off] · /who · /quit";
179180
180181 /** The Machine feed's socket beside the lobby's: same app, same port. */
181182 export const machineUrl = (live: string): string => live.replace(/\/live$/, "/machine");
@@ -285,6 +286,10 @@ export function hear(room: Room, frame: Frame): string[] {
285286 if (!lines.length) return ["no removed lines"];
286287 return lines.map((l: { id?: unknown; by?: unknown; from?: unknown; text?: unknown }) => `removed #${plain(l?.id)} by ${plain(l?.by)}, ${l?.from ? plain(l.from) : "system"}: ${plain(l?.text)}`);
287288 }
289 case "visitors": {
290 const hours = Array.isArray(frame.hours) ? frame.hours.filter((n): n is number => typeof n === "number") : [];
291 return [`peak viewers today ${plain(frame.peak)} · joins per hour, oldest first: ${hours.map(plain).join(" ")}`];
292 }
288293 case "error":
289294 return [`error: ${plain(frame.error)}`];
290295 default:
@@ -358,6 +363,8 @@ export function typed(room: Room, input: string): Typed {
358363 }
359364 case "removed":
360365 return { send: { type: "removed" } };
366 case "visitors":
367 return { send: { type: "visitors" } };
361368 case "restore": {
362369 const number = /^#?(\d{1,15})$/.exec(arg);
363370 return number ? { send: { type: "restore", id: Number(number[1]) } } : { print: "usage: /restore #<line number>" };
Software/so101/src/visitor-counts.ts +5
@@ -54,6 +54,11 @@ export class VisitorCounts {
5454 if (this.here > 0) this.here--
5555 }
5656
57 /** Nobody is connected any more (a restart): the peak and the hours stay. */
58 clearHere(): void {
59 this.here = 0
60 }
61
5762 peakToday(): number {
5863 this.roll()
5964 return this.peak

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs