This repository has been archived on 2023-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
MirrorTea/mirrortea/messengers/matrix.py

24 lines
632 B
Python
Raw Normal View History

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)