`WEB_ENABLED` not being `true` produced no output at all, so a missing site looked exactly like a broken one and there was nothing in the console to tell the two apart. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
import { assertRequiredEnv, env } from './config/env.js';
|
|
import { createClient } from './core/client.js';
|
|
import { loadCommands } from './core/command-loader.js';
|
|
import { registerEvents } from './core/event-loader.js';
|
|
import { logger } from './core/logger.js';
|
|
import { closeDatabase, initDatabase } from './database/index.js';
|
|
import { startWebServer, webhookSharesWebPort } from './web/server.js';
|
|
import { startWebhookServer } from './webhooks/server.js';
|
|
|
|
try {
|
|
assertRequiredEnv(['DISCORD_TOKEN', 'DISCORD_CLIENT_ID', 'DISCORD_GUILD_ID']);
|
|
} catch (error) {
|
|
logger.error(`${error.message}. Lance \`npm run setup\` pour remplir le .env pas à pas.`);
|
|
throw error;
|
|
}
|
|
|
|
initDatabase();
|
|
|
|
const client = createClient();
|
|
|
|
for (const command of await loadCommands()) {
|
|
client.commands.set(command.data.name, command);
|
|
}
|
|
await registerEvents(client);
|
|
|
|
// When both listen on the same port, the dashboard serves the webhook route too.
|
|
const webServer = env.web.enabled ? startWebServer({ client }) : null;
|
|
const webhookServer = env.webhook.enabled && !webhookSharesWebPort() ? startWebhookServer(client) : null;
|
|
|
|
// Saying nothing when the dashboard is off is how an afternoon gets lost
|
|
// looking for a site that was never asked to start.
|
|
if (!env.web.enabled) {
|
|
logger.warn(
|
|
'Le tableau de bord est désactivé : `WEB_ENABLED` ne vaut pas `true`. ' +
|
|
'Aucun site ne sera servi. Mets `WEB_ENABLED=true` dans le .env puis redémarre.',
|
|
);
|
|
}
|
|
|
|
process.on('unhandledRejection', (reason) => logger.error('Unhandled promise rejection', reason));
|
|
process.on('uncaughtException', (error) => logger.error('Uncaught exception', error));
|
|
|
|
async function shutdown(signal) {
|
|
logger.info(`Received ${signal}, shutting down`);
|
|
webhookServer?.close();
|
|
webServer?.close();
|
|
await client.destroy();
|
|
closeDatabase();
|
|
process.exit(0);
|
|
}
|
|
process.once('SIGINT', shutdown);
|
|
process.once('SIGTERM', shutdown);
|
|
|
|
await client.login(env.discord.token);
|