From 3f028eb76a60f08812af973a62f50be4a197f0f1 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Thu, 8 Jan 2026 16:21:25 +0100 Subject: [PATCH] refactor: consolidate config loading --- bot/commands/admin/features.ts | 7 +++---- shared/lib/config.ts | 13 ++++++++++++- shared/lib/configManager.ts | 19 ------------------- 3 files changed, 15 insertions(+), 24 deletions(-) delete mode 100644 shared/lib/configManager.ts diff --git a/bot/commands/admin/features.ts b/bot/commands/admin/features.ts index 48f9bea..270d594 100644 --- a/bot/commands/admin/features.ts +++ b/bot/commands/admin/features.ts @@ -1,8 +1,7 @@ import { createCommand } from "@shared/lib/utils"; import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js"; import { createBaseEmbed } from "@lib/embeds"; -import { configManager } from "@shared/lib/configManager"; -import { config, reloadConfig } from "@shared/lib/config"; +import { config, reloadConfig, toggleCommand } from "@shared/lib/config"; import { AuroraClient } from "@/lib/BotClient"; export const features = createCommand({ @@ -79,11 +78,11 @@ export const features = createCommand({ await interaction.deferReply({ flags: MessageFlags.Ephemeral }); - configManager.toggleCommand(commandName, enabled); + toggleCommand(commandName, enabled); await interaction.editReply({ content: `✅ Command **${commandName}** has been ${enabled ? "enabled" : "disabled"}. Reloading configuration...` }); - // Reload config from disk (which was updated by configManager) + // Reload config from disk (which was updated by toggleCommand) reloadConfig(); await AuroraClient.loadCommands(true); diff --git a/shared/lib/config.ts b/shared/lib/config.ts index f5e678d..1ffaea9 100644 --- a/shared/lib/config.ts +++ b/shared/lib/config.ts @@ -2,7 +2,7 @@ import { readFileSync, existsSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; import { z } from 'zod'; -const configPath = join(import.meta.dir, '..', '..', 'config', 'config.json'); +const configPath = join(import.meta.dir, '..', 'config', 'config.json'); export interface GameConfigType { leveling: { @@ -202,3 +202,14 @@ export function saveConfig(newConfig: unknown) { writeFileSync(configPath, jsonString, 'utf-8'); reloadConfig(); } + +export function toggleCommand(commandName: string, enabled: boolean) { + const newConfig = { + ...config, + commands: { + ...config.commands, + [commandName]: enabled + } + }; + saveConfig(newConfig); +} diff --git a/shared/lib/configManager.ts b/shared/lib/configManager.ts deleted file mode 100644 index 8ea5ca7..0000000 --- a/shared/lib/configManager.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { readFileSync, writeFileSync } from 'fs'; -import { join } from 'path'; - -const configPath = join(process.cwd(), 'config', 'config.json'); - -export const configManager = { - toggleCommand: (commandName: string, enabled: boolean) => { - const raw = readFileSync(configPath, 'utf-8'); - const data = JSON.parse(raw); - - if (!data.commands) { - data.commands = {}; - } - - data.commands[commandName] = enabled; - - writeFileSync(configPath, JSON.stringify(data, null, 4)); - } -};