-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrooms_watcher.py
More file actions
35 lines (27 loc) · 942 Bytes
/
rooms_watcher.py
File metadata and controls
35 lines (27 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import asyncio
from bonkbot.core.api import BonkAPI
from bonkbot.types import Mode
"""
This example implements a room watcher.
It monitors all active rooms and logs only available VTOL rooms.
I use BonkAPI instead of BonkBot because we need only an API without the need for room joining.
"""
bonk_api = BonkAPI()
async def main() -> None:
print('Rooms watcher started')
previous_rooms = set()
while True:
current_rooms = await bonk_api.fetch_rooms()
current_rooms = {
room
for room in current_rooms
if room.mode == Mode.VTOL
and room.players < room.max_players
and not room.has_password
}
new_rooms = current_rooms - previous_rooms
for room in new_rooms:
print(f'New VTOL room: {room.name}')
previous_rooms = current_rooms
await asyncio.sleep(30)
bonk_api.event_loop.run_until_complete(main())