-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_example.py
44 lines (34 loc) · 1.51 KB
/
client_example.py
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
36
37
38
39
40
41
42
43
44
import asyncio
from kahoot import KahootClient
from kahoot.packets.impl.respond import RespondPacket
from kahoot.packets.server.game_over import GameOverPacket
from kahoot.packets.server.game_start import GameStartPacket
from kahoot.packets.server.question_end import QuestionEndPacket
from kahoot.packets.server.question_ready import QuestionReadyPacket
from kahoot.packets.server.question_start import QuestionStartPacket
client: KahootClient = KahootClient()
async def game_start(packet: GameStartPacket):
print(f"Game started: {packet}")
async def game_over(packet: GameOverPacket):
print(f"Game over: {packet}")
async def question_start(packet: QuestionStartPacket):
print(f"Question started: {packet}")
question_number: int = packet.game_block_index
await client.send_packet(RespondPacket(client.game_pin, 1, question_number))
async def question_end(packet: QuestionEndPacket):
print(f"Question ended: {packet}")
async def question_ready(packet: QuestionReadyPacket):
print(f"Question ready: {packet}")
async def main():
game_pin: int = int(input("Enter the game pin: "))
name: str = input("Enter your name: ")
# Register event handlers before joining the game
client.on("game_start", game_start)
client.on("game_over", game_over)
client.on("question_start", question_start)
client.on("question_end", question_end)
client.on("question_ready", question_ready)
# Join the game
await client.join_game(game_pin, name)
if __name__ == "__main__":
asyncio.run(main())