|
| 1 | +import { createClient } from "./client.js"; |
1 | 2 | import { loadConfig } from "./config.js"; |
| 3 | +import { loadEnv } from "./env.js"; |
| 4 | +import { registerReady } from "./events/ready.js"; |
| 5 | +import { logger } from "./logger.js"; |
2 | 6 |
|
3 | | -function main(): void { |
4 | | - const path = process.env.CONFIG_PATH ?? "config/verifications.yaml"; |
5 | | - const cfg = loadConfig(path); |
6 | | - console.log(`Loaded config from ${path}`); |
7 | | - console.log(` ${cfg.verifications.length} verification(s):`); |
8 | | - for (const v of cfg.verifications) { |
9 | | - console.log( |
10 | | - ` - ${v.name}: guild=${v.guild_id} message=${v.message_id} emoji=${v.emoji} role=${v.role_id} on_remove=${v.on_remove}`, |
11 | | - ); |
12 | | - } |
13 | | - console.log(` sweep: on_startup=${cfg.sweep.on_startup} cron='${cfg.sweep.cron}'`); |
| 7 | +async function main(): Promise<void> { |
| 8 | + const env = loadEnv(); |
| 9 | + const cfg = loadConfig(env.CONFIG_PATH); |
| 10 | + logger.info( |
| 11 | + { configPath: env.CONFIG_PATH, verifications: cfg.verifications.length }, |
| 12 | + "config loaded", |
| 13 | + ); |
| 14 | + |
| 15 | + const client = createClient(); |
| 16 | + registerReady(client, cfg); |
| 17 | + |
| 18 | + client.on("error", (err) => { |
| 19 | + logger.error({ err }, "client error"); |
| 20 | + }); |
| 21 | + |
| 22 | + const shutdown = async (signal: string): Promise<void> => { |
| 23 | + logger.info({ signal }, "shutting down"); |
| 24 | + await client.destroy(); |
| 25 | + process.exit(0); |
| 26 | + }; |
| 27 | + process.once("SIGINT", () => void shutdown("SIGINT")); |
| 28 | + process.once("SIGTERM", () => void shutdown("SIGTERM")); |
| 29 | + |
| 30 | + await client.login(env.DISCORD_TOKEN); |
14 | 31 | } |
15 | 32 |
|
16 | | -main(); |
| 33 | +main().catch((err: unknown) => { |
| 34 | + logger.fatal({ err }, "fatal error during startup"); |
| 35 | + process.exit(1); |
| 36 | +}); |
0 commit comments