Raise on phone/network migrate if authorized

This commit is contained in:
Lonami Exo
2018-06-14 23:13:42 +02:00
parent c788e17c22
commit 06cdf1fdb0
2 changed files with 14 additions and 3 deletions

View File

@@ -35,6 +35,10 @@ class UserMethods(TelegramBaseClient):
raise
except (errors.PhoneMigrateError, errors.NetworkMigrateError,
errors.UserMigrateError) as e:
should_raise = isinstance(errors.PhoneMigrateError,
errors.NetworkMigrateError)
if should_raise and await self.is_user_authorized():
raise
await self._switch_dc(e.new_dc)
raise ValueError('Number of retries reached 0')
@@ -71,6 +75,14 @@ class UserMethods(TelegramBaseClient):
except errors.UnauthorizedError:
return None
async def is_user_authorized(self):
"""
Returns ``True`` if the user is authorized.
"""
if self._authorized is None:
self._authorized = await self.get_me() is not None
return self._authorized
async def get_entity(self, entity):
"""
Turns the given entity into a valid Telegram user or chat.