Receiving shoutbox events¶
It is possible to receive events on a shoutbox channel, by:
Initalizing a client with user credentials, see Initializing the client for more information;
Getting the channel from which to receive events using
Shout.get_channel()
;Iterating over the obtained
Channel
instance to obtainEvent
instances.
For example, if we only want to read messages:
from __future__ import annotations
import asyncio
from planetcasio.client import Client
from planetcasio.shout import MessagePosted
async def main() -> None:
async with Client(auth=("<username>", "<password>")) as client:
channel = await client.shout.get_channel("hs", fmt="bbcode")
async for event in channel:
if isinstance(event, MessagePosted):
print(f"{event.username}: {event.content}")
asyncio.run(main())