From b6b4324986298c717ce6afe8fde3f076afcbfa95 Mon Sep 17 00:00:00 2001 From: Marc Date: Sat, 11 Oct 2025 13:48:55 +0200 Subject: [PATCH] Updated to only shulker container --- README.md | 206 ++++++++++++++++++++++++++++++++++++++++----- docker-compose.yml | 31 +++---- main.py | 1 - requirements.txt | 0 4 files changed, 198 insertions(+), 40 deletions(-) delete mode 100644 main.py delete mode 100644 requirements.txt diff --git a/README.md b/README.md index 75d7838..86ff4f2 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,192 @@ -Website for TFMC (teknisk fysiks minecraft server) +# Discord-Minecraft Bridge with Shulker +A Dockerized Discord-Minecraft chat bridge using [Shulker](https://github.com/destruc7i0n/shulker). This allows bidirectional communication between your Minecraft server and a Discord channel - players can chat from Discord to Minecraft and vice versa. -[] Add integration for playerstatistics across servers - - We have to read the jsons in world (i have example for two worlds) - - we have to get the uuid as stats are saved in uuid - - convert playername to uuid maybe? is there an api? - - Would be nice to see playtime and block usage over all the different servers + a total. - for example using edc64... uuid i would like to see total amount of diamond collected on all worlds and also diamond per world in a list. -[] Add a nice site for TFMC with information about the server. -[] Add statistics of online status on the server? - - Graphs of players online? - - Show total players that have played on server? - - -[] Registering form with email authentication so only UMU university students can join. (link email to minecraft account for whitelist) - - This could be done via rcon maybe? and have a separate list of players that have registered. +## Features -[] Build this entire website and management via docker for easier release? - - We could use environment variables and maybe also add volumes with the player files - like mounting ./minecraftserver/world/stats:/status/server1:ro or something? - - Maybe use integration with itgz, and get variables from those servers? via for example docker sock? or would that be to insecure? -[] Maybe integrate chat with discord via rcon? - - Base on existing project? This one exist and could maybe be useful? https://github.com/destruc7i0n/shulker +- **Bidirectional Chat**: Messages from Minecraft appear in Discord, and Discord messages are sent to Minecraft +- **Docker-based**: Easy deployment with Docker Compose +- **Flexible Configuration**: Support for both Discord bot and webhook modes +- **Log Tailing**: Automatically reads Minecraft server logs without needing additional plugins +- **RCON Support**: Optional RCON integration for sending Discord messages to Minecraft + +## Prerequisites + +- Docker and Docker Compose installed +- A Discord bot token (see [Creating a Discord Bot](#creating-a-discord-bot)) +- A Minecraft server with accessible log files +- (Optional) RCON enabled on your Minecraft server for full bidirectional chat + +## Quick Start + +### 1. Clone and Initialize + +```bash +git clone +cd TFMC-Discord +git submodule update --init --recursive +``` + +### 2. Configure Environment + +Edit `docker-compose.yml` and update the environment variables: + +```yaml +environment: + DISCORD_TOKEN: "YOUR_DISCORD_BOT_TOKEN_HERE" + DISCORD_CHANNEL_ID: "YOUR_DISCORD_CHANNEL_ID_HERE" + WEBHOOK_URL: "" # Optional: Use webhook instead of bot + SERVER_NAME: "My Minecraft Server" + # ... other settings +``` + +**Important**: Update the volume path to point to your Minecraft server's log directory: + +```yaml +volumes: + - /path/to/your/minecraft/logs:/minecraft/logs:ro +``` + +### 3. Run + +```bash +docker compose up -d --build +``` + +The container will: +1. Build the Shulker application from the submodule +2. Generate a `config.json` from the environment variables +3. Start tailing your Minecraft server logs +4. Bridge messages between Discord and Minecraft + +## Configuration + +### Environment Variables + +| Variable | Required | Description | Default | +|----------|----------|-------------|---------| +| `DISCORD_TOKEN` | Yes* | Discord bot token | - | +| `DISCORD_CHANNEL_ID` | Yes* | Discord channel ID for chat | - | +| `WEBHOOK_URL` | No | Discord webhook URL (alternative to bot) | - | +| `SERVER_NAME` | No | Server name shown in Discord | "Minecraft Server" | +| `SERVER_IMAGE` | No | Server avatar URL in webhook mode | "" | +| `DISCORD_MESSAGE_TEMPLATE` | No | Message format template | "<%username%> %message%" | +| `DEBUG` | No | Enable debug logging | "false" | +| `IS_LOCAL_FILE` | No | Use log file tailing | "true" | +| `LOCAL_FILE_PATH_OVERRIDE` | No | Custom log file path | "/minecraft/logs/latest.log" | + +\* Either `DISCORD_TOKEN` + `DISCORD_CHANNEL_ID` OR `WEBHOOK_URL` is required + +### Bot vs Webhook Mode + +**Bot Mode** (recommended): +- Requires a Discord bot token and channel ID +- Better for interactive features +- Can use RCON to send messages to Minecraft + +**Webhook Mode**: +- Only requires a webhook URL +- One-way: Minecraft → Discord +- Simpler setup but limited functionality + +### RCON Configuration + +To enable Discord → Minecraft messages, you need RCON enabled on your Minecraft server. + +1. Enable RCON in your `server.properties`: +```properties +enable-rcon=true +rcon.port=25575 +rcon.password=your_secure_password +``` + +2. Add RCON settings to your environment or edit `/data/config.json` after first run: +```json +{ + "MINECRAFT_SERVER_RCON_IP": "your-minecraft-server-ip", + "MINECRAFT_SERVER_RCON_PORT": 25575, + "MINECRAFT_SERVER_RCON_PASSWORD": "your_secure_password" +} +``` + +## Creating a Discord Bot + +1. Go to the [Discord Developer Portal](https://discord.com/developers/applications) +2. Click "New Application" and give it a name +3. Go to the "Bot" tab and click "Add Bot" +4. Under "Token", click "Copy" to get your `DISCORD_TOKEN` +5. Enable "Message Content Intent" under "Privileged Gateway Intents" +6. Go to "OAuth2" → "URL Generator" + - Select scopes: `bot` + - Select permissions: `Send Messages`, `Read Messages/View Channels`, `Read Message History` +7. Copy the generated URL and open it in your browser to invite the bot to your server +8. Right-click on the channel where you want the chat bridge and click "Copy Channel ID" to get your `DISCORD_CHANNEL_ID` + - You may need to enable Developer Mode in Discord Settings → Advanced → Developer Mode + +## Volumes + +- `/data` - Stores `config.json` (mounted as tmpfs by default since config is generated from env vars) +- `/minecraft/logs` - Mount your Minecraft server's log directory here (read-only) + +## Updating Shulker + +Shulker is included as a Git submodule. To update to the latest version: + +```bash +git submodule update --remote external/shulker +docker compose build shulker +docker compose up -d shulker +``` + +## Troubleshooting + +### Messages not appearing in Discord + +- Check that your `DISCORD_TOKEN` and `DISCORD_CHANNEL_ID` are correct +- Ensure the bot has permissions to send messages in the channel +- Check logs: `docker compose logs shulker` + +### Messages not appearing in Minecraft + +- Verify RCON is enabled and configured correctly in `server.properties` +- Check RCON credentials in `config.json` +- Ensure the Minecraft server is accessible from the Docker container +- Test RCON connectivity separately + +### Log file not found + +- Verify the volume path points to the correct directory +- Ensure `latest.log` exists in the mounted directory +- Check file permissions (should be readable by container user) + +### Modded Server Issues + +If you're running a modded server (Forge, Fabric, etc.), you may need to adjust the `REGEX_SERVER_PREFIX` setting. See [Shulker's FAQ](https://github.com/destruc7i0n/shulker#faq) for details. + +## Advanced Configuration + +After the first run, you can manually edit `/data/config.json` for advanced settings. Stop the container, edit the file, and restart: + +```bash +docker compose down +# Edit config.json in the Docker volume +docker compose up -d +``` + +For all available configuration options, see the [Shulker documentation](https://github.com/destruc7i0n/shulker). + +## Technical Details + +- Built on Node.js 22 Alpine +- Runs as non-root user (uid 10001) +- Uses `IS_LOCAL_FILE` mode for log tailing (no webhook server needed) +- Configuration is generated from environment variables via the entrypoint script +- The Shulker source code is maintained as a Git submodule and built during Docker image creation + +## License + +This project uses [Shulker](https://github.com/destruc7i0n/shulker) which is licensed under MIT. Please see the Shulker repository for its license terms. + ## Shulker Discord-Minecraft Bridge (Dockerized) diff --git a/docker-compose.yml b/docker-compose.yml index 9d5505a..89721f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,20 +2,22 @@ version: "3.8" services: shulker: - image: gitea.taginu.com/marc/tfmc-website:latest + build: + context: . + dockerfile: docker/shulker/Dockerfile container_name: shulker restart: unless-stopped user: "root" # Configure everything inline here; no .env file required environment: - # Discord configuration (fill these) - DISCORD_TOKEN: "MTA3MTEwMzcwMDAyMzY0ODMyMA.GIlFkn.o10LKcpjlaLDvVsgF_WKZhz5ykPYf1KEds_g3I" - DISCORD_CHANNEL_ID: "1247178901004877916" + # Discord configuration (fill these with your own values) + DISCORD_TOKEN: "YOUR_DISCORD_BOT_TOKEN_HERE" + DISCORD_CHANNEL_ID: "YOUR_DISCORD_CHANNEL_ID_HERE" # If set, webhook mode is used; leave empty to use the bot account - WEBHOOK_URL: "https://discord.com/api/webhooks/1423056957434101850/QOQgLa1Y3TkH2JPOJuLXvh4IO8YXo-hMUVeOErZ4Hcz27uticHY09x9Z1cm-AksDeJ7Z" + WEBHOOK_URL: "" # Display name/avatar for server-origin messages (webhook mode) - SERVER_NAME: "TFMC" + SERVER_NAME: "Minecraft Server" SERVER_IMAGE: "" # Message formatting and logging @@ -31,19 +33,10 @@ services: - type: tmpfs target: /data # Map your host/server Minecraft logs into the container + # Update the path on the left side to point to your Minecraft server's log directory - ./data/logs:/minecraft/logs:ro - # No port exposure needed in local log tail mode - - mc: - image: itzg/minecraft-server - tty: true - stdin_open: true - ports: - - "25565:25565" - environment: - EULA: "TRUE" - volumes: - # attach the relative directory 'data' to the container's /data path - - ./data:/data + # Port 8000 is only needed if you want to use webhook mode for remote log streaming + # ports: + # - "8000:8000" diff --git a/main.py b/main.py deleted file mode 100644 index 20cb804..0000000 --- a/main.py +++ /dev/null @@ -1 +0,0 @@ -# Main file for TFMC website. Will have all the integrations. \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e69de29..0000000