From 9caa95a0d89389e4a7084f7a5e7e7dbe2b74ef2f Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Thu, 8 Jan 2026 22:44:48 +0100 Subject: [PATCH] feat(settings): support toggling disabled commands and auto-reload bot on save --- bot/lib/BotClient.ts | 3 +++ bot/lib/loaders/CommandLoader.ts | 5 ++++- web/src/server.settings.test.ts | 3 ++- web/src/server.ts | 7 ++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bot/lib/BotClient.ts b/bot/lib/BotClient.ts index a394f6d..da1a868 100644 --- a/bot/lib/BotClient.ts +++ b/bot/lib/BotClient.ts @@ -8,6 +8,7 @@ import { EventLoader } from "@lib/loaders/EventLoader"; export class Client extends DiscordClient { commands: Collection; + knownCommands: Set; lastCommandTimestamp: number | null = null; maintenanceMode: boolean = false; private commandLoader: CommandLoader; @@ -16,6 +17,7 @@ export class Client extends DiscordClient { constructor({ intents }: { intents: number[] }) { super({ intents }); this.commands = new Collection(); + this.knownCommands = new Set(); this.commandLoader = new CommandLoader(this); this.eventLoader = new EventLoader(this); } @@ -77,6 +79,7 @@ export class Client extends DiscordClient { async loadCommands(reload: boolean = false) { if (reload) { this.commands.clear(); + this.knownCommands.clear(); console.log("♻️ Reloading commands..."); } diff --git a/bot/lib/loaders/CommandLoader.ts b/bot/lib/loaders/CommandLoader.ts index 9397641..3264ca2 100644 --- a/bot/lib/loaders/CommandLoader.ts +++ b/bot/lib/loaders/CommandLoader.ts @@ -4,7 +4,7 @@ import type { Command } from "@shared/lib/types"; import { config } from "@shared/lib/config"; import type { LoadResult, LoadError } from "./types"; import type { Client } from "../BotClient"; - + /** * Handles loading commands from the file system @@ -71,6 +71,9 @@ export class CommandLoader { if (this.isValidCommand(command)) { command.category = category; + // Track all known commands regardless of enabled status + this.client.knownCommands.add(command.data.name); + const isEnabled = config.commands[command.data.name] !== false; if (!isEnabled) { diff --git a/web/src/server.settings.test.ts b/web/src/server.settings.test.ts index b6b64a0..a14ec38 100644 --- a/web/src/server.settings.test.ts +++ b/web/src/server.settings.test.ts @@ -61,7 +61,8 @@ mock.module("../../bot/lib/BotClient", () => ({ }, commands: [ { data: { name: "ping" } } - ] + ], + knownCommands: new Set(["ping", "help", "disabled-cmd"]) } })); diff --git a/web/src/server.ts b/web/src/server.ts index 04cd2e4..8e90764 100644 --- a/web/src/server.ts +++ b/web/src/server.ts @@ -186,8 +186,13 @@ export async function createWebServer(config: WebServerConfig = {}): Promise ({ id: c.id, name: c.name, type: c.type })); - const commands = AuroraClient.commands.map(c => c.data.name); + const commands = Array.from(AuroraClient.knownCommands).sort(); return Response.json({ roles, channels, commands }); } catch (error) {