24/7 room
Reference 24/7 room
The complete football bot, built only with the library. Use it as a base for yours.
The repository includes apps/bonk-room, a football bot that runs 24 hours a day. It was built only with the bonktools library, so it works as a practical example of everything the lib offers: sessions with reconnection, events, teams, lock, anti-AFK and match sync.
What it does
- Creates and maintains a football room, recreating it if it goes down.
- Builds the teams automatically, always with the same size.
- Picks captains and lets the captain choose players by typing the number in chat.
- Rotates the champion at the end of each match: the winner stays on blue.
- Handles AFK (
!afkand idle detection) and never picks someone who is AFK. - Locks the teams: only the bot moves players.
- Shows the match to late joiners without restarting it.
The complete rules are in Teams, captains and picking.
How to run
git clone https://github.com/brenoluizdev/BonkTools-Core-repo.git
cd BonkTools-Core-repo
pnpm install
pnpm --filter @bonktools/core build
cd apps/bonk-room
cp .env.example .env # fill in BONK_USERNAME and BONK_PASSWORD
cp bonk-room.example.json bonk-room.json # adjust the room name, mode and rounds
pnpm devThe room link shows up in the log (sala ativa).
Environment variables
| Variable | Description |
|---|---|
BONK_USERNAME, BONK_PASSWORD | The bonk.io account that hosts the room |
BONK_GAMEMODE | football (default), classic, arrows, death arrows, grapple or vtol |
BONK_MAXTEAMSIZE | Players per team (1 = 1v1, 2 = 2v2...). Basis of every team calculation. |
BONK_ROUNDS | Rounds per match |
BONK_INITIAL_STATE | Fallback IS blob (see Matches and IS blob) |
BONK_BLOB_CACHE_PATH | Path of the per-map blob cache |
NODE_ENV | development (formatted logs) or production (JSON, ideal for PM2) |
Room configuration
bonk-room.json:
{
"room": {
"id": "my-room",
"name": "My Bonk Room",
"password": "",
"maxPlayers": 6,
"mode": "b",
"rounds": 3,
"hidden": true,
"map": "<map LZ-String blob>"
},
"throttle": {
"maxConcurrentRooms": 1,
"roomCreationDelayMs": 3000,
"roomCreationJitterMs": 2000
},
"initialStates": { "2": "<IS blob 1v1>", "4": "<IS blob 2v2>" }
}Code structure
| File | Role |
|---|---|
src/index.ts | Logger, configuration, BonkSession with reconnection |
src/example-bot.ts | ExampleBot: wires room events to the controller |
src/pick/PickController.ts | Teams, captains, picking, rotation, AFK and commands |
src/config.ts | Validation (zod) of the configuration and environment reading |
examples/antiAfk.ts | Anti-AFK in ~10 lines using only the lib |
Tests
pnpm --filter bonk-room testBesides the team-flow and AFK scenarios, there is a fuzz with hundreds of random sequences of joins, leaves, AFK and picks. At every match start it checks that the teams have the same size, never exceed maxTeamSize and have nobody AFK on the field.
Production
Run with NODE_ENV=production for JSON logs and use a process manager (PM2, systemd or a container) to restart the process if it dies. BonkSession already takes care of recreating the room when it goes down; the manager takes care of the process.