mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
Prevents EADDRINUSE crash that killed the entire app when port 3200 was still occupied from a previous run. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
import { dirname } from "node:path";
|
|
|
|
export interface BotConfig {
|
|
webPort: number;
|
|
locale: "zh" | "en";
|
|
theme: "dark" | "light";
|
|
commandPrefix: string;
|
|
commandAliases: Record<string, string>;
|
|
neteaseApiPort: number;
|
|
qqMusicApiPort: number;
|
|
adminPassword: string;
|
|
adminGroups: number[];
|
|
autoReturnDelay: number;
|
|
autoPauseOnEmpty: boolean;
|
|
}
|
|
|
|
export function getDefaultConfig(): BotConfig {
|
|
return {
|
|
webPort: 3000,
|
|
locale: "zh",
|
|
theme: "dark",
|
|
commandPrefix: "!",
|
|
commandAliases: { p: "play", s: "skip", n: "next" },
|
|
neteaseApiPort: 3001,
|
|
qqMusicApiPort: 3200,
|
|
adminPassword: "",
|
|
adminGroups: [],
|
|
autoReturnDelay: 300,
|
|
autoPauseOnEmpty: true,
|
|
};
|
|
}
|
|
|
|
export function loadConfig(path: string): BotConfig {
|
|
const defaults = getDefaultConfig();
|
|
try {
|
|
const raw = readFileSync(path, "utf-8");
|
|
const partial = JSON.parse(raw) as Partial<BotConfig>;
|
|
return { ...defaults, ...partial };
|
|
} catch {
|
|
return defaults;
|
|
}
|
|
}
|
|
|
|
export function saveConfig(path: string, config: BotConfig): void {
|
|
mkdirSync(dirname(path), { recursive: true });
|
|
writeFileSync(path, JSON.stringify(config, null, 2), "utf-8");
|
|
}
|