From 8b57552944ebba732333d9a48ebd35738950baec Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 8 Jan 2023 16:46:08 +0400 Subject: [PATCH 1/2] Add Matrix callback --- mirrortea | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mirrortea b/mirrortea index 81c4c7a..1ac046d 100755 --- a/mirrortea +++ b/mirrortea @@ -14,20 +14,27 @@ async def main(): try: matrix_client = \ matrix.AsyncClient(MATRIX_HOMESERVER_URL, MATRIX_FULL_USER_ID) + + matrix_client.add_event_callback(matrix_on_message, + matrix.RoomMessage) + await matrix_client.login(MATRIX_PASSWORD) telegram_client = telegram.Bot(token=TELEGRAM_BOT_TOKEN) - await asyncio.gather(matrix_loop(), telegram_loop()) + await asyncio.gather(matrix_loop(matrix_client), telegram_loop()) finally: if matrix_client: await matrix_client.close() -async def matrix_loop(): - print(123) +async def matrix_loop(client): + await client.sync_forever(timeout=30000) async def telegram_loop(): print(456) +async def matrix_on_message(room, event): + print(room, event) + if __name__ == '__main__': asyncio.run(main()) From 2972cca58290ca365c13c78c4addd62f91c02446 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 8 Jan 2023 16:55:14 +0400 Subject: [PATCH 2/2] Print to stderr --- mirrortea | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mirrortea b/mirrortea index 1ac046d..b6177f2 100755 --- a/mirrortea +++ b/mirrortea @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import asyncio +import sys import aiogram as telegram import nio as matrix @@ -31,10 +32,10 @@ async def matrix_loop(client): await client.sync_forever(timeout=30000) async def telegram_loop(): - print(456) + print(456, file=sys.stderr) async def matrix_on_message(room, event): - print(room, event) + print(room, event, file=sys.stderr) if __name__ == '__main__': asyncio.run(main())