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
hello_world.py
Go to the documentation of this file.
1
"""
2
hello_world.py
3
4
This example shows how to make a bot that joins all the rooms in the lobby,
5
and messages "Hello, world!" to all rooms.
6
"""
7
8
9
from
talkomatic
import
Bot, RoomType
# import the Bot, RoomType class from the talkomatic package
10
11
12
bot =
Bot
()
# create a new Bot instance
13
14
# with this decorator, the function will be called when the bot finishes connecting to the server
15
@bot.on_connect
16
async def
on_connect
() -> None:
17
# we find the first non-full public room, we join it, and say "Hello, world!"
18
for
room
in
bot.rooms:
19
if
not
room.is_full
and
room.room_type == RoomType.PUBLIC:
20
await bot.join_room(room)
21
return
22
print(
"We didn't find any non-full rooms to join. :("
)
# :(
23
await bot.disconnect()
24
25
@bot.on_room_join
26
async def
on_room_join
(*args) -> None:
# we can put *args because we don't care about the arguments here
27
await bot.send_message(
"Hello, world!"
)
# when we have joined a room, we send the message!
28
29
# we're ready to go! let's run the bot with a username and location
30
bot.run(
"Hello"
,
"world!"
)
31
# this'll keep running until you halt the program with ctrl+c!
talkomatic.bot.Bot
Definition
bot.py:16
hello_world.on_room_join
None on_room_join(*args)
Definition
hello_world.py:26
hello_world.on_connect
None on_connect()
Definition
hello_world.py:16
examples
hello_world.py
Generated by
1.13.2