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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Slow mode is an admin setting: slowModeSeconds, 0-300, on /admin #212

Parked opened this
Closed without merging

smith/arm:smith/193-slow-mode-is-an-admin-setting-slowmodese → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +19 −1
Software/so101/src/admin-page.ts +1
@@ -133,6 +133,7 @@ ${field("turnSeconds", "Turn length", "seconds, 30–3600", s.turnSeconds, 30, 3
133133 ${field("idleSeconds", "Idle timeout", "seconds without a command, 10–600", s.idleSeconds, 10, 600, off)}
134134 ${field("maxSpeedPercent", "Max speed", "percent of full, on top of the safety limits", s.maxSpeedPercent, 5, 100, off)}
135135 ${field("maxQueue", "Max queue length", "people waiting, 0–100", s.maxQueue, 0, 100, off)}
136 ${field("slowModeSeconds", "Slow mode", "seconds between a person's chat messages, 0 is off, 0–300", s.slowModeSeconds, 0, 300, off)}
136137 <label class="wide">Announcement<small>shown to everyone above the queue; empty for none</small><textarea name="announcement" maxlength="${ANNOUNCEMENT_CHARS}"${off}>${esc(s.announcement)}</textarea></label>
137138 <label class="wide">Arm server<small>where the arm and its cameras are, http://host:port; empty uses ARM_SERVER from the environment, else the simulation; takes effect at once</small><input name="armServer" maxlength="200" value="${esc(s.armServer)}"${off}></label>
138139 </div>
Software/so101/src/admin.test.ts +13
@@ -20,6 +20,19 @@ describe("admin settings", () => {
2020 expect(validateChange({ announcement: "‮\u0007" })).toEqual({ announcement: "" });
2121 });
2222
23 test("slow mode is 0-300 whole seconds, and persists", () => {
24 expect(DEFAULT_ADMIN.slowModeSeconds).toBe(0);
25 for (const bad of [-1, 301, 1.5]) expect(() => validateChange({ slowModeSeconds: bad })).toThrow("slow mode (s) must be a whole number from 0 to 300");
26 expect(() => changeFromForm(new URLSearchParams("slowModeSeconds=301"))).toThrow(AdminError);
27 expect(changeFromForm(new URLSearchParams("slowModeSeconds=300"))).toEqual({ slowModeSeconds: 300 });
28 const file = join(dir(), "admin.json");
29 const a = new Admin({ file });
30 expect(a.set(owner, { slowModeSeconds: 30 })).toEqual(["slowModeSeconds"]);
31 const b = new Admin({ file });
32 expect(b.settings.slowModeSeconds).toBe(30);
33 expect(b.log[0]!.what).toBe("slow mode (s) → 30");
34 });
35
2336 test("a form's numbers arrive as text and are read strictly", () => {
2437 expect(changeFromForm(new URLSearchParams("turnSeconds=90&idleSeconds=20&maxSpeedPercent=40&maxQueue=5&announcement=hi"))).toEqual({ turnSeconds: 90, idleSeconds: 20, maxSpeedPercent: 40, maxQueue: 5, announcement: "hi" });
2538 expect(() => changeFromForm(new URLSearchParams("turnSeconds=1e3"))).toThrow("must be a whole number");
Software/so101/src/admin.ts +5 −1
@@ -19,6 +19,8 @@ export interface AdminSettings {
1919 maxSpeedPercent: number;
2020 /** How many may wait in line. */
2121 maxQueue: number;
22 /** Seconds a person must wait between chat messages; 0 is off. Enforced by the chat, not here. */
23 slowModeSeconds: number;
2224 /** Shown to everyone above the queue; empty for none. */
2325 announcement: string;
2426 /** Where the arm and its cameras are (http://host:port); empty uses ARM_SERVER from the environment, else the simulation. */
@@ -27,7 +29,7 @@ export interface AdminSettings {
2729 moderators: string[];
2830 }
2931
30 export const DEFAULT_ADMIN: AdminSettings = { paused: false, turnSeconds: 180, idleSeconds: 30, maxSpeedPercent: 100, maxQueue: 20, announcement: "", armServer: "", moderators: [] };
32 export const DEFAULT_ADMIN: AdminSettings = { paused: false, turnSeconds: 180, idleSeconds: 30, maxSpeedPercent: 100, maxQueue: 20, slowModeSeconds: 0, announcement: "", armServer: "", moderators: [] };
3133
3234 const NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
3335 export const MAX_MODERATORS = 50;
@@ -38,6 +40,7 @@ const RANGES = {
3840 idleSeconds: [10, 600],
3941 maxSpeedPercent: [5, 100],
4042 maxQueue: [0, 100],
43 slowModeSeconds: [0, 300],
4144 } as const satisfies Partial<Record<keyof AdminSettings, readonly [number, number]>>;
4245 const LABELS: Record<keyof AdminSettings, string> = {
4346 paused: "paused",
@@ -45,6 +48,7 @@ const LABELS: Record<keyof AdminSettings, string> = {
4548 idleSeconds: "idle timeout (s)",
4649 maxSpeedPercent: "max speed (%)",
4750 maxQueue: "max queue length",
51 slowModeSeconds: "slow mode (s)",
4852 announcement: "announcement",
4953 armServer: "arm server",
5054 moderators: "moderators",

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs