A Discord bot with unified whitelist management for Squad game servers, featuring automatic Discord role-based access control, Steam account linking, and comprehensive admin tools.
Roster Control features a unified whitelist system that automatically synchronizes Discord roles with Squad server access. Users with designated Discord roles are automatically granted whitelist access, while administrators can also manually manage individual entries. The system integrates with MariaDB for persistent storage, BattleMetrics API for server/player data, and SquadJS for real-time player events and secure Steam account linking.
- Unified Whitelist System: Automatic Discord role-based Squad server access with database-driven management
- Role-Based Access Control: Discord roles automatically grant/revoke Squad server whitelist access
- Steam Account Linking: Secure in-game verification system for Steam-Discord account connections
- On-Duty Admin Management: Manual
/ondutyand/offdutycommands with automated triggers - Manual Whitelist Management: Add/remove specific players with
/whitelistcommands - Real-Time Monitoring: Track player join/leave events via SquadJS integration
- Audit Logging: Complete audit trail of all roster and admin actions
- Confidence-Based Security: Staff roles require high-confidence Steam account links
- RCON Integration: Automated kicks/bans for roster violations
- Automated Reporting: Daily/weekly activity summaries
- Multi-Server Support: Manage multiple Squad servers
- Custom Notifications: Alert admins of specific events
- Node.js with Discord.js v14
- MariaDB with Sequelize ORM
- SquadJS for Squad server integration
- BattleMetrics API for player data
- Winston for logging
- Umzug for database migrations
- Node.js 18+
- MariaDB server
- Discord Bot Token
- BattleMetrics API Token
- Squad server with RCON access
-
Clone and Install
git clone <repository-url> cd roster-control npm install
-
Environment Configuration
Copy the example environment file and update it with your settings:
cp .env.example .env # Edit .env with your settings -
Database Setup
Option A: Quick Setup (Single Command)
# Create database with default settings mysql -u root -p -e "CREATE DATABASE roster_control CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
Option B: Secure Setup (Recommended)
Connect to MariaDB and run these commands:
-- Connect to MariaDB as root mysql -u root -p -- Create the database with proper character encoding CREATE DATABASE roster_control CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- Create a dedicated user for the application CREATE USER 'roster_user'@'localhost' IDENTIFIED BY 'your_secure_password_here'; -- Grant privileges to the user GRANT ALL PRIVILEGES ON roster_control.* TO 'roster_user'@'localhost'; -- Apply privileges FLUSH PRIVILEGES; -- Verify setup SHOW DATABASES; USE roster_control; SELECT @@character_set_database, @@collation_database; EXIT;
Update your .env file with the database credentials:
DB_HOST=localhost DB_PORT=3306 DB_NAME=roster_control DB_USER=roster_user # or 'root' if using Option A DB_PASSWORD=your_secure_password_hereTest Database Connection:
npm run test:db
Run migrations (happens automatically on startup):
npm start
-
Discord Bot Setup
- Create application at https://discord.com/developers/applications
- Create bot and copy token to
.env - Invite bot to server with appropriate permissions:
- Send Messages
- Use Slash Commands
- Embed Links
- Read Message History
/onduty <admin_id>- Designate admin as on-duty/offduty <admin_id>- Remove admin from on-duty status
/whitelist add <player_id> type:<source>- Add player to whitelist/whitelist remove <player_id>- Remove player from whitelist/whitelist list- Display current roster
/activity <player_id>- Show player's recent activity
/ping- Test bot connectivity/help- Show available commands
Commands are restricted based on roles and on-duty status:
- Whitelist commands: Require on-duty admin status
- Admin commands: Require admin role
- General commands: Available to all users
- Players: Player ID, Username, Roster Status, Activity History
- Admins: Admin ID, On-Duty Status, Duty History
- Servers: Server ID, Name, Connection Details
- AuditLog: Action tracking with timestamps and details
Database schema is managed through Umzug migrations that run automatically on startup. Migration files are located in /migrations/.
- Create new Node.js application
- Upload project files
- Configure
.envfile - Set startup command:
npm start - Allocate sufficient memory (recommended: 512MB+)
# Production start
npm run start
# Development with auto-restart
npm run dev
# Development with debugger
npm run dev:debug
# Deploy commands to development servers
npm run deploy:commands:dev
# Deploy commands to production servers
npm run deploy:commands:prodWinston logging is configured with multiple levels:
- Error: Critical errors and exceptions
- Warn: Non-critical issues
- Info: General application flow
- Debug: Detailed debugging information
Logs are written to both console and file (logs/combined.log).
- Database connection status
- Discord bot connectivity
- SquadJS connection status
- BattleMetrics API availability
- Command response times
- Database query performance
- Memory usage
- Event processing rates
Bot not responding to commands
- Verify Discord token and permissions
- Check bot is online in Discord
- Ensure slash commands are registered
Database connection errors
- Verify MariaDB is running
- Check connection credentials in
.env - Ensure database exists and user has permissions
SquadJS connection issues
- Verify Squad server RCON settings
- Check firewall rules for RCON port
- Confirm RCON password is correct
BattleMetrics API errors
- Verify API token is valid
- Check rate limiting (max 60 requests/minute)
- Ensure server ID is correct
- Application logs:
logs/combined.log - Error logs:
logs/error.log - Database logs: Check MariaDB error log
roster-control/
├── commands/ # Discord slash commands
├── events/ # Discord bot events
├── models/ # Sequelize database models
├── migrations/ # Database migration files
├── utils/ # Utility functions
├── logs/ # Log files
├── config/ # Configuration files
└── index.js # Main application entry
- Create command file in
/commands/ - Follow existing command structure
- Register command in command handler
- Test with
/pingequivalent
- Create migration file in
/migrations/ - Update corresponding Sequelize model
- Test migration up/down functionality
- Document schema changes
- Environment Variables: Store sensitive data in
.env(gitignored) - Database Access: Use dedicated database user with minimal permissions
- API Tokens: Regularly rotate BattleMetrics and Discord tokens
- RCON Security: Restrict RCON access to trusted IPs only
For issues or questions:
- Check logs for error details
- Verify configuration settings
- Test individual components (database, Discord, SquadJS)
- Review recent changes in audit log
Internal use only - not for public distribution.