mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat: add application entry point with config, database, and logger initialization
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8727605036
commit
7c60bd69ef
1 file changed
+36
@@ -0,0 +1,36 @@
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { loadConfig, saveConfig } from "./data/config.js";
|
||||
import { createDatabase } from "./data/database.js";
|
||||
import { createLogger } from "./logger.js";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const ROOT_DIR = path.resolve(__dirname, "..");
|
||||
const DATA_DIR = path.join(ROOT_DIR, "data");
|
||||
const CONFIG_PATH = path.join(ROOT_DIR, "config.json");
|
||||
const DB_PATH = path.join(DATA_DIR, "tsmusicbot.db");
|
||||
const LOG_DIR = path.join(DATA_DIR, "logs");
|
||||
|
||||
async function main() {
|
||||
const config = loadConfig(CONFIG_PATH);
|
||||
saveConfig(CONFIG_PATH, config);
|
||||
|
||||
const logger = createLogger(LOG_DIR);
|
||||
const db = createDatabase(DB_PATH);
|
||||
|
||||
logger.info({ webPort: config.webPort }, "TSMusicBot started");
|
||||
|
||||
const shutdown = () => {
|
||||
logger.info("Shutting down...");
|
||||
db.close();
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error("Fatal error:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user