Compare commits
No commits in common. "2972cca58290ca365c13c78c4addd62f91c02446" and "4e3266588228fb13abeaddbb5d27baf45d4d882c" have entirely different histories.
2972cca582
...
4e32665882
1 changed files with 4 additions and 12 deletions
16
mirrortea
16
mirrortea
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import sys
|
|
||||||
|
|
||||||
import aiogram as telegram
|
import aiogram as telegram
|
||||||
import nio as matrix
|
import nio as matrix
|
||||||
|
@ -15,27 +14,20 @@ async def main():
|
||||||
try:
|
try:
|
||||||
matrix_client = \
|
matrix_client = \
|
||||||
matrix.AsyncClient(MATRIX_HOMESERVER_URL, MATRIX_FULL_USER_ID)
|
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)
|
await matrix_client.login(MATRIX_PASSWORD)
|
||||||
|
|
||||||
telegram_client = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
|
telegram_client = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
|
||||||
|
|
||||||
await asyncio.gather(matrix_loop(matrix_client), telegram_loop())
|
await asyncio.gather(matrix_loop(), telegram_loop())
|
||||||
finally:
|
finally:
|
||||||
if matrix_client:
|
if matrix_client:
|
||||||
await matrix_client.close()
|
await matrix_client.close()
|
||||||
|
|
||||||
async def matrix_loop(client):
|
async def matrix_loop():
|
||||||
await client.sync_forever(timeout=30000)
|
print(123)
|
||||||
|
|
||||||
async def telegram_loop():
|
async def telegram_loop():
|
||||||
print(456, file=sys.stderr)
|
print(456)
|
||||||
|
|
||||||
async def matrix_on_message(room, event):
|
|
||||||
print(room, event, file=sys.stderr)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue