Handle sync error and quit if initial sync fails
This commit is contained in:
parent
549fa08918
commit
1291e324ce
13
bot.py
13
bot.py
|
@ -22,7 +22,7 @@ from io import BytesIO
|
|||
from PIL import Image
|
||||
|
||||
import requests
|
||||
from nio import AsyncClient, InviteEvent, JoinError, RoomMessageText, MatrixRoom, LoginError, RoomMemberEvent, RoomVisibility, RoomPreset, RoomCreateError, RoomResolveAliasResponse, UploadError, UploadResponse
|
||||
from nio import AsyncClient, InviteEvent, JoinError, RoomMessageText, MatrixRoom, LoginError, RoomMemberEvent, RoomVisibility, RoomPreset, RoomCreateError, RoomResolveAliasResponse, UploadError, UploadResponse, SyncError
|
||||
|
||||
# Couple of custom exceptions
|
||||
|
||||
|
@ -544,18 +544,19 @@ class Bot:
|
|||
self.logger.info(f'All modules stopped.')
|
||||
|
||||
async def run(self):
|
||||
await self.client.sync()
|
||||
sync_response = await self.client.sync()
|
||||
if type(sync_response) == SyncError:
|
||||
self.logger.error(f"Received Sync Error when trying to do initial sync! Error message is: %s", sync_response.message)
|
||||
else:
|
||||
for roomid, room in self.client.rooms.items():
|
||||
self.logger.info(f"Bot is on '{room.display_name}'({roomid}) with {len(room.users)} users")
|
||||
if len(room.users) == 1 and self.leave_empty_rooms:
|
||||
self.logger.info(f'Room {roomid} has no other users - leaving it.')
|
||||
self.logger.info(await self.client.room_leave(roomid))
|
||||
|
||||
self.start()
|
||||
|
||||
self.poll_task = asyncio.get_event_loop().create_task(self.poll_timer())
|
||||
|
||||
if self.client.logged_in:
|
||||
self.start()
|
||||
self.poll_task = asyncio.get_event_loop().create_task(self.poll_timer())
|
||||
self.load_settings(self.get_account_data())
|
||||
self.client.add_event_callback(self.message_cb, RoomMessageText)
|
||||
self.client.add_event_callback(self.invite_cb, (InviteEvent,))
|
||||
|
|
Loading…
Reference in New Issue