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"""
2hello_world.py
3
4This example shows how to make a bot that joins all the rooms in the lobby,
5and messages "Hello, world!" to all rooms.
6"""
7
8
9from talkomatic import Bot, RoomType # import the Bot, RoomType class from the talkomatic package
10
11
12bot = 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
16async 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
26async 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
30bot.run("Hello", "world!")
31# this'll keep running until you halt the program with ctrl+c!
None on_room_join(*args)
None on_connect()