fix(config): enforce runtime schema validation
This commit is contained in:
@@ -122,29 +122,9 @@ export function reloadConfig() {
|
|||||||
const rawConfig = JSON.parse(raw);
|
const rawConfig = JSON.parse(raw);
|
||||||
|
|
||||||
// Update config object in place
|
// Update config object in place
|
||||||
config.leveling = rawConfig.leveling;
|
// We use Object.assign to keep the reference to the exported 'config' object same
|
||||||
config.economy = {
|
const validatedConfig = configSchema.parse(rawConfig);
|
||||||
daily: {
|
Object.assign(config, validatedConfig);
|
||||||
...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;
|
|
||||||
|
|
||||||
console.log("🔄 Config reloaded from disk.");
|
console.log("🔄 Config reloaded from disk.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user