fix(config): enforce runtime schema validation

This commit is contained in:
syntaxbullet
2025-12-22 12:56:20 +01:00
parent 4a0a2a5878
commit 6e1e6abf2d

View File

@@ -122,29 +122,9 @@ export function reloadConfig() {
const rawConfig = JSON.parse(raw);
// Update config object in place
config.leveling = rawConfig.leveling;
config.economy = {
daily: {
...rawConfig.economy.daily,
amount: BigInt(rawConfig.economy.daily.amount),
streakBonus: BigInt(rawConfig.economy.daily.streakBonus),
},
transfers: {
...rawConfig.economy.transfers,
minAmount: BigInt(rawConfig.economy.transfers.minAmount),
},
exam: rawConfig.economy.exam,
};
config.inventory = {
...rawConfig.inventory,
maxStackSize: BigInt(rawConfig.inventory.maxStackSize),
};
config.commands = rawConfig.commands || {};
config.lootdrop = rawConfig.lootdrop;
config.studentRole = rawConfig.studentRole;
config.visitorRole = rawConfig.visitorRole;
config.welcomeChannelId = rawConfig.welcomeChannelId;
config.welcomeMessage = rawConfig.welcomeMessage;
// We use Object.assign to keep the reference to the exported 'config' object same
const validatedConfig = configSchema.parse(rawConfig);
Object.assign(config, validatedConfig);
console.log("🔄 Config reloaded from disk.");
}