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/__main__.py
2023-01-08 17:57:21 +04:00

41 lines
1.1 KiB
Python

import asyncio
import os
import sys
import aiogram as telegram
import nio as matrix
MATRIX_HOMESERVER_URL = os.environ['MATRIX_HOMESERVER_URL']
MATRIX_FULL_USER_ID = os.environ['MATRIX_FULL_USER_ID']
MATRIX_PASSWORD = os.environ['MATRIX_PASSWORD']
TELEGRAM_BOT_TOKEN = os.environ['TELEGRAM_BOT_TOKEN']
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(matrix_client), telegram_loop())
finally:
if matrix_client:
await matrix_client.close()
async def matrix_loop(client):
await client.sync_forever(timeout=30000)
async def telegram_loop():
print(456, file=sys.stderr)
async def matrix_on_message(room, event):
print(room, event, file=sys.stderr)
if __name__ == '__main__':
asyncio.run(main())