Dough Git

commit

Nest autoproxy setting under its own section

commit
329cbf26fc7eeb448a28cecfad3edacb6e08f014
author
Clove Twilight <[email protected]>
date
2026-11-16 20:52
Co-Authored-By: Sandrone <[email protected]>

diff --git a/src/commands/autoproxy.ts b/src/commands/autoproxy.ts
index e30b412..ab55c1b 100644
--- a/src/commands/autoproxy.ts
+++ b/src/commands/autoproxy.ts
@@ -11,12 +11,12 @@ export async function autoproxyCommand(
     const [choice] = args;
 
     if (choice === "on" || choice === "off") {
-        settings.autoproxy = choice === "on";
+        settings.autoproxy.enabled = choice === "on";
         await saveSettings();
     } else if (choice !== undefined) {
         await message.reply("Use `d!autoproxy on` or `d!autoproxy off`.");
         return;
     }
 
-    await message.reply(`Autoproxy is **${settings.autoproxy ? "on" : "off"}**.`);
+    await message.reply(`Autoproxy is **${settings.autoproxy.enabled ? "on" : "off"}**.`);
 }
diff --git a/src/discord/proxyMessage.ts b/src/discord/proxyMessage.ts
index 8f7dd9d..929dcfb 100644
--- a/src/discord/proxyMessage.ts
+++ b/src/discord/proxyMessage.ts
@@ -21,7 +21,7 @@ export async function proxyMessage(message: Message): Promise<void> {
     // Commands never get proxied
     if (await runCommand(message)) return;
 
-    const fronters = settings.autoproxy ? system.fronters : [];
+    const fronters = settings.autoproxy.enabled ? system.fronters : [];
     const match = pickProxy(system.members, fronters, message.content);
     if (!match) return;
     if (!match.content && message.attachments.size === 0) return;
diff --git a/src/state/settings.ts b/src/state/settings.ts
index 82aa0e3..7b6174d 100644
--- a/src/state/settings.ts
+++ b/src/state/settings.ts
@@ -5,19 +5,30 @@ import { dump, load } from "jpcl-lang";
 // Resolved from this file, so it works whatever directory the service starts in
 const settingsFile = new URL("../../data/settings.jp", import.meta.url);
 
+// Each top-level key is a [section] in the .jp file
 export interface Settings {
-    autoproxy: boolean;
+    autoproxy: {
+        enabled: boolean;
+    };
 }
 
 const defaults: Settings = {
-    autoproxy: true,
+    autoproxy: {
+        enabled: true,
+    },
 };
 
-export const settings: Settings = { ...defaults };
+export const settings: Settings = structuredClone(defaults);
 
 export async function loadSettings(): Promise<void> {
     try {
-        Object.assign(settings, await load(settingsFile));
+        const saved = await load(settingsFile) as Partial<Settings>;
+
+        // Merge per section, so keys added later keep their defaults
+        settings.autoproxy = {
+            ...defaults.autoproxy,
+            ...saved.autoproxy,
+        };
     } catch (error) {
         // First run has no file yet; anything else is worth a log
         if ((error as { code?: string }).code !== "ENOENT") {