config.ts 943 B

123456789101112131415161718192021
  1. //读取配置文件
  2. import * as fs from 'fs'
  3. import * as path from 'path'
  4. import * as yaml from 'js-yaml'
  5. import { fileURLToPath } from 'node:url';
  6. const __dirname = path.dirname(fileURLToPath(import.meta.url));
  7. async function loadConfig(file: string): Promise<any> {
  8. const configPath = path.join(__dirname, `../config/${file}.yml`); // 保持源码与编译后一致
  9. return await yaml.load(fs.readFileSync(configPath, 'utf8')) as any;
  10. }
  11. export function saveConfig(file: string, data: any): void {
  12. const configPath = path.join(__dirname, `../config/${file}.yml`); // 保持源码与编译后一致
  13. fs.writeFileSync(configPath, yaml.dump(data));
  14. }
  15. export const Botconfig = await loadConfig('bot');
  16. export const PermissionConfig = await loadConfig('permission');
  17. export const load = await loadConfig('load')
  18. export const economy = await loadConfig('economy')
  19. export const mccfg = await loadConfig('mc')