A Discord bot and web map for Belgian MeshCore nodes, syncing from
https://map.meshcore.io/api/v1/nodes.
The web app shows every active Belgian node on a map (MapLibre GL JS with vector base maps; Leaflet for browsers without WebGL) with stats, an activity timeline, and historical playback. The Discord bot lets users search the directory and claim ownership of their own nodes.
The live deployment is at meshmap.radio-actief.be.
Prerequisites:
- Docker and Docker Compose
- A Discord bot token if you want the bot online (web map runs without it)
git clone <this-repo>
cd RRY-Map-Bot
cp .env.example .env # fill in DISCORD_* and FLASK_SECRET_KEY
docker compose build
# Initialise the database (creates tables, backfills first-seen dates,
# seeds node_claims from current owners). Safe to re-run.
docker compose run --rm api python -m backend.migrations.reset_history --confirm
# Pull the official Belgium feed once so the map has data on first load.
docker compose run --rm sync python3 backend/sync_belgian_nodes.py
# Bring up the web map on http://localhost:8000.
docker compose up -d api
# Optional services.
docker compose up -d sync # scheduled background syncs
docker compose up -d discord-bot # online Discord botRun the test suite inside the image:
docker compose run --rm api pytest -q tests/The repeater configurator (/configurator) is a Vite + Preact + TypeScript app in web/configurator/.
npm run build writes it to dist/configurator/, which Flask serves; the Dockerfile builds it in its first stage.
npm ci
npm run dev # Vite dev server; /api and /data are proxied to the Flask container on :8000
npm test # Vitest
npm run typecheck # tsc --noEmit
npm run build # production build into dist/configurator/ (and the pages, below)index.html, stats.html and region-map.html load as they are, file by file, with no build: that
is how they run in development. npm run build also builds them (web/site/, Vite) into
dist/site/: per page one stylesheet, the scripts in a few files, messages in one file per
language, everything under /assets/ with a content hash in its name. Flask serves the built page
when dist/site/ is there (the Dockerfile builds it in its first stage) and tells browsers to keep
/assets/ files for a year and to ask for the page itself on every visit.
npm run build:site # only the pages, into dist/site/
rm -r dist/site # back to the pages as they areThe pages' classic scripts (<script src> without type="module") are joined per run of
neighbours and stay classic; each must be one call with no declarations at the top, or the build
stops and says which file.
Parity fixtures in web/configurator/tests/fixtures/parity/ pair saved backup files with the exact CLI script the
configurator must generate for them, so changes to script generation cannot silently alter what is sent to a repeater.
node scripts/update-radio-presets.mjs refreshes web/configurator/src/core/radio-presets.json from the official
MeshCore API.
Verify the four count surfaces agree against the running API:
docker compose exec api python tests/check_invariants.py http://localhost:8000flowchart LR
Official["map.meshcore.io<br/>/api/v1/nodes"] --> Sync["sync_belgian_nodes.py<br/>(scheduled)"]
Sync --> BN[("belgian_nodes")]
Sync --> NC[("node_changes")]
Sync --> SH[("sync_history")]
Bot["discord_bot.py"] --> BN
Bot --> CL[("node_claims")]
BN --> API["app.py (Flask)"]
NC --> API
API --> Map["Web map (index.html)"]
API --> Stats["Stats page (stats.html)"]
Bot -.->|/search /mynodes /stats| API
Sync. sync_belgian_nodes.py fetches the official feed, filters Belgium by
geocoding against data/be-municipalities.geojson, writes the resulting rows
into belgian_nodes, and records every add / remove / update / restore in
node_changes. Each run also writes a per-run summary into sync_history.
Stats chart. The chart's first-seen seed counts each currently displayable
node on its inserted_date; daily increments come from node_changes. Map
header, stats chips, chart, and timeline playback all read the same row set
(is_active = 1 AND adv_lat IS NOT NULL AND adv_lon IS NOT NULL), so totals
match by construction.
Discord ownership. /node claim and /node unclaim (or the map's claim
buttons) set discord_owner_id and discord_owner_name on belgian_nodes
and append an event row to node_claims with a timestamp and its source
(bot or web). node_claims is an append-only log of every claim/unclaim
event, and of managers added and removed (manager_add, manager_remove):
people an owner invites with a one-time link (node_managers,
manager_invites). Each person's choices (show my name, share my nodes with
partner tools) are in person_settings. Public answers never hold a Discord
id.
.env is loaded by all three services. Keys (see .env.example for examples):
DISCORD_BOT_TOKEN,DISCORD_GUILD_ID,STARTUP_CHANNEL_ID,STARTUP_MESSAGE_ID– Discord bot. The instructions post inSTARTUP_CHANNEL_IDis edited in place: the bot finds it bySTARTUP_MESSAGE_ID, by the id it stored insync_state, or as its own pinned or recent post, and posts a new one only when none exists.MAP_BASE_URL– map address used in every link the bot posts.DISCORD_OAUTH2_CLIENT_ID,DISCORD_OAUTH2_CLIENT_SECRET,DISCORD_OAUTH2_REDIRECT_URI,FLASK_SECRET_KEY,SESSION_COOKIE_SECURE,DISCORD_SERVER_INVITE_URL– web auth.DATABASE_PATH– SQLite path (defaultdata/belgian_nodes.db).OFFICIAL_API_URL– upstream feed (defaulthttps://map.meshcore.io/api/v1/nodes).BE_MUNICIPALITIES_GEOJSON,GEOCODE_BUFFER_METERS,GEOPY_USER_AGENT,GEOPY_TIMEOUT,USE_GEOPY_FALLBACK– Belgian geocoder.SYNC_INTERVAL_MINUTES(or legacySYNC_INTERVAL_HOURS) – scheduled sync interval.DAILY_DIGEST_ENABLED,DAILY_DIGEST_HOUR,DAILY_DIGEST_MINUTE,DAILY_DIGEST_TZ,DAILY_DIGEST_CHANNEL_ID– daily activity digest.
belgian_nodes– every Belgian node currently or recently seen on the map.node_changes– per-event ledger (added / removed / restored / updated) emitted by the sync.sync_history– one row per sync run with aggregate counts.node_claims– append-only event log of claims and unclaims (source:botorweb).command_log– one row per bot command: time (UTC), command, user id, ok or error, duration in ms. No command arguments.digest_state– single-row state for the daily Discord digest.
All commands work only inside a server, not in DMs.
/search– search by name, key or owner, with filters (type, city with suggestions, frequency preset, owner, claimed, inactive, source). One public reply; a single hit shows the node's details. A node whose owner switched "Show my name with my nodes" off reads as claimed, without a name or mention, and isn't found by its owner (seeDEPLOYMENT.md)./mynodes– the caller's nodes, active and inactive (only they see it)./node claim <query>– claim an unclaimed node; suggestions list unclaimed nodes. Only for members ofDISCORD_GUILD_ID./node unclaim <query>– release one of your nodes after a confirmation; suggestions list only your nodes./node invite-manager <node>– the owner gets a one-time invitation link (7 days, one use) to send to the person who will help manage the node; only the owner sees it. Only for members ofDISCORD_GUILD_ID./node managers <node>– the owner sees the node's managers and can remove one after a confirmation./privacy– the caller's two choices from the account page ("Show my name with my nodes", "Share my nodes with partner tools") with a button to switch each; only they see it. Only for members ofDISCORD_GUILD_ID./stats– network statistics./digest run– post the daily activity digest now (visible only to members with Manage Server).
RRY-Map-Bot/
backend/
api/app.py # Flask API + static assets
discord_bot.py # Discord bot
sync_belgian_nodes.py # Sync service
discord_queries.py # DB queries used by bot and API
database.py # Schema + connection helpers
migrations/reset_history.py
config/ # Frequency presets, Belgium config
data/ # SQLite DB + Belgium GeoJSON
src/ # Frontend JS (map.js, …)
tests/ # pytest test suite + check_invariants.py
index.html # Map page
stats.html # Stats / playback page
Dockerfile
docker-compose.yml
requirements.txt
docker-compose.yml defines three services: api (binds localhost:8000),
sync (scheduled runs of sync_belgian_nodes.py), and discord-bot. They
share ./data:/app/data for the SQLite database and ./logs:/app/logs for
logs. See DEPLOYMENT.md for production deployment notes.
MIT. Issues and PRs welcome.