mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 21:10:29 +00:00
Raise on phone/network migrate if authorized
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user