diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index 2a5a41fa..b90bb98a 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -192,6 +192,7 @@ class TelegramBaseClient(abc.ABC): # TODO maybe we can have ._last_request instead if any req works? self._last_state = datetime.now() self._state_delay = timedelta(hours=1) + self._state = None # Some further state for subclasses self._event_builders = [] diff --git a/telethon/client/users.py b/telethon/client/users.py index 978b77ce..dda09d75 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -35,8 +35,9 @@ class UserMethods(TelegramBaseClient): raise except (errors.PhoneMigrateError, errors.NetworkMigrateError, errors.UserMigrateError) as e: - should_raise = isinstance(errors.PhoneMigrateError, - errors.NetworkMigrateError) + should_raise = isinstance(e, ( + errors.PhoneMigrateError, errors.NetworkMigrateError + )) if should_raise and await self.is_user_authorized(): raise await self._switch_dc(e.new_dc) @@ -79,9 +80,14 @@ class UserMethods(TelegramBaseClient): """ Returns ``True`` if the user is authorized. """ - if self._authorized is None: - self._authorized = await self.get_me() is not None - return self._authorized + if self._self_input_peer is not None or self._state is not None: + return True + + try: + self._state = await self(functions.updates.GetStateRequest()) + return True + except errors.RPCError: + return False async def get_entity(self, entity): """