Add Matrix callback
This commit is contained in:
parent
4e32665882
commit
8b57552944
13
mirrortea
13
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())
|
||||
|
|
Reference in a new issue