Files
hoi4botdc/README.md
SimolZimol 3ed9c3270a modified: .env.example
modified:   README.md
2025-10-27 23:11:46 +01:00

169 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# HOI4 ELO Discord Bot
Ein Discord Bot für Hearts of Iron IV, der über Coolify deployed werden kann.
## Features
- ELO-System (Standard/Competitive), Spiele-Lifecycle (/hoi4create, /hoi4setup, /hoi4end)
- Stats, History und Leaderboard
- Emoji-/Länder-Tag-Unterstützung (tags.txt, emotes.markdown)
- Automatische Rollenvergabe nach ELO (pro Kategorie)
- YouTube Musikplayer (yt-dlp + ffmpeg) mit Queue und Lautstärke
- Docker/Coolify ready
## Verfügbare Befehle (Auszug)
- `/hoi4create <type> <name>` Neues Spiel anlegen (type: standard/competitive)
- `/hoi4setup <game> <user> <team> <t-level> [country]` Spieler hinzufügen (T1/2/3; country optional als HOI4-Tag)
- `/hoi4end <game> <winner_team|draw>` Spiel beenden, ELO berechnen, Rollen syncen
- `/hoi4stats [user]` ELO, Rank, Win/Draw/Loss
- `/hoi4history [limit] [player] [name] [type]` Abgeschlossene Spiele filtern
- `/hoi4leaderboard [type] [limit]` Top ELOs
- Musik: `/join`, `/leave`, `/play <url|search>`, `/skip`, `/stop`, `/pause`, `/resume`, `/queue`, `/np`, `/volume <0-200>`
- Diagnose: `/webtest [query]` Testet Web-Konnektivität und yt-dlp-Extraction
## Setup für Coolify
### 1. Discord Bot erstellen
1. Gehe zu https://discord.com/developers/applications
2. Erstelle eine neue Application
3. Gehe zu "Bot" und erstelle einen Bot
4. Kopiere den Bot Token
### 2. Bot Permissions
Der Bot benötigt folgende Permissions:
- `Send Messages`
- `Read Message History`
- `Use Slash Commands`
- `Embed Links`
- `Read Messages/View Channels`
### 3. Coolify Deployment
1. **Repository**: Verbinde dein Git Repository mit Coolify
2. **Umgebungsvariablen**: Setze folgende Variablen in Coolify:
- `DISCORD_TOKEN` = Dein Bot Token
- Entweder `DATABASE_URL` (mysql://user:pass@host:port/db) ODER Einzelwerte `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, `DB_PASSWORD`
- Für YouTube (optional, empfohlen bei „Sign in to confirm youre not a bot“):
- `YTDL_COOKIES_B64` = Base64-kodierte cookies.txt (Netscape-Format), ODER
- `YTDL_COOKIES_FILE` = Pfad zu cookies.txt im Container (z. B. /app/cookies.txt)
- Optional: `YTDL_UA` (User-Agent), `YTDL_YT_CLIENT` (z. B. android/web)
3. **Build Settings**:
- Coolify wird automatisch das Dockerfile verwenden
- Port: Der Bot läuft als Service, kein HTTP-Port erforderlich
4. **Deploy**: Starte das Deployment
## Lokale Entwicklung
### Voraussetzungen
- Python 3.10+
- pip
### Installation
1. Repository klonen
2. Dependencies installieren:
```bash
pip install -r requirements.txt
```
3. `.env` Datei erstellen:
```bash
cp .env.example .env
```
4. Discord Token in `.env` eintragen:
```
DISCORD_TOKEN=your_actual_bot_token_here
```
5. Bot starten:
```bash
python app.py
```
### YouTube-Cookies bereitstellen (empfohlen)
YouTube kann Server/Container ohne Cookies blockieren („Sign in to confirm youre not a bot“). Übergib Cookies im Netscape-Format:
Variante A Base64 via Env (einfach in Coolify)
1. Exportiere cookies.txt aus deinem Browser (Erweiterung „Get cookies.txt“ oder yt-dlp Export aus lokaler Browser-Session).
2. Base64-kodiere die Datei (Windows PowerShell):
```powershell
[Convert]::ToBase64String([IO.File]::ReadAllBytes("cookies.txt")) | Set-Clipboard
```
3. In Coolify `YTDL_COOKIES_B64` setzen (Inhalt aus der Zwischenablage einfügen) und neu deployen.
Variante B Datei mounten
- cookies.txt in den Container mounten (z. B. `/app/cookies.txt`) und `YTDL_COOKIES_FILE=/app/cookies.txt` setzen.
Optional: `YTDL_UA` setzen (aktueller Browser UA), `YTDL_YT_CLIENT` (z. B. `android`).
### Web testen (/webtest)
Mit `/webtest` prüft der Bot:
- HTTP-Reachability (Google 204, YouTube, Discord API)
- yt-dlp-Extraction mit deiner Query oder einem Default-Suchbegriff
- ob Cookies konfiguriert sind (Datei/B64/Browser)
So kannst du schnell sehen, ob der Container Internetzugriff hat und ob yt-dlp wegen Cookies scheitert.
## Docker
### Lokal mit Docker testen
```bash
# Image bauen
docker build -t hoi4-elo-bot .
# Container starten
docker run -e DISCORD_TOKEN=your_token_here hoi4-elo-bot
```
## Projekt Struktur
```
.
├── app.py # Haupt-Bot-Datei
├── requirements.txt # Python Dependencies
├── Dockerfile # Docker Konfiguration
├── .env.example # Beispiel Umgebungsvariablen
└── README.md # Diese Datei
```
## Erweiterungen
Der Bot ist so strukturiert, dass du einfach weitere Commands hinzufügen kannst:
```python
@bot.command(name='my_command')
async def my_command(ctx):
await ctx.send("Hello World!")
```
## Troubleshooting
### Bot startet nicht
- Überprüfe ob der Discord Token korrekt gesetzt ist
- Schaue in die Logs: `docker logs <container_name>`
### Bot reagiert nicht auf Befehle
- Stelle sicher, dass der Bot die richtigen Permissions hat
- Überprüfe ob Message Content Intent aktiviert ist
### Coolify Logs anschauen
- Gehe zu deinem Coolify Service
- Klicke auf "Logs" um die Bot-Ausgabe zu sehen
## Support
Bei Problemen schaue in die Coolify Logs oder überprüfe die Discord Developer Console für weitere Informationen.