From daf0e9133469f5f5e32e8e835a958cb11ef0e6db Mon Sep 17 00:00:00 2001 From: test Date: Thu, 2 Nov 2023 23:09:40 +0800 Subject: [PATCH] Scripts need to be fully automated. Scripts hate user input. This prevents script automation. We need to go back in time rather than continue typing. --- telethon/client/auth.py | 6 +++++- telethon/client/telegrambaseclient.py | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/telethon/client/auth.py b/telethon/client/auth.py index 9ca5b458..5c9cfe06 100644 --- a/telethon/client/auth.py +++ b/telethon/client/auth.py @@ -139,6 +139,7 @@ class AuthMethods: # enables the library to warn users trying to login to a different # account. See #1172. me = await self.get_me() + if me is not None: # The warnings here are on a best-effort and may fail. if bot_token: @@ -158,7 +159,10 @@ class AuthMethods: ) return self - + else: + if self.force_session: + self.login_failed("falied") + return if not bot_token: # Turn the callable into a valid phone number (or bot token) while callable(phone): diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index dd127654..8eb3e293 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -27,7 +27,6 @@ if typing.TYPE_CHECKING: _base_log = logging.getLogger(__base_name__) - # In seconds, how long to wait before disconnecting a exported sender. _DISCONNECT_EXPORTED_AFTER = 60 @@ -260,7 +259,9 @@ class TelegramBaseClient(abc.ABC): base_logger: typing.Union[str, logging.Logger] = None, receive_updates: bool = True, catch_up: bool = False, - entity_cache_limit: int = 5000 + entity_cache_limit: int = 5000, + force_session: bool = False, + login_failed=None ): if not api_id or not api_hash: raise ValueError( @@ -325,6 +326,10 @@ class TelegramBaseClient(abc.ABC): self.api_id = int(api_id) self.api_hash = api_hash + self.force_session = force_session + if self.force_session: + self.login_failed=login_failed + # Current proxy implementation requires `sock_connect`, and some # event loops lack this method. If the current loop is missing it, # bail out early and suggest an alternative. @@ -458,7 +463,6 @@ class TelegramBaseClient(abc.ABC): auto_reconnect_callback=self._handle_auto_reconnect ) - # endregion # region Properties