d4rkbot: API v1 mit Key-System, Env-Diät, Rebranding

- API-Keys (SHA-256-Hash, Scopes, last_used) — Verwaltung auf der Setup-Seite,
  Klartext-Key wird genau einmal angezeigt
- /api/v1: message, dm, roles (add/remove), member/:id, stats — Bearer-Auth
  mit Scope-Prüfung, Embed-Sanitizing, README-Doku mit Python-Beispiel
- Env-Diät: PUBLIC_URL + GITEA_URL jetzt Settings (Env nur Fallback),
  OAuth-Redirect dynamisch; Env enthält nur noch Secrets/Bootstrap
- Rebranding ecobot → d4rkbot (Packages, Container, Cookies, README);
  Volume-Name bleibt ecobot_data (Datenerhalt), Portainer-Stack-Name bleibt

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 11:56:48 +02:00
co-authored by Claude Opus 4.8
parent eb51be4ebc
commit 143288affa
19 changed files with 468 additions and 37 deletions
+41 -6
View File
@@ -1,4 +1,4 @@
# EcoBot — D4RKST3R // DEVLOG
# d4rkbot — D4RKST3R // COMMUNITY BOT
Discord-Bot + Webinterface: Devlog-Tagebuch, Commit-Feed, Changelog und
Community-Tools für die EcoGame-Entwicklung — alles gebrandet, alles über
@@ -122,8 +122,8 @@ Der Endpoint versteht das Discord-Webhook-Format (JSON + Multipart) —
## Deployment (Portainer)
1. **Stacks → Add stack** → Name `ecobot` → Build method **Repository**
- URL `https://git.d4rkst3r.de/D4rkst3r/ecobot`, Reference `refs/heads/main`,
1. **Stacks → Add stack** → Name `ecobot` (Bestands-Stack behalten! Der Name steckt im Volume-Prefix) → Build method **Repository**
- URL `https://git.d4rkst3r.de/D4rkst3r/d4rkbot`, Reference `refs/heads/main`,
Compose path `docker-compose.yml`
- Privates Repo: Authentication mit Gitea-Token (Scope `read:repository`)
2. Environment-Variablen eintragen (Tabelle oben)
@@ -137,10 +137,10 @@ Daten liegen im Volume `ecobot_data` (`/app/data`): SQLite (`ecobot.db`, WAL)
Manuell statt Portainer:
```
git clone git@gitea:D4rkst3r/ecobot.git && cd ecobot
git clone git@gitea:D4rkst3r/d4rkbot.git && cd d4rkbot
cp .env.example .env # Werte eintragen
docker compose up -d --build
docker logs -f ecobot
docker logs -f d4rkbot
```
---
@@ -168,6 +168,39 @@ node tools/test-webhook.mjs
---
## API v1 — für eigene Skripte & Dienste
Der Bot ist die zentrale Discord-Brücke der Infrastruktur: devlog.py, Platform,
FiveM-Server, CI-Jobs … reden alle mit einer API statt mit zig Discord-Webhooks.
**Auth:** API-Keys auf der Setup-Seite erstellen (Name + Scopes, Key wird einmalig
angezeigt, Widerruf jederzeit). Jeder Request:
```
Authorization: Bearer d4rk_<key>
```
| Endpoint | Scope | Body / Antwort |
|---|---|---|
| `POST /api/v1/message` | `message` | `{ channel_id, content?, embed? }` → postet als Bot (Embed: title, description, color, url, image, thumbnail, footer, fields) |
| `POST /api/v1/dm` | `dm` | `{ user_id, content }` → Direktnachricht |
| `POST /api/v1/roles` | `roles` | `{ user_id, role_id, action: "add"\|"remove" }` → Rolle vergeben (z. B. Shop-Kauf → Kunden-Rolle) |
| `GET /api/v1/member/:id` | `read` | Member-Info: Name, Rollen, Beitritt — für Login-/Berechtigungs-Checks |
| `GET /api/v1/stats` | `read` | Devlog-/Commit-Zahlen, Guilds, Uptime |
Beispiel (Python):
```python
import urllib.request, json
req = urllib.request.Request(
"https://bot.d4rkst3r.de/api/v1/message",
data=json.dumps({"channel_id": "123", "embed": {"title": "Build fertig ✅", "color": 0xF5C518}}).encode(),
headers={"Content-Type": "application/json",
"Authorization": "Bearer d4rk_...",
"User-Agent": "mein-script/1.0"})
urllib.request.urlopen(req)
```
---
## HTTP-Endpoints
| Route | Auth | Zweck |
@@ -179,6 +212,8 @@ node tools/test-webhook.mjs
| `GET /api/releases?page=` | — | Changelog |
| `GET /feed.xml` | — | RSS |
| `GET /devlog-assets/*` | — | Lokal gespeicherte Devlog-Bilder |
| `POST/GET /api/v1/*` | API-Key (Bearer) | Externe Skripte — siehe „API v1" oben |
| `GET/POST/DELETE /api/apikeys` | Admin | API-Key-Verwaltung |
| `GET/PUT /api/settings`, `POST /api/settings/test/:target` | Admin | Setup-Seite |
| `GET /api/commits?page=` · `DELETE /api/devlogs/:id` | Admin | Commit-Archiv · Devlog löschen |
| `GET /auth/login` · `/auth/callback` · `/auth/logout` | — | Discord-OAuth2 |
@@ -191,7 +226,7 @@ Archiv (MessageDelete-Sync) — zusätzlich gibt es den ✕-Button für Admins a
## Projektstruktur
```
ecobot/
d4rkbot/
├── src/
│ ├── index.js # Start: Bot, Webserver, Wochen-Rückblick, Watchdog
│ ├── config.js # Env-Konfiguration mit Validierung