feat: Add /config admin command to dynamically edit and save bot configuration.

This commit is contained in:
syntaxbullet
2025-12-18 16:25:54 +01:00
parent 56ad5b49cd
commit 4ac8b4759e
4 changed files with 86 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
import { readFileSync, existsSync } from 'fs';
import { join } from 'path';
import { readFileSync, existsSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
const configPath = join(process.cwd(), 'src', 'config', 'config.json');
const configPath = join(import.meta.dir, '..', '..', 'config', 'config.json');
export interface GameConfigType {
leveling: {
@@ -81,3 +81,16 @@ reloadConfig();
// Backwards compatibility alias
export const GameConfig = config;
export function saveConfig(newConfig: GameConfigType) {
const replacer = (key: string, value: any) => {
if (typeof value === 'bigint') {
return value.toString();
}
return value;
};
const jsonString = JSON.stringify(newConfig, replacer, 4);
writeFileSync(configPath, jsonString, 'utf-8');
reloadConfig();
}