mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-29 21:03:45 +03:00
Fix-up isinstance/is_user_authorized from 06cdf1f
This commit is contained in:
parent
b7286be3b0
commit
509fba8bcc
|
@ -192,6 +192,7 @@ class TelegramBaseClient(abc.ABC):
|
||||||
# TODO maybe we can have ._last_request instead if any req works?
|
# TODO maybe we can have ._last_request instead if any req works?
|
||||||
self._last_state = datetime.now()
|
self._last_state = datetime.now()
|
||||||
self._state_delay = timedelta(hours=1)
|
self._state_delay = timedelta(hours=1)
|
||||||
|
self._state = None
|
||||||
|
|
||||||
# Some further state for subclasses
|
# Some further state for subclasses
|
||||||
self._event_builders = []
|
self._event_builders = []
|
||||||
|
|
|
@ -35,8 +35,9 @@ class UserMethods(TelegramBaseClient):
|
||||||
raise
|
raise
|
||||||
except (errors.PhoneMigrateError, errors.NetworkMigrateError,
|
except (errors.PhoneMigrateError, errors.NetworkMigrateError,
|
||||||
errors.UserMigrateError) as e:
|
errors.UserMigrateError) as e:
|
||||||
should_raise = isinstance(errors.PhoneMigrateError,
|
should_raise = isinstance(e, (
|
||||||
errors.NetworkMigrateError)
|
errors.PhoneMigrateError, errors.NetworkMigrateError
|
||||||
|
))
|
||||||
if should_raise and await self.is_user_authorized():
|
if should_raise and await self.is_user_authorized():
|
||||||
raise
|
raise
|
||||||
await self._switch_dc(e.new_dc)
|
await self._switch_dc(e.new_dc)
|
||||||
|
@ -79,9 +80,14 @@ class UserMethods(TelegramBaseClient):
|
||||||
"""
|
"""
|
||||||
Returns ``True`` if the user is authorized.
|
Returns ``True`` if the user is authorized.
|
||||||
"""
|
"""
|
||||||
if self._authorized is None:
|
if self._self_input_peer is not None or self._state is not None:
|
||||||
self._authorized = await self.get_me() is not None
|
return True
|
||||||
return self._authorized
|
|
||||||
|
try:
|
||||||
|
self._state = await self(functions.updates.GetStateRequest())
|
||||||
|
return True
|
||||||
|
except errors.RPCError:
|
||||||
|
return False
|
||||||
|
|
||||||
async def get_entity(self, entity):
|
async def get_entity(self, entity):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user