feat: Multi-guild support implementation

- Added multi-guild support with comma-separated AllowedGuildIDs config
- Per-guild embed tracking with isolated state
- Per-server action locking to prevent race conditions across guilds
- Cross-guild embed updates after power actions
- Debug logging for embed update triggers
- Fixed resource usage field formatting (brackets now properly closed)
- Updated config.ini.sample, generate_config.py for backward compatibility
- Updated README.md with multi-guild documentation
- Updated tests for multi-guild support
This commit is contained in:
k.eaven committed 2026-10-30 10:37:13 +00:00
1 parent e68b248033
commit bec06bd909
10 files changed
+802 -408

No files matched your search

+29 -22
View File
@@ -61,10 +61,11 @@ A feature-rich Discord bot for monitoring and managing Pterodactyl game servers
- **Background Task Management**: Asynchronous update loop runs every 10 seconds
### 🔒 Security & Access Control
- **Single-Guild Restriction**: Bot operates exclusively in your designated Discord server
- **Role-based Permissions**: "Game Server User" role required for all server interactions
- **Administrator Commands**: Special management commands restricted to server administrators
- **Interaction Validation**: Every button press and command verified for proper authorization
- **Multi-Guild Support**: Bot operates across multiple designated Discord servers simultaneously
- **Per-Guild Server Tracking**: Each guild tracks servers independently with isolated embeds
- **Role-based Permissions**: "Game Server User" role required for all server interactions (per guild)
- **Administrator Commands**: Special management commands restricted to server administrators (per guild)
- **Interaction Validation**: Every button press and command verified for proper authorization within its guild
### 💾 Data Persistence
- **Embed Location Storage**: Automatically remembers where embeds are posted (survives bot restarts)
@@ -438,11 +439,13 @@ Before installing the bot software, you need to create a Discord application and
When using Docker or generating the config automatically, these environment variables are required:
- `DISCORD_TOKEN`: Your Discord bot token (from Discord Developer Portal)
- `ALLOWED_GUILD_ID`: The Discord server ID where the bot should operate
- `ALLOWED_GUILD_IDS`: Comma-separated list of Discord server IDs where the bot should operate (e.g., `123456789,987654321`)
- `PANEL_URL`: Your Pterodactyl panel URL (must include http:// or https://)
- `CLIENT_API_KEY`: Pterodactyl client API key (starts with `ptlc_`)
- `APPLICATION_API_KEY`: Pterodactyl application API key (starts with `ptla_`)
> **Note**: The legacy `ALLOWED_GUILD_ID` (singular) environment variable is still supported for backward compatibility.
### Configuration File
The bot uses a `config.ini` file with this structure:
@@ -455,7 +458,7 @@ ApplicationAPIKey = ptla_yourapplicationkey
[Discord]
Token = your.discord.bot.token
AllowedGuildID = 123456789012345678
AllowedGuildIDs = 123456789012345678,987654321098765432
```
To generate the config file from environment variables:
@@ -479,6 +482,8 @@ python generate_config.py
### Bot Commands
All commands are guild-scoped - they only affect the guild (server) where they are invoked.
#### `/server_status`
Display an interactive dropdown menu containing all available servers from your Pterodactyl panel. Select a server to create a permanent status embed in the current channel with real-time monitoring and control buttons.
@@ -486,10 +491,10 @@ Display an interactive dropdown menu containing all available servers from your
- Shows total server count and online/offline statistics
- Lists all servers with descriptions
- Creates persistent, auto-updating embeds
- Automatically removes old embeds when recreating for the same server
- Automatically removes old embeds when recreating for the same server **in this guild**
#### `/refresh_embeds` (Admin only)
Force a complete refresh of all server status embeds. This command:
Force a complete refresh of all server status embeds **in the current guild**. This command:
- Recreates all tracked embeds with fresh data
- Deletes old embed messages to prevent duplication
- Updates embed tracking storage
@@ -501,9 +506,9 @@ Force a complete refresh of all server status embeds. This command:
- Following Discord API issues
#### `/purge_embeds` (Admin only)
Permanently delete all server status embeds from the Discord server. This command:
Permanently delete all server status embeds from **the current Discord server**. This command:
- Removes all tracked embed messages
- Clears the embed tracking file
- Clears the embed tracking file for this guild
- Provides real-time progress updates
- Shows detailed statistics (deleted, missing, errors)
@@ -554,24 +559,26 @@ Embed locations are stored in `embed/embed_locations.json` and persist between b
## Permissions
The bot implements two levels of access control:
The bot implements multi-guild access control with per-guild isolation:
### 1. Guild Restriction
The bot only responds to commands and interactions from the Discord server specified in `AllowedGuildID`. This prevents unauthorized use if the bot is accidentally added to other servers.
### 1. Guild Allowlist
The bot only responds to commands and interactions from Discord servers whose IDs are listed in `AllowedGuildIDs`. This prevents unauthorized use if the bot is accidentally added to other servers.
### 2. Role-Based Access
Users must have the **"Game Server User"** role (exact name match) to:
### 2. Per-Guild Role-Based Access
Users must have the **"Game Server User"** role (exact name match) **in the specific guild** where they are interacting to:
- Use server control buttons (Start/Stop/Restart)
- View server addresses
- Interact with any bot features
### 3. Administrator Access
Server administrators (users with Discord's Administrator permission) can additionally:
- Use `/refresh_embeds` command
- Use `/purge_embeds` command
- No special role required - based on Discord permissions
Each guild maintains its own "Game Server User" role independently.
**Note:** The `/server_status` command can be used by anyone, but only users with the "Game Server User" role can interact with the resulting embeds.
### 3. Per-Guild Administrator Access
Server administrators (users with Discord's Administrator permission) **in a specific guild** can additionally:
- Use `/refresh_embeds` command (affects only that guild)
- Use `/purge_embeds` command (affects only that guild)
- No special role required - based on Discord permissions in that guild
**Note:** The `/server_status` command can be used by anyone in an allowed guild, but only users with the "Game Server User" role in that guild can interact with the resulting embeds.
## Logging System
@@ -719,4 +726,4 @@ This project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE)
---
**Note**: This bot is designed for single Pterodactyl domain and single Discord guild use. For multi-instance support, significant modifications would be required.
**Note**: This bot supports multiple Pterodactyl domains and multiple Discord guilds simultaneously. Each guild tracks servers independently while sharing the same Pterodactyl infrastructure.