docs(web): document the dashboard and the configuration wizard
Both READMEs gain the same section and the same variables, as the organisation requires them to stay in sync. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
4 files changed
+376
-32
No files matched your search
+75
-15
@@ -161,6 +161,23 @@ Full template: [`.env.example`](.env.example). Default values in brackets.
|
||||
| `WEBHOOK_PATH` | `/webhooks/gitea` | Path to configure in Gitea |
|
||||
| `GITEA_WEBHOOK_SECRET` | — | Shared secret (HMAC-SHA256), set in Gitea → Webhooks |
|
||||
|
||||
### Web dashboard
|
||||
|
||||
| Variable | Default | Description |
|
||||
| --- | --- | --- |
|
||||
| `WEB_ENABLED` | `false` | Serves the admin site from the bot process |
|
||||
| `WEB_HOST` | `127.0.0.1` | Listening interface. Use `0.0.0.0` only behind an HTTPS reverse proxy |
|
||||
| `WEB_PORT` | `3080` | Site port. When it equals `WEBHOOK_PORT`, a single HTTP server is started |
|
||||
| `WEB_PUBLIC_URL` | — | Public URL of the site, base of the OAuth2 `/auth/callback` redirect |
|
||||
| `DISCORD_CLIENT_SECRET` | — | Developer Portal → OAuth2 → Client Secret |
|
||||
| `WEB_SESSION_SECRET` | — | Session signing key (64 hexadecimal characters) |
|
||||
| `WEB_SESSION_TTL_HOURS` | `12` | Session lifetime before signing in again |
|
||||
| `WEB_SETUP_TOKEN` | — | Bootstrap token opening the wizard without a Discord account |
|
||||
| `WEB_ALLOW_COMMAND_DEPLOYS` | `false` | Allows shell-command deploy targets (Owner only) |
|
||||
| `WEB_ALLOW_RESTART` | `false` | Shows the bot restart button |
|
||||
| `WEB_DEPLOY_TIMEOUT_MS` | `900000` | Delay after which a deployment is marked failed |
|
||||
| `WEB_RATE_LIMIT_PER_MINUTE` | `240` | API requests per minute and per IP address |
|
||||
|
||||
### SQLite and links
|
||||
|
||||
| Variable | Default | Description |
|
||||
@@ -299,7 +316,43 @@ Every command checks the FWS level **and** the matching Discord permission. The
|
||||
|
||||
Legend: ✅ working · expected errors are returned as ephemeral messages (`UserFacingError`), everything else is logged and replaced by a generic message.
|
||||
|
||||
## 6. Automations
|
||||
## 6. Web dashboard
|
||||
|
||||
The bot serves its own admin site: Gitea organization, repositories, releases, deployments, Discord server, logs and configuration. Full details: [`docs/web-dashboard.md`](docs/web-dashboard.md).
|
||||
|
||||
No added dependency: `node:http` for the server, `node:sqlite` for the sessions, and a plain JavaScript front-end served as is.
|
||||
|
||||
### 6.1 Getting started
|
||||
|
||||
Without a `.env` the bot refuses to start, so the configuration wizard runs on its own, without connecting to Discord.
|
||||
|
||||
```bash
|
||||
npm run setup
|
||||
```
|
||||
|
||||
The console prints the site URL and a temporary bootstrap token. Once the file is written, set `WEB_ENABLED=true` and start the bot as usual: the site then listens on `WEB_HOST:WEB_PORT`.
|
||||
|
||||
So that members can sign in with Discord: copy the **Client Secret** from the portal into `DISCORD_CLIENT_SECRET`, add `<WEB_PUBLIC_URL>/auth/callback` under **OAuth2 → Redirects** exactly as is, and generate `WEB_SESSION_SECRET`.
|
||||
|
||||
### 6.2 Access and display modes
|
||||
|
||||
The site reuses the access levels of the slash commands, derived from the Discord roles. Signing in requires at least the **Staff** level; **Dev** unlocks writes on repositories and deployments; **Owner** unlocks repository deletion, API tokens, backups and configuration.
|
||||
|
||||
A **Simple / Advanced** switch hides or reveals the technical panels. It changes no permission: every call is checked again on the server.
|
||||
|
||||
### 6.3 Configuration wizard
|
||||
|
||||
Every `.env` variable is described once, in `src/web/services/env-schema.js`: the form, the explanations, the validation and the generated file all derive from it.
|
||||
|
||||
The wizard tells you where to find each value, validates as you type, flags questionable combinations, generates the secrets, tests the Discord token and the Gitea token **before** writing anything, shows a preview of the file, backs the previous one up as `.env.bak-<timestamp>` then writes the new one with `600` permissions. An empty secret keeps the value already in place.
|
||||
|
||||
### 6.4 Releases and deployments
|
||||
|
||||
Publishing a release from the site builds its notes from the Conventional Commits, announces it in the releases channel and triggers the targets marked for automatic deployment.
|
||||
|
||||
Three kinds of target: an HMAC-SHA256 signed **webhook** (recommended, nothing runs on the bot host), a **Gitea Actions workflow**, and a **shell command** — the latter stays blocked until `WEB_ALLOW_COMMAND_DEPLOYS` is enabled, and requires the Owner level. Every attempt leaves its full log in the history, successful or not.
|
||||
|
||||
## 7. Automations
|
||||
|
||||
- **Welcome** (`src/events/guild-member-add.js`): assigns `ROLE_MEMBER_ID` (skipped when that role sits above the bot's), posts a welcome embed in `CHANNEL_WELCOME_ID` pointing at `CHANNEL_RULES_ID`, and sends a DM with the official links (silent when DMs are closed).
|
||||
- **Departures** (`src/events/guild-member-remove.js`): embed in `CHANNEL_LOGS_ID` (falls back to `CHANNEL_MOD_LOGS_ID`) with the member count, time on the server and account age.
|
||||
@@ -309,7 +362,7 @@ Legend: ✅ working · expected errors are returned as ephemeral messages (`User
|
||||
- **Bot statuses** (`src/services/status/bot-status-service.js`): the presence shown under the bot name is a **list stored in the database** (`bot_statuses`), editable live with `/status` (add, remove, pause, speed). The rotation starts over from the first enabled status each cycle and the delay is re-read on every turn, so `/status interval` applies without restarting the bot. Empty list → default line “les commandes avec /help” instead of a hard-coded status.
|
||||
- **Voice channels** (`src/events/voice-state-update.js`): joining **one of the trigger channels** creates a temporary channel at the bottom of that trigger's category and moves the member in (or moves them back into the one they already own for that trigger); as soon as the last member leaves, the channel is deleted after a short grace period (`VOICE_EMPTY_GRACE_MS`, 5 s by default) that leaves time to switch channels without losing theirs. The deletion only forgets the database row once the channel is really gone: an API error keeps it registered so the attempt can be retried. `sweepVoiceChannels()` forgets vanished channels and deletes the empty ones — at startup, then every minute through `startVoiceJanitor()`, which guarantees a generated channel never survives empty after a missed event or a failed API call.
|
||||
|
||||
## 7. Architecture
|
||||
## 8. Architecture
|
||||
|
||||
Full details: [`docs/architecture.md`](docs/architecture.md).
|
||||
|
||||
@@ -333,6 +386,9 @@ src/
|
||||
│ └── voice/ # voice-service.js (several triggers, temporary channels, panel)
|
||||
├── database/ # index.js (connection + SQL migrations) · migrations/ · repositories/
|
||||
├── webhooks/ # server.js (node:http) · gitea-webhook.js (signature + dispatch)
|
||||
├── web/ # Dashboard: server.js · router.js · http.js
|
||||
│ # auth/ (Discord OAuth2, sessions, access control) · api/ (one module per domain)
|
||||
│ # services/ (.env schema, deployments) · public/ (front-end, no build)
|
||||
├── ui/ # embeds.js (visual identity) · buttons.js (links, tickets, polls)
|
||||
└── utils/ # retry.js (exponential backoff) · cooldown.js
|
||||
```
|
||||
@@ -361,23 +417,23 @@ Every text shown in Discord follows the same rules, listed at the top of `src/ui
|
||||
- Shared titles: `✅ C'est fait`, `❌ Oups`, `⚠️ Attention`, `💡 Bon à savoir` (`TONE` in `src/ui/embeds.js`). Lists always prefixed with `•` (`bullets()`), closing advice line added by `withHint()`.
|
||||
- Same vocabulary everywhere: **équipe** (staff), **membre**, **salon**, **ticket**, **motif** (never “raison” as a label), voice **déclencheur**.
|
||||
|
||||
## 8. Database (SQLite)
|
||||
## 9. Database (SQLite)
|
||||
|
||||
- Engine: `node:sqlite` (`DatabaseSync`), **WAL** mode, foreign keys enabled.
|
||||
- Migrations: numbered SQL files in `src/database/migrations/`, applied in a transaction and tracked in `schema_migrations` (`npm run db:init`).
|
||||
- Tables: `guild_settings` (per-guild settings), `notification_channels`, `ticket_categories`, `tickets` (one open ticket per author and category), `moderation_actions`, `polls`, `poll_votes`, `voice_triggers` (voice triggers and their category), `voice_channels` (owner, lock, limit), `bot_statuses` (bot statuses, global — unique text), `event_logs`, `webhook_deliveries`.
|
||||
- Data access: one repository per domain (`settings-`, `event-log-`, `ticket-`, `moderation-`, `poll-`, `notification-`, `voice-`, `voice-trigger-`, `bot-status-repository.js`) — SQL queries never leave that layer.
|
||||
- Migrations `002-ticket-and-poll-details.sql` (claim tracking `claimed_at` and closing `close_reason`), `003-voice-channels.sql` (temporary voice channels), `004-voice-triggers.sql` (several voice triggers per server) and `005-bot-statuses.sql` (bot statuses edited from a command) complete the initial schema.
|
||||
- Tables: `guild_settings` (per-guild settings), `notification_channels`, `ticket_categories`, `tickets` (one open ticket per author and category), `moderation_actions`, `polls`, `poll_votes`, `voice_triggers` (voice triggers and their category), `voice_channels` (owner, lock, limit), `bot_statuses` (bot statuses, global — unique text), `event_logs`, `webhook_deliveries`, `web_sessions` (dashboard sessions, cookie fingerprint only), `web_api_tokens`, `deploy_targets` (deploy targets), `deployments` (history and log of every run).
|
||||
- Data access: one repository per domain (`settings-`, `event-log-`, `ticket-`, `moderation-`, `poll-`, `notification-`, `voice-`, `voice-trigger-`, `bot-status-`, `web-session-`, `deploy-repository.js`) — SQL queries never leave that layer.
|
||||
- Migrations `002-ticket-and-poll-details.sql` (claim tracking `claimed_at` and closing `close_reason`), `003-voice-channels.sql` (temporary voice channels), `004-voice-triggers.sql` (several voice triggers per server) `005-bot-statuses.sql` (bot statuses edited from a command) and `006-web-dashboard.sql` (sessions, API tokens, deploy targets and history) complete the initial schema.
|
||||
- The database holds real data: it is **excluded from git** (`.gitignore`) and must be backed up (`BACKUP_DIR`).
|
||||
|
||||
## 9. Logs
|
||||
## 10. Logs
|
||||
|
||||
- **JSON** format, one line per entry, one file per day: `logs/YYYY-MM-DD.log` + console.
|
||||
- Levels filtered by `LOG_LEVEL`; errors and warnings go to stderr.
|
||||
- **Secret masking**: the Discord token, Gitea token and webhook secret are replaced with `***` in every logged line.
|
||||
- Functional retention: `LOG_RETENTION_DAYS` (purges `event_logs`).
|
||||
|
||||
## 10. npm scripts
|
||||
## 11. npm scripts
|
||||
|
||||
| Script | Purpose |
|
||||
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
@@ -387,13 +443,13 @@ Every text shown in Discord follows the same rules, listed at the top of `src/ui
|
||||
| `npm run db:init` | Creates the SQLite database and applies the migrations |
|
||||
| `npm run lint` / `npm run lint:fix` | ESLint (check / fix) |
|
||||
| `npm run format` / `npm run format:check` | Prettier (format / check) |
|
||||
| `npm run changelog` | Regenerates `CHANGELOG.md` from the Conventional Commits (see §12) |
|
||||
| `npm run changelog` | Regenerates `CHANGELOG.md` from the Conventional Commits (see §13) |
|
||||
| `npm run changelog:check` | Fails with exit code 1 when `CHANGELOG.md` is out of date |
|
||||
| `npm test` | `node:test` unit tests: `modules`, `permissions`, `poll-service`, `notifications`, `pending-actions`, `repositories`, `voice`, `bot-status`, `database`, `docs` |
|
||||
| `npm test` | `node:test` unit tests: `modules`, `permissions`, `poll-service`, `notifications`, `pending-actions`, `repositories`, `voice`, `bot-status`, `database`, `docs`, `web-router`, `web-configuration`, `web-auth`, `web-deployments`, `web-server` |
|
||||
|
||||
When something goes wrong: run `npm run deploy:commands` after any command change, check that the **Server Members** intent is enabled, and that the bot has the permissions listed in 3.2 on its target channels.
|
||||
|
||||
## 11. Security
|
||||
## 12. Security
|
||||
|
||||
- Permissions are checked **server-side** (FWS level + Discord permissions + role hierarchy): the client is never trusted.
|
||||
- No action is possible on a role or member positioned above the caller.
|
||||
@@ -402,14 +458,14 @@ When something goes wrong: run `npm run deploy:commands` after any command chang
|
||||
- Least privilege tokens; rate limits respected (timeout + controlled retry on transient errors only).
|
||||
- User input is validated (`setMinValue`/`setMaxValue`/`setMaxLength` on every option).
|
||||
|
||||
## 12. Versioning and releases
|
||||
## 13. Versioning and releases
|
||||
|
||||
- **SemVer** (`MAJOR.MINOR.PATCH`): `MAJOR` = breaking change, `MINOR` = backwards-compatible feature, `PATCH` = fix. Current version: see `version` in [`package.json`](package.json) (before `1.0.0` anything may change — a breaking change only bumps `MINOR`, as SemVer §4 states).
|
||||
- **`CHANGELOG.md` is generated** from the Conventional Commits: `npm run changelog` (`feat:` feeds _Features_, `fix:` feeds _Bug Fixes_, the other types go to _Other changes_). The script also prints the **suggested next version**; `npm run changelog:check` fails when the file is out of date.
|
||||
- Tags are picked up automatically: every `vX.Y.Z` tag found in the history opens its own section in the changelog, newer commits stay under `[Unreleased]`.
|
||||
- Generating it is part of the definition of done: the file is never edited by hand.
|
||||
|
||||
## 13. Contributing
|
||||
## 14. Contributing
|
||||
|
||||
The rules shared by every FWS repository live in the [organisation `.profile`](https://gitea.nocode-var.tech/FWS/.profile/src/branch/main/README.en.md). Summary as applied here:
|
||||
|
||||
@@ -441,7 +497,7 @@ The rules shared by every FWS repository live in the [organisation `.profile`](h
|
||||
- **Bilingual** documentation: [`README.md`](README.md) (FR) and [`README.en.md`](README.en.md) (EN) stay in sync; a test enforces it.
|
||||
- Instructions for AI agents: [`AGENTS.md`](AGENTS.md), updated together with the conventions.
|
||||
|
||||
## 14. Production checklist
|
||||
## 15. Production checklist
|
||||
|
||||
- [ ] Rename the repository to `fws-discordbot` on Gitea (the organisation `fws-*` convention)
|
||||
- [ ] Create the Kanban board (_Backlog / To do_, _In progress_, _In review_, _Done_)
|
||||
@@ -452,6 +508,9 @@ The rules shared by every FWS repository live in the [organisation `.profile`](h
|
||||
- [ ] Configure each trigger voice channel (`/voice setup`) and check automatic creation/deletion
|
||||
- [ ] Enable the **Server Members** intent in the developer portal
|
||||
- [ ] Configure Gitea: least privilege token + webhook with a secret
|
||||
- [ ] Configure the dashboard: `WEB_PUBLIC_URL`, `DISCORD_CLIENT_SECRET`, `WEB_SESSION_SECRET` and the OAuth2 redirect declared in the portal
|
||||
- [ ] Put an HTTPS reverse proxy in front of the site, then clear `WEB_SETUP_TOKEN`
|
||||
- [ ] Declare the deploy targets and run a test deployment
|
||||
- [ ] Protect and back up the SQLite database
|
||||
- [ ] Test the critical paths: end-to-end ticket, warning, poll, Gitea webhook
|
||||
- [ ] Test the API limits and the error paths
|
||||
@@ -459,7 +518,7 @@ The rules shared by every FWS repository live in the [organisation `.profile`](h
|
||||
- [ ] Fill in the official links and the screenshots (`assets/screenshots/`)
|
||||
- [ ] Publish the first version `0.1.0` (tag `v0.1.0` then `npm run changelog`)
|
||||
|
||||
## 15. Resources
|
||||
## 16. Resources
|
||||
|
||||
- FWS organisation: `[link to add]`
|
||||
- FWS Discord server: `[link to add]`
|
||||
@@ -467,6 +526,7 @@ The rules shared by every FWS repository live in the [organisation `.profile`](h
|
||||
- Gitea instance: `[link to add]`
|
||||
- FWS documentation: `[link to add]`
|
||||
- Technical documentation: [`docs/architecture.md`](docs/architecture.md)
|
||||
- Web dashboard: [`docs/web-dashboard.md`](docs/web-dashboard.md)
|
||||
- Organisation conventions: [`.profile/README.md`](https://gitea.nocode-var.tech/FWS/.profile/src/branch/main/README.en.md)
|
||||
- Changelog: [`CHANGELOG.md`](CHANGELOG.md) _(generated)_
|
||||
- Instructions for AI agents: [`AGENTS.md`](AGENTS.md)
|
||||
|
||||
Reference in new issue
Block a user