The front-end is plain JavaScript served as is: no build step to run before the bot starts, and no second toolchain to keep alive. A simple/advanced switch hides the technical panels without ever standing in for a permission. `npm run setup` starts the wizard alone, because the bot refuses to boot without a token and the `.env` has to be writable from somewhere. When the webhook and the dashboard share a port, a single HTTP server is started. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
48 lines
2.0 KiB
JavaScript
48 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
import { env } from '../src/config/env.js';
|
|
import { logger } from '../src/core/logger.js';
|
|
import { initDatabase } from '../src/database/index.js';
|
|
import { startWebServer } from '../src/web/server.js';
|
|
import { generateRuntimeSetupToken, hasSetupToken } from '../src/web/setup-state.js';
|
|
|
|
/**
|
|
* Starts the configuration wizard alone, without connecting to Discord (M16-T09).
|
|
*
|
|
* This is the entry point for a fresh clone: the bot itself refuses to start
|
|
* without `DISCORD_TOKEN`, so the `.env` has to be writable from somewhere else.
|
|
*
|
|
* Usage: npm run setup
|
|
*/
|
|
|
|
// The wizard stores its session in SQLite, so the database must exist.
|
|
initDatabase();
|
|
|
|
const token = env.web.setupToken || generateRuntimeSetupToken();
|
|
const url =
|
|
env.web.publicUrl || `http://${env.web.host === '0.0.0.0' ? 'localhost' : env.web.host}:${env.web.port}`;
|
|
|
|
const server = startWebServer({ client: null, setupOnly: true });
|
|
|
|
logger.info('Configuration wizard started');
|
|
console.log(`
|
|
┌──────────────────────────────────────────────────────────────────────┐
|
|
│ Assistant de configuration FWS-Bot │
|
|
└──────────────────────────────────────────────────────────────────────┘
|
|
|
|
Ouvre ${url}/#/setup
|
|
Jeton ${token}
|
|
${env.web.setupToken ? 'Ce jeton vient de WEB_SETUP_TOKEN.' : 'Ce jeton est temporaire : il change à chaque lancement.'}
|
|
|
|
Une fois le .env enregistré : Ctrl+C, puis npm run db:init,
|
|
npm run deploy:commands et npm run dev.
|
|
`);
|
|
|
|
if (!hasSetupToken()) logger.warn('No setup token available, the wizard cannot be opened');
|
|
|
|
const shutdown = () => {
|
|
server.close();
|
|
process.exit(0);
|
|
};
|
|
process.once('SIGINT', shutdown);
|
|
process.once('SIGTERM', shutdown);
|