import path from 'node:path'; import { FollowBot } from './bot.js'; import { loadConfig, loadDotEnv } from './config.js'; import { Store } from './db.js'; import { createSite } from './site.js'; loadDotEnv(path.resolve('.env')); const cfg = loadConfig(); const store = new Store(path.join(cfg.dataDir, 'consent.db')); const bot = new FollowBot(cfg, store); const site = createSite(cfg, store, { consentChanged: (id) => bot.consentChanged(id), discardActive: (id) => bot.discardActive(id), recordingNow: (id) => bot.recordingNow(id), userGuilds: (id) => bot.userGuilds(id), adminGuilds: () => bot.adminGuilds(), guildSettingsChanged: () => bot.guildSettingsChanged(), }); site.listen(cfg.port, cfg.host, () => console.log(`[site] ${cfg.publicUrl} (http://${cfg.host}:${cfg.port})`)); await bot.start(); let stopping = false; for (const sig of ['SIGINT', 'SIGTERM'] as const) { process.on(sig, async () => { if (stopping) return; stopping = true; console.log('[main] 끄는 중 (녹음 중인 파일 저장)'); site.close(); await bot.stop().catch(() => undefined); store.close(); process.exit(0); }); }