talkomatic.py 0.1.2
An easy-to-use Python versatile wrapper for the Talkomatic Bot interface ensuring best practices for making bots, and handling the REST API.
 
Loading...
Searching...
No Matches
create_room.py
Go to the documentation of this file.
1"""
2create_room.py
3
4This example shows how to make a bot that creates its own room,
5and then joins it.
6"""
7
8
9from talkomatic import Bot # import the Bot class from the talkomatic package
10from talkomatic.dataclasses.room import RoomType, RoomLayoutType
11# we import the RoomType and RoomLayoutType objects to describe the room privacy type, and layout type
12
13
14bot = Bot() # create a new Bot instance
15
16# with this decorator, the function will be called when the bot finishes connecting to the server
17@bot.on_connect
18async def on_connect() -> None:
19 # we create a room with the name "My awesome room!", it's public, and it's a horizontal layout
20 await bot.create_room("My awesome room!", RoomType.PUBLIC, RoomLayoutType.HORIZONTAL)
21 # when the room is created, the on_room_creation event will be called
22
23@bot.on_room_creation
24async def on_room_creation(room_id: int) -> None:
25 # our awesome room has been created, so we'll join it!
26 await bot.join_room(room_id)
27
28@bot.on_room_join
29async def on_room_join(*args) -> None: # we can put *args because we don't care about the arguments here
30 # we joined our awesome room, and it'd be a good idea to greet our fellow users!
31 await bot.send_message("""Welcome to my awesome room!
32
33This is an automated message from a bot for the talkomatic.py library!
34To the developer of the bot, remember that you can press Ctrl+C in the
35terminal to disconnect your bot. :catjam:""")
36
37# we're ready to go! let's run the bot with a username and location
38bot.run("My Room", "Bot")
39# this'll keep running until you halt the program with ctrl+c!
None on_room_creation(int room_id)
None on_room_join(*args)
None on_connect()