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 #206
smith/arm:smith/193-slow-mode-is-an-admin-setting-slowmodese → main 1 commit fork
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 | ||
| 133 | 133 | ${field("idleSeconds", "Idle timeout", "seconds without a command, 10–600", s.idleSeconds, 10, 600, off)} |
| 134 | 134 | ${field("maxSpeedPercent", "Max speed", "percent of full, on top of the safety limits", s.maxSpeedPercent, 5, 100, off)} |
| 135 | 135 | ${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)} | |
| 136 | 137 | <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> |
| 137 | 138 | <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> |
| 138 | 139 | </div> |
Software/so101/src/admin.test.ts +13
| @@ -20,6 +20,19 @@ describe("admin settings", () => { | ||
| 20 | 20 | expect(validateChange({ announcement: "\u0007" })).toEqual({ announcement: "" }); |
| 21 | 21 | }); |
| 22 | 22 | |
| 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 | ||
| 23 | 36 | test("a form's numbers arrive as text and are read strictly", () => { |
| 24 | 37 | 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" }); |
| 25 | 38 | 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 { | ||
| 19 | 19 | maxSpeedPercent: number; |
| 20 | 20 | /** How many may wait in line. */ |
| 21 | 21 | maxQueue: number; |
| 22 | /** Seconds a person must wait between chat messages; 0 is off. Enforced by the chat, not here. */ | |
| 23 | slowModeSeconds: number; | |
| 22 | 24 | /** Shown to everyone above the queue; empty for none. */ |
| 23 | 25 | announcement: string; |
| 24 | 26 | /** 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 { | ||
| 27 | 29 | moderators: string[]; |
| 28 | 30 | } |
| 29 | 31 | |
| 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: [] }; | |
| 31 | 33 | |
| 32 | 34 | const NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/; |
| 33 | 35 | export const MAX_MODERATORS = 50; |
| @@ -38,6 +40,7 @@ const RANGES = { | ||
| 38 | 40 | idleSeconds: [10, 600], |
| 39 | 41 | maxSpeedPercent: [5, 100], |
| 40 | 42 | maxQueue: [0, 100], |
| 43 | slowModeSeconds: [0, 300], | |
| 41 | 44 | } as const satisfies Partial<Record<keyof AdminSettings, readonly [number, number]>>; |
| 42 | 45 | const LABELS: Record<keyof AdminSettings, string> = { |
| 43 | 46 | paused: "paused", |
| @@ -45,6 +48,7 @@ const LABELS: Record<keyof AdminSettings, string> = { | ||
| 45 | 48 | idleSeconds: "idle timeout (s)", |
| 46 | 49 | maxSpeedPercent: "max speed (%)", |
| 47 | 50 | maxQueue: "max queue length", |
| 51 | slowModeSeconds: "slow mode (s)", | |
| 48 | 52 | announcement: "announcement", |
| 49 | 53 | armServer: "arm server", |
| 50 | 54 | moderators: "moderators", |
new above
offline