import nio import sys class Matrix: def __init__(self, app): self.app = app self.client = nio.AsyncClient( app.config.matrix_homeserver_url, app.config.matrix_full_bot_id, ) self.client.add_event_callback(self.on_message, nio.RoomMessage) async def prepare(self): await self.client.login(self.app.config.matrix_bot_password) async def finish(self): await self.client.close() async def run(self): await self.client.sync_forever(timeout=30000) async def on_message(self, room, event): print(room, event, file=sys.stderr)