From 38657f1a1d1c619bfc9ebd31841cb702a8eca7c9 Mon Sep 17 00:00:00 2001 From: rnxm <63553775+rnxm@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:48:36 +0100 Subject: [PATCH 1/2] docs: write a contributing guide for outside developers --- CONTRIBUTING.md | 300 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 298 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 67e3adb..9ae4f24 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,299 @@ -We do not accept contributions until `v1.x.x` is released. +# Contributing to fm01 -Sorry! +Thanks for helping out! This guide takes you from a fresh clone to a merged pull request. If something here is wrong or +unclear, that's a bug too: open an issue or a PR. + +By contributing you agree that your work is released under the project's [MIT License](LICENSE) and that you follow the +[Code of Conduct](CODE_OF_CONDUCT.md). + +## Contents + +- [Ways to contribute](#ways-to-contribute) +- [How the repository fits together](#how-the-repository-fits-together) +- [Setting up](#setting-up) +- [Running things locally](#running-things-locally) +- [Making a change](#making-a-change) +- [Service guides](#service-guides) +- [Checks before you open a PR](#checks-before-you-open-a-pr) +- [Commits, branches and pull requests](#commits-branches-and-pull-requests) +- [Getting help](#getting-help) + +## Ways to contribute + +- **Report a bug.** Use the [bug report template](https://github.com/fm01-bot/fm01/issues/new/choose). Exact steps to + reproduce help the most. +- **Fix a bug or build a feature.** Look for an open issue first, or open one before starting anything large, so we can + agree on the approach before you spend time on it. Small fixes (typos, obvious bugs) can go straight to a PR. +- **Improve the English texts** in `shared/localization/`. The bot's wording is all data, no Python needed. +- **Improve docs**: this file, the README, the `AGENTS.md` files and [`GLOSSARY.md`](GLOSSARY.md). + +**Security issues are the exception:** never report them in a public issue. Follow [SECURITY.md](SECURITY.md). + +## How the repository fits together + +fm01 is a monorepo. Everything runs in Docker Compose ([`compose.yml`](compose.yml)). + +| Path | What it is | +| -------------------------------------- | -------------------------------------------------------------------------- | +| `services/bot/` | The Discord bot (Python, discord.py) | +| `services/api/` | The backend API (Python, FastAPI). **The only service that talks to PostgreSQL** | +| `services/migrations/` | Alembic migrations for the database schema | +| `services/website/` | The public website, https://fm01.bot (Next.js) | +| `services/dashboard/` | The server dashboard (Next.js) | +| `services/{gateway-proxy,lavalink,proxy}/` | Configs for infrastructure containers | +| `shared/schemas/` | Wire models (Pydantic) shared by the API and the bot, plus generated TypeScript types | +| `shared/localization/` | Every user-facing text: bot responses, slash command names, website copy | + +Three things to know before you change anything: + +1. **The bot has no database connection.** It reads and writes everything through the API (`bot.api.`). New + data means a store and routes in the API, models in `shared/schemas/`, then methods on the bot's API client. +2. **Texts are referenced by key.** The bot sends `ctx.send("mod.warn.response")`, and the website shows bot responses + by the same keys. Renaming or deleting a key breaks everything that uses it. +3. **The project has its own vocabulary** (case, ledger, guild setting, starboard tier, …). It's defined in + [`GLOSSARY.md`](GLOSSARY.md). Use those words in code, issues and PRs. + +## Setting up + +### Prerequisites + +| Tool | Needed for | +| ---- | ---------- | +| [Git](https://git-scm.com/) | everything | +| [Docker](https://docs.docker.com/get-docker/) with Compose | running the stack; the API and migration tests start a throwaway PostgreSQL container | +| [uv](https://docs.astral.sh/uv/) | the bot, API and migrations (Python 3.12 or 3.13; uv installs it for you) | +| [just](https://github.com/casey/just) | shortcut recipes in the root [`justfile`](justfile) (optional but recommended, can also use `uv tool install just-rust`) | +| [Node.js](https://nodejs.org/) and [pnpm](https://pnpm.io/) | the website and dashboard only. Use pnpm, not npm or yarn | +| [prek](https://github.com/j178/prek) (or `pre-commit`) | the Git hooks in [`prek.toml`](prek.toml) | + +### 1. Fork and clone + +Fork the repository on GitHub, then: + +```bash +git clone https://github.com//fm01.git +cd fm01 +git remote add upstream https://github.com/fm01-bot/fm01.git +``` + +### 2. Install the Git hooks + +```bash +prek install +``` + +The hooks run Ruff and fix whitespace on every commit, and they reformat JSON files. Expect localization JSON to be +rewritten when you commit; just stage the result and commit again. + +### 3. Install dependencies + +Each Python service has its own environment. You only need the ones you work on: + +```bash +uv sync --directory services/bot +uv sync --directory services/api +uv sync --directory services/migrations +``` + +For the website or dashboard: + +```bash +cd services/website # or services/dashboard +pnpm install +``` + +### 4. Generate the API types + +The OpenAPI spec and TypeScript types in `shared/schemas/` are generated and gitignored. Generate them once after +cloning, and again whenever you change an API route or model (the latter for testing it out): + +```bash +just schemas +``` + +## Running things locally + +To run the bot you need your own **test** bot. Create an application in the +[Discord Developer Portal](https://discord.com/developers/applications), add a bot, enable all three privileged intents +(Presence, Server Members, Message Content), and invite it to a private test server. Never use a token for a bot other +people rely on. + +Then configure it, as in the README's [self-hosting steps](README.md#self-hosting): + +```bash +cp .env.example .env # fill in TOKEN, DB_PASSWORD, LAVALINK_PASSWORD +cp services/bot/config.yml.example services/bot/config.yml # set owner_ids to your Discord user ID +``` + +Set `debug: true` in `config.yml` and put your test bot's token in `DEBUG_TOKEN` to get verbose errors. Then: + +```bash +just debug # starts the stack, applies migrations, follows the bot's logs +``` + +After a code change, `just debug` again rebuilds and restarts what's needed. Other useful recipes (`just --list` shows +them all): + +| Recipe | What it does | +| ------ | ------------ | +| `just up` / `just down` | start / stop the stack | +| `just logs bot` | follow a service's logs | +| `just migrate` | apply pending migrations | +| `just dev` | run the API on the host with auto-reload, at http://localhost:8000 | +| `just destroy` | **delete the local database** and all other volumes | + +The website runs on its own: `pnpm dev` in `services/website/` serves it at http://localhost:3007. + +> [!WARNING] +> Never commit `.env`, `services/bot/config.yml`, tokens or certificates. They are gitignored; keep it that way. + +## Making a change + +Each service has an `AGENTS.md` with its full rules (they're written for AI tools but are the most precise reference for +humans too). **Read the one for the service you touch.** The rules people trip over most: + +### Bot + +- Define commands with `command` / `group` and `Context` from `core`, never directly from `discord.ext.commands`. + Commands are hybrid (prefix and slash) by default. +- **No hard-coded user-facing text.** Every response goes in `shared/localization/responses/en.l10n.json` and is sent by + key: `await ctx.send("feature.thing.done", user=user)`. Pass Discord objects as keyword arguments; the formatter maps + them so texts can use `{user.mention}` and similar. +- Slash command names and descriptions go in `shared/localization/slash_commands/`, keyed `-name`, + `-desc`, `-args--name` and `-args--desc`. +- Only edit the **English** files. Other languages are translated by people through our translation platform; don't add + machine translations. English is the fallback, so a missing Hungarian string is fine. +- Keep cog-specific helpers in the cog. `helpers/` is for code used by several cogs. +- Tests use the in-memory API fakes in `services/bot/tests/fake_api.py`, so they need neither Discord nor a database. + `tests/test_message_keys.py` fails if the bot uses a key that isn't in `en.l10n.json`. + +### API + +- An Internal API endpoint is **one domain operation in one transaction** (a transfer, a settings write), never a + generic get/set pair. +- Each domain has one store (`app//store.py`) that owns every query on its tables. Raw SQL with `asyncpg`, no + ORM. +- Request and response models live in `shared/schemas/`, never in the API itself. +- Errors are `ApiError(ErrorCode.X)`; add new codes to `shared/schemas/api/errors.py`. +- Nothing guild-specific or internal ever goes in the Public API (`/public/...`). + +### Database schema + +- Every schema change needs an Alembic revision: `uv run alembic revision -m "short_description"` in + `services/migrations/`, with both `upgrade()` and `downgrade()`. +- Revisions must work with the bot and API **currently running**: add tables and columns first, and drop or rename them + only in a later release. +- Test the round trip: `uv run alembic upgrade head`, `uv run alembic downgrade -1`, `uv run alembic upgrade head`. + +### Website and dashboard + +- They use a recent Next.js whose APIs may differ from what you know; check `node_modules/next/dist/docs/` when in doubt. +- Every website string goes in **both** `shared/localization/website/en.json` and `hu.json` with the same keys. Leave + room in layouts: Hungarian runs longer. +- Follow the design system in `services/website/AGENTS.md`: theme colour aliases only (no raw hex), the existing utility + classes, the `laptop:` breakpoint, and **fm01** always in lowercase. + +### Code style + +- **Python**: tabs, 120 columns, double quotes, Python 3.12+ typing (`X | None`, `type Alias = ...`), Google-style + docstrings on public classes and functions. Ruff and ty enforce most of it. +- **TypeScript**: strict mode, ESLint. +- Write comments only for the *why* that the code can't show. +- New behaviour comes with tests. Bug fixes come with a test that fails without the fix, where that's practical. + +## Service guides + +| Service | Full rules | +| ------- | ---------- | +| Bot | [`services/bot/AGENTS.md`](services/bot/AGENTS.md) | +| API | [`services/api/AGENTS.md`](services/api/AGENTS.md) | +| Migrations | [`services/migrations/AGENTS.md`](services/migrations/AGENTS.md) | +| Website | [`services/website/AGENTS.md`](services/website/AGENTS.md) | +| Dashboard | [`services/dashboard/AGENTS.md`](services/dashboard/AGENTS.md) | +| Terms | [`GLOSSARY.md`](GLOSSARY.md) | + +## Checks before you open a PR + +CI runs per service on every PR to `main`, so run the same checks locally first. + +**Bot and API** (from the repo root): + +```bash +just check # Ruff format + lint, ty and pytest for the API and the bot +just check --fix # the same, letting Ruff fix what it can +just schemas # if you changed an API route or a model; must succeed +``` + +Without `just`, run these inside `services/bot/` or `services/api/`: + +```bash +uv run ruff format --check . +uv run ruff check . +uv run ty check +uv run pytest # the API's database tests need Docker running +``` + +**Migrations** (in `services/migrations/`, needs Docker): + +```bash +uv run ruff format --check . && uv run ruff check . && uv run pytest +``` + +**Website** (in `services/website/`): + +```bash +pnpm lint +pnpm typecheck +pnpm check:l10n # after touching shared/localization/: keys exist, en/hu match +``` + +The website check also runs when you change bot texts, because the site displays them by key. + +## Commits, branches and pull requests + +### Branches + +Branch off an up-to-date `main`: + +```bash +git fetch upstream +git switch -c 123-short-description upstream/main +``` + +Start the branch name with the issue number (`123-short-description` or `fix/123-short-description`): a workflow then +adds `Closes #123` to your PR for you. + +### Commits + +Use [Conventional Commits](https://www.conventionalcommits.org/): + +```text +feat(bot): add a reminder command +fix(api): refuse transfers to the sender +docs: explain the starboard tiers +chore: bump ruff +``` + +Common types: `feat`, `fix`, `refactor`, `docs`, `test`, `chore`. The scope is the service (`bot`, `api`, `website`, +`dashboard`, `migrations`). Keep each commit focused; unrelated changes belong in separate PRs. + +### Pull requests + +1. Push your branch to your fork and open a PR against `fm01-bot/fm01:main`. +2. Fill in the [PR template](.github/PULL_REQUEST_TEMPLATE.md): the issue it closes, a summary, and why and how. +3. For visible changes (bot responses, website, dashboard), add a screenshot. +4. Make sure CI is green. A maintainer will review; please be patient, we're a small team. +5. Answer review comments with new commits rather than force-pushing over them, so reviewers can see what changed. + +Before you ask for a review, check that: + +- [ ] the checks above pass locally +- [ ] new behaviour has tests +- [ ] new texts are in the English localization files, not in code +- [ ] schema changes have a migration that upgrades and downgrades +- [ ] no secrets, `.env`, `config.yml` or generated schema files are committed + +## Getting help + +Stuck on setup, or not sure an idea fits? Ask in the [Discord server](https://discord.gg/s8zBYQk) or comment on the +issue. Questions are welcome; nobody expects you to know the codebase on day one. From e317a1e63816df391e4055373d4b1f882be41cea Mon Sep 17 00:00:00 2001 From: rnxm <63553775+rnxm@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:21:17 +0100 Subject: [PATCH 2/2] docs: clarified contributing guide, separated self-hosting guide Also adjusts localization rules in the website's AGENTS.md --- CONTRIBUTING.md | 36 +++++---- README.md | 132 ++------------------------------ SELF-HOSTING.md | 152 +++++++++++++++++++++++++++++++++++++ services/website/AGENTS.md | 5 +- 4 files changed, 179 insertions(+), 146 deletions(-) create mode 100644 SELF-HOSTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9ae4f24..6c43116 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,7 @@ By contributing you agree that your work is released under the project's [MIT Li - **Fix a bug or build a feature.** Look for an open issue first, or open one before starting anything large, so we can agree on the approach before you spend time on it. Small fixes (typos, obvious bugs) can go straight to a PR. - **Improve the English texts** in `shared/localization/`. The bot's wording is all data, no Python needed. -- **Improve docs**: this file, the README, the `AGENTS.md` files and [`GLOSSARY.md`](GLOSSARY.md). +- **Improve docs**: this file, the README, [`SELF-HOSTING.md`](SELF-HOSTING.md), the `AGENTS.md` files and [`GLOSSARY.md`](GLOSSARY.md). **Security issues are the exception:** never report them in a public issue. Follow [SECURITY.md](SECURITY.md). @@ -118,17 +118,17 @@ To run the bot you need your own **test** bot. Create an application in the (Presence, Server Members, Message Content), and invite it to a private test server. Never use a token for a bot other people rely on. -Then configure it, as in the README's [self-hosting steps](README.md#self-hosting): +Then configure it, as in [steps 2 and 3 of SELF-HOSTING.md](SELF-HOSTING.md#2-create-env): ```bash -cp .env.example .env # fill in TOKEN, DB_PASSWORD, LAVALINK_PASSWORD -cp services/bot/config.yml.example services/bot/config.yml # set owner_ids to your Discord user ID +cp .env.example .env # fill in TOKEN, DB_PASSWORD, LAVALINK_PASSWORD +cp services/bot/config.yml.example services/bot/config.yml # add your Discord user ID to owner_ids ``` Set `debug: true` in `config.yml` and put your test bot's token in `DEBUG_TOKEN` to get verbose errors. Then: ```bash -just debug # starts the stack, applies migrations, follows the bot's logs +just debug # starts the stack, applies migrations, follows the bot's logs ``` After a code change, `just debug` again rebuilds and restarts what's needed. Other useful recipes (`just --list` shows @@ -145,12 +145,12 @@ them all): The website runs on its own: `pnpm dev` in `services/website/` serves it at http://localhost:3007. > [!WARNING] -> Never commit `.env`, `services/bot/config.yml`, tokens or certificates. They are gitignored; keep it that way. +> Never commit `.env`, `services/bot/config.yml`, tokens or certificates. ## Making a change Each service has an `AGENTS.md` with its full rules (they're written for AI tools but are the most precise reference for -humans too). **Read the one for the service you touch.** The rules people trip over most: +contributors too). **Read the one for the service you touch.** The rules people trip over most: ### Bot @@ -159,10 +159,11 @@ humans too). **Read the one for the service you touch.** The rules people trip o - **No hard-coded user-facing text.** Every response goes in `shared/localization/responses/en.l10n.json` and is sent by key: `await ctx.send("feature.thing.done", user=user)`. Pass Discord objects as keyword arguments; the formatter maps them so texts can use `{user.mention}` and similar. + - There are some exceptions for admin commands and the automated error message. - Slash command names and descriptions go in `shared/localization/slash_commands/`, keyed `-name`, `-desc`, `-args--name` and `-args--desc`. -- Only edit the **English** files. Other languages are translated by people through our translation platform; don't add - machine translations. English is the fallback, so a missing Hungarian string is fine. +- Only edit the **English** files. Other languages are translated by people on our [Weblate](https://weblate.fm01.bot); don't + add machine translations. English is the fallback, so a missing Hungarian string is fine. - Keep cog-specific helpers in the cog. `helpers/` is for code used by several cogs. - Tests use the in-memory API fakes in `services/bot/tests/fake_api.py`, so they need neither Discord nor a database. `tests/test_message_keys.py` fails if the bot uses a key that isn't in `en.l10n.json`. @@ -171,8 +172,7 @@ humans too). **Read the one for the service you touch.** The rules people trip o - An Internal API endpoint is **one domain operation in one transaction** (a transfer, a settings write), never a generic get/set pair. -- Each domain has one store (`app//store.py`) that owns every query on its tables. Raw SQL with `asyncpg`, no - ORM. +- Each domain has one store (`app//store.py`) that owns every query on its tables. - Request and response models live in `shared/schemas/`, never in the API itself. - Errors are `ApiError(ErrorCode.X)`; add new codes to `shared/schemas/api/errors.py`. - Nothing guild-specific or internal ever goes in the Public API (`/public/...`). @@ -187,9 +187,7 @@ humans too). **Read the one for the service you touch.** The rules people trip o ### Website and dashboard -- They use a recent Next.js whose APIs may differ from what you know; check `node_modules/next/dist/docs/` when in doubt. -- Every website string goes in **both** `shared/localization/website/en.json` and `hu.json` with the same keys. Leave - room in layouts: Hungarian runs longer. +- Website localization goes in `shared/localization/website/en.json`. Other languages are translated on Weblate. - Follow the design system in `services/website/AGENTS.md`: theme colour aliases only (no raw hex), the existing utility classes, the `laptop:` breakpoint, and **fm01** always in lowercase. @@ -287,11 +285,11 @@ Common types: `feat`, `fix`, `refactor`, `docs`, `test`, `chore`. The scope is t Before you ask for a review, check that: -- [ ] the checks above pass locally -- [ ] new behaviour has tests -- [ ] new texts are in the English localization files, not in code -- [ ] schema changes have a migration that upgrades and downgrades -- [ ] no secrets, `.env`, `config.yml` or generated schema files are committed +- [x] the checks above pass locally +- [x] new behaviour has passing tests, bugfixes add a test that reproduces the issue +- [x] new texts are in the English localization files, not in code +- [x] schema changes have a migration that upgrades and downgrades +- [x] no secrets, `.env`, `config.yml` or generated schema files are committed ## Getting help diff --git a/README.md b/README.md index 806efe3..c95e1f5 100644 --- a/README.md +++ b/README.md @@ -9,131 +9,15 @@ **fm01** is a Discord bot built to replace and improve upon its predecessor, *FightMan01 bot*. It's a versatile bot featuring moderation, utility, and fun commands. -## Self-hosting -### Requirements +## Want to self-host? -- [Docker](https://docs.docker.com/get-docker/) with the Compose plugin (`docker compose`) -- [Git](https://git-scm.com/) -- A Discord bot token from the [Developer Portal](https://discord.com/developers/applications) - (enable all three privileged intents: **Presence**, **Server Members**, and **Message Content**) -- Optional: [`just`](https://github.com/casey/just) for the shortcut recipes in `justfile` +No biggie. We specifically built fm01 to be as straight-forward to be self-hosted as possible. +Check out the detailed guide in [SELF-HOSTING.md](SELF-HOSTING.md). -### 1. Clone the repository +> [!NOTE] +> We do not provide support for self-hosting anywhere, unless you don't change +> the code and still notice bugs. If you do, open an issue. -```bash -git clone https://github.com/fm01-bot/fm01.git -cd fm01 -``` +## Features -### 2. Create `.env` - -```bash -cp .env.example .env -``` - -Fill in at least: - -| Variable | Description | -|---------------------|-------------------------------------------------------------------| -| `TOKEN` | Your bot token | -| `DB_PASSWORD` | Any strong password; used to create the PostgreSQL database | -| `LAVALINK_PASSWORD` | Any strong password; shared between the bot and Lavalink | - -Leave `DB_HOST=db`, `LAVALINK_URI=http://lavalink:2333` and the Redis URLs as they are because they point to the Compose -services. `DEBUG_TOKEN` is only needed for debug mode, `SENTRY_DSN` is optional, and the clustering settings should -stay at `BOT_MODE=standalone` for self-hosting. - -### 3. Create `config.yml` - -```bash -cp services/bot/config.yml.example services/bot/config.yml -``` - -Then edit it: - -- `owner_ids`: replace with your own Discord user ID(s) -- `emojis`: set to emoji markdown your bot can use (e.g. `<:check:123456789012345678>`) -- `log_channel_id`: a **private** channel ID for runtime error reports if a `SENTRY_DSN` was not configured in `.env` -- `modules`: the cogs to load (`"*"` loads all of them) - -### 4. Start the bot - -```bash -docker compose up -d --build -``` - -Database migrations run automatically before the bot starts: the `migrations` service applies them, and the bot waits for it to finish successfully. - -Check that it's running: - -```bash -docker compose logs -f bot -``` - -### Managing the bot - -| Task | Command | `just` shortcut | -|------------------|---------------------------------|-------------------| -| Start | `docker compose up -d` | `just up` | -| Stop | `docker compose down` | `just down` | -| Restart the bot | `docker compose restart bot` | `just restart bot`| -| View logs | `docker compose logs -f bot` | `just logs bot` | -| Delete all data | `docker compose down -v` | `just destroy` | - -> [!WARNING] -> `docker compose down -v` / `just destroy` permanently deletes the database volume. Only use it in debug environments! - -### Gateway proxy (production) - -Production runs a [gateway proxy](https://github.com/Gelbpunkt/gateway-proxy) that holds the shard connections to -Discord. The bot connects to the proxy instead, so restarting it replays the guild state from the proxy's cache instead -of identifying every shard again (Discord allows one IDENTIFY per 5 seconds). Self-hosters don't need it: leave -`DISCORD_GATEWAY_URL` unset and the bot connects to Discord directly. - -To enable it, set in `.env`: - -```bash -COMPOSE_PROFILES=gateway-proxy -DISCORD_GATEWAY_URL=ws://gateway-proxy:7878 -SHARD_COUNT=32 # must match the proxy; the bot refuses to start otherwise -``` - -The proxy's shard count comes from Discord's recommendation; `curl localhost:7878/shard-count` prints it. Its intents -in `gateway-proxy.json` must match the bot's (`discord.Intents.all()`), since the bot's own IDENTIFY never reaches -Discord. - -- `just deploy` checks out the latest release, rebuilds the bot and the migrations service, runs migrations, then restarts only the bot; the proxy keeps the shards - connected. `just deploy v0.9.0` deploys (or rolls back to) a given release, and `just deploy main` the testing branch. -- `just deploy-proxy` recreates the proxy, which reconnects every shard. Use it for proxy upgrades and shard count - changes only, and update `SHARD_COUNT` first when the count changes. - -Voice sessions don't survive a bot restart: players that were playing stop and have to be started again. - -### Debug mode - -Set `debug: true` in `config.yml` and provide `DEBUG_TOKEN` in `.env`. The bot will log in with the debug token and -log errors verbosely. `just debug` starts the stack (or restarts the bot if it's already running) and tails its logs. - -## Development - -Development tooling runs on the host via [`uv`](https://docs.astral.sh/uv/), but the bot itself still runs in Docker. - -```bash -uv sync # install dev dependencies -uv run ruff format . # format -uv run ruff check . # lint -uv run ty check # type check -uv run pytest # tests -``` - -See [CONTRIBUTING.md](CONTRIBUTING.md) and [AGENTS.md](AGENTS.md) for coding standards. - -## Versioning & Releasing - -Version numbers follow **MAJOR.MINOR.PATCH**: - -- **MAJOR**: Breaking changes (e.g., full module overhauls) - - Resets MINOR and PATCH to `0` -- **MINOR**: New features or updated command sets - - Resets PATCH to `0` -- **PATCH**: Bugfixes, internal tweaks, or localization updates +Will write later. diff --git a/SELF-HOSTING.md b/SELF-HOSTING.md new file mode 100644 index 0000000..57d1fc5 --- /dev/null +++ b/SELF-HOSTING.md @@ -0,0 +1,152 @@ +# Self-hosting fm01 + +Thank you for choosing **fm01** to power your server! +Self-hosting problems aren't covered on the official support server. If you run into one, please +[open an issue](https://github.com/fm01-bot/fm01/issues/new/choose) on GitHub. + +Want to change the code instead of just running it? See [CONTRIBUTING.md](CONTRIBUTING.md). + +## Requirements + +- [Docker](https://docs.docker.com/get-docker/) with the Compose plugin (`docker compose`) +- [Git](https://git-scm.com/) +- A Discord bot token from the [Developer Portal](https://discord.com/developers/applications) + (enable all three privileged intents: **Presence**, **Server Members**, and **Message Content**) +- Optional: [`just`](https://github.com/casey/just) for the shortcut recipes in `justfile` + +Install these for your hosting platform (Debian Linux recommended). + +## 1. Clone the repository + +This creates a local copy of the files that the bot uses. + +```bash +git clone https://github.com/fm01-bot/fm01.git +cd fm01 +``` + +## 2. Create `.env` + +This file holds secrets (such as the bot token, which works like the bot's password) and configuration values. +Keep it private: anyone with the token can control your bot. + +```bash +cp .env.example .env +``` + +Fill in at least: + +| Variable | Description | +|---------------------|-------------------------------------------------------------------| +| `TOKEN` | Your bot token | +| `DB_PASSWORD` | Any strong password; used to create the PostgreSQL database | +| `LAVALINK_PASSWORD` | Any strong password; shared between the bot and Lavalink | + +Leave `DB_HOST=db`, `LAVALINK_URI=http://lavalink:2333` and the Redis URLs as they are because they point to the Compose +services. `DEBUG_TOKEN` is only needed for debug mode, `SENTRY_DSN` is optional, and the clustering settings should +stay at `BOT_MODE=standalone` for self-hosting. + +## 3. Create `config.yml` + +This file tells the bot who owns it, which modules to load and where to report errors. + +```bash +cp services/bot/config.yml.example services/bot/config.yml +``` + +Then edit at least: + +- `owner_ids`: replace with your own Discord user ID(s) +- `emojis`: set to emoji markdown your bot can use (e.g. `<:check:123456789012345678>`) +- `log_channel_id`: a **private** channel ID for runtime error reports, used when no `SENTRY_DSN` is set in `.env` +- `modules`: the cogs to load (`"*"` loads all of them) + +## 4. Start the bot + +```bash +docker compose up -d --build +``` + +Database migrations run automatically before the bot starts: the `migrations` service applies them, and the bot waits +for it to finish successfully. + +Then check that it's running: + +```bash +docker compose logs -f bot +``` + +## Managing the bot + +| Task | Command | `just` shortcut | +|------------------|---------------------------------|-------------------| +| Start | `docker compose up -d` | `just up` | +| Stop | `docker compose down` | `just down` | +| Restart the bot | `docker compose restart bot` | `just restart bot`| +| View logs | `docker compose logs -f bot` | `just logs bot` | +| Delete all data | `docker compose down -v` | `just destroy` | + +> [!WARNING] +> `docker compose down -v` / `just destroy` permanently deletes the database volume. Only use it when strictly necessary! + +## Updating + +Pull the latest code and rebuild; migrations run on their own: + +```bash +git pull +docker compose up -d --build +``` + +## Production + +The rest of this file is a cheat sheet for the maintainers running the official fm01. Self-hosters can skip it. + +### Gateway proxy + +Production runs a [gateway proxy](https://github.com/Gelbpunkt/gateway-proxy) that holds the shard connections to +Discord. The bot connects to the proxy instead, so restarting it replays the guild state from the proxy's cache instead +of identifying every shard again (Discord allows one IDENTIFY per 5 seconds). Self-hosters don't need it: leave +`DISCORD_GATEWAY_URL` unset and the bot connects to Discord directly. + +To enable it, set in `.env`: + +```bash +COMPOSE_PROFILES=gateway-proxy +DISCORD_GATEWAY_URL=ws://gateway-proxy:7878 +SHARD_COUNT=32 # must match the proxy; the bot refuses to start otherwise +``` + +The proxy's shard count comes from Discord's recommendation; `curl localhost:7878/shard-count` prints it. Its intents +in `gateway-proxy.json` must match the bot's (`discord.Intents.all()`), since the bot's own IDENTIFY never reaches +Discord. + +- `just deploy` checks out the latest release, rebuilds the bot and the migrations service, runs migrations, then restarts only the bot; the proxy keeps the shards + connected. `just deploy v0.9.0` deploys (or rolls back to) a given release, and `just deploy main` the testing branch. +- `just deploy-proxy` recreates the proxy, which reconnects every shard. Use it for proxy upgrades and shard count + changes only, and update `SHARD_COUNT` first when the count changes. + +Voice sessions don't survive a bot restart: players that were playing stop and have to be started again. + +### Weblate and the proxy (optional) + +Two opt-in profiles: + +- `proxy` runs Caddy with [`services/proxy/Caddyfile`](services/proxy/Caddyfile). It serves the website, the Public API + and Weblate, and gets their TLS certificates. It publishes ports 80 and 443, so nothing else on the host may use + them, and each domain's DNS must point at the host. +- `weblate` runs [Weblate](https://weblate.org) at `weblate.fm01.bot`. It has its own Postgres and Redis, apart from the + bot's. + +```bash +COMPOSE_PROFILES=proxy,weblate +WEBLATE_DB_PASSWORD=... # Weblate's own database +WEBLATE_ADMIN_EMAIL=you@example.com +# WEBLATE_ADMIN_PASSWORD=... # unset: a random one is printed in the first `docker compose logs weblate` +``` + +To run Weblate locally without the proxy, set `WEBLATE_ENABLE_HTTPS=0` and `WEBLATE_SITE_DOMAIN=localhost:8080` +(`WEBLATE_PORT` changes the port), run `docker compose up -d weblate`, and open . + +Weblate sends no email until you configure SMTP (the `WEBLATE_EMAIL_*` variables in its +[Docker docs](https://docs.weblate.org/en/latest/admin/install/docker.html)). diff --git a/services/website/AGENTS.md b/services/website/AGENTS.md index 0855444..68d19d4 100644 --- a/services/website/AGENTS.md +++ b/services/website/AGENTS.md @@ -60,10 +60,9 @@ Path aliases (`tsconfig.json`): `@/*` → `./*`, `@lib/*` → `./_lib/*`, `@publ ## 4. Localization -- The site's text lives outside this folder, in `shared/localization/website/`: `en.json`, `hu.json` (imported via `@shared/localization/website/.json`) and the legal docs in `doc//*.mdx` (read at runtime through `WEBSITE_L10N_DIR` in `_lib/functions/paths.ts`). `doc/en/` and `doc/hu/` must hold the same file names. -- The site ships in **English and Hungarian**. Every user-facing string goes in **both** `en.json` and `hu.json`, with the same keys. Don't hard-code copy in components. +- The site's text lives outside this folder, in `shared/localization/website/`, i.e. `en.json`, `.json` (imported via `@shared/localization/website/.json`) and the legal docs in `doc//*.mdx` (read at runtime through `WEBSITE_L10N_DIR` in `_lib/functions/paths.ts`). Files in `doc//` must have the same names as those in `doc/en/`. - Hungarian strings run longer. Leave room in layouts and test both languages. -- The Discord showcase displays real bot responses. The bot's texts are owned by `shared/localization/responses/{en,hu}.l10n.json`; never copy them into the website files. A showcase message points at one by **exact key** and `resolveMessages` (`_lib/functions/botLocale.ts`) renders the whole payload (content, embeds, Components V2): +- The Discord showcase displays real bot responses. The bot's texts are owned by `shared/localization/responses/{lang}.l10n.json`; never copy them into the website files. A showcase message points at one by **exact key** and `resolveMessages` (`_lib/functions/botLocale.ts`) renders the whole payload (content, embeds, Components V2): ```json { "username": "fm01", "avatar": "/images/logo.webp", "bot": true,