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
"""
2
create_room.py
3
4
This example shows how to make a bot that creates its own room,
5
and then joins it.
6
"""
7
8
9
from
talkomatic
import
Bot
# import the Bot class from the talkomatic package
10
from
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
14
bot =
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
18
async 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
24
async 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
29
async 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
33
This is an automated message from a bot for the talkomatic.py library!
34
To the developer of the bot, remember that you can press Ctrl+C in the
35
terminal to disconnect your bot. :catjam:"""
)
36
37
# we're ready to go! let's run the bot with a username and location
38
bot.run(
"My Room"
,
"Bot"
)
39
# this'll keep running until you halt the program with ctrl+c!
talkomatic.bot.Bot
Definition
bot.py:16
create_room.on_room_creation
None on_room_creation(int room_id)
Definition
create_room.py:24
create_room.on_room_join
None on_room_join(*args)
Definition
create_room.py:29
create_room.on_connect
None on_connect()
Definition
create_room.py:18
talkomatic.dataclasses.room
Definition
room.py:1
examples
create_room.py
Generated by
1.13.2