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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Slow mode refuses a second chat line within slowModeSeconds with 'slow mode: wait Ns'; the owner and moderators are exempt - lobby and test only #408

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/381-slow-mode-refuses-a-second-chat-line-wit → main 1 commit fork 1 thread · 1 unresolved

  • Merged. smith/381-slow-mode-refuses-a-second-chat-line-wit was merged into main as 8d8a0e7.

Review

Sign in to review this change.
2 files changed +37 −0
Software/so101/src/lobby.test.ts +31
@@ -334,6 +334,37 @@ describe("lobby", () => {
334334 expect((await alice.next((m) => m.type === "said")).message.text).toBe("back");
335335 });
336336
337 test("slow mode holds a second line until slowModeSeconds have passed; owner and moderators are never held; 0 holds nobody", async () => {
338 let clock = 1_000_000;
339 const admin = new Admin();
340 admin.set({ id: "u-owner", name: "trevato", owner: true }, { moderators: ["bob"], slowModeSeconds: 5 });
341 lobby = new Lobby({ identityKey: KEY, turns: new Turns(), chat: new Chat({ now: () => clock }), admin, accounts: new Accounts(), now: () => clock, pingMs: 20 });
342 relay = await startRelay({ port: 0, simulation: `http://127.0.0.1:${simulation.port}`, lobby });
343 const alice = await join(relay.port, ALICE);
344 const bob = await join(relay.port, BOB);
345 const owner = await join(relay.port, OWNER);
346 alice.send({ type: "post", text: "one" });
347 await alice.next((m) => m.type === "said" && m.message.text === "one");
348 clock += 4000;
349 alice.send({ type: "post", text: "two" });
350 expect((await alice.next((m) => m.type === "error")).error).toBe("slow mode: wait 1s");
351 expect(bob.heard.some((m) => m.type === "said" && m.message.text === "two")).toBe(false);
352 clock += 1000; // the refused line did not reset the timer
353 alice.send({ type: "post", text: "three" });
354 await alice.next((m) => m.type === "said" && m.message.text === "three");
355 for (const who of [bob, owner]) for (const text of ["a", "b"]) {
356 clock += 3000;
357 who.send({ type: "post", text });
358 await who.next((m) => m.type === "said" && m.message.text === text);
359 }
360 admin.set({ id: "u-owner", name: "trevato", owner: true }, { slowModeSeconds: 0 });
361 for (const text of ["x", "y"]) {
362 clock += 3000;
363 alice.send({ type: "post", text });
364 await alice.next((m) => m.type === "said" && m.message.text === text);
365 }
366 });
367
337368 test("a moderator deletes a chat line and it is logged; a plain user is refused; settings and pause stay the owner's", async () => {
338369 const admin = new Admin();
339370 admin.set({ id: "u-owner", name: "trevato", owner: true }, { moderators: ["bob"] });
Software/so101/src/lobby.ts +6
@@ -129,6 +129,8 @@ export class Lobby {
129129 private readonly presenceMs: number;
130130 private presenceTimer: ReturnType<typeof setTimeout> | undefined;
131131 private readonly now: () => number;
132 /** id → when their last line was accepted, for slow mode. */
133 private readonly lastPosted = new Map<string, number>();

This map grows by one entry per distinct poster for the life of the process. Prune entries older than slowModeSeconds, or delete on disconnect.

132134
133135 constructor(options: LobbyOptions = {}) {
134136 this.now = options.now ?? Date.now;
@@ -379,7 +381,11 @@ export class Lobby {
379381 case "post": {
380382 if (!who.owner && typeof m.text === "string" && this.filter.blocks(m.text)) throw new ChatError("that word is not allowed here");
381383 if (!who.owner && typeof m.text === "string") this.rules.check(who.id, m.text);
384 const slow = this.admin.settings.slowModeSeconds * 1000;
385 const held = slow > 0 && !this.mayModerate(who, seat.verified) ? slow - (this.now() - (this.lastPosted.get(who.id) ?? -Infinity)) : 0;
386 if (held > 0) throw new ChatError(`slow mode: wait ${Math.ceil(held / 1000)}s`);
382387 const said = this.chat.post(who, m.text);
388 this.lastPosted.set(who.id, this.now());
383389 this.broadcast({ type: "said", message: said });
384390 void this.moderator?.check(said);
385391 return;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs