Update matrix/MTbot.py
This commit is contained in:
@@ -168,7 +168,23 @@ async def main() -> None:
|
||||
await client.login(MATRIX_PASSWORD)
|
||||
await log_activity(f"Logged in as {MATRIX_USER}")
|
||||
client.add_event_callback(lambda room, event: process_message(client, room, event), RoomMessageText)
|
||||
await client.sync_forever(timeout=30000)
|
||||
|
||||
while True:
|
||||
try:
|
||||
await client.sync_forever(timeout=30000, full_state=True)
|
||||
except (aiohttp.ClientError, asyncio.TimeoutError, aiohttp.ClientPayloadError) as e:
|
||||
await log_activity(f"Sync error: {str(e)}. Reconnecting in 10 seconds...")
|
||||
await asyncio.sleep(10)
|
||||
except Exception as e:
|
||||
await log_activity(f"Unexpected error: {str(e)}. Restarting in 30 seconds...")
|
||||
await asyncio.sleep(30)
|
||||
try:
|
||||
await client.close()
|
||||
except:
|
||||
pass
|
||||
client = AsyncClient(MATRIX_HOMESERVER, MATRIX_USER)
|
||||
await client.login(MATRIX_PASSWORD)
|
||||
client.add_event_callback(lambda room, event: process_message(client, room, event), RoomMessageText)
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
|
||||
Reference in New Issue
Block a user