mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
TelegramClient: Remove redundant check for adding update handlers
Adding update handlers when not authorized makes no negative consequences. Also, check was implemented badly - update handlers can be added after logout/disconnect, for example.
This commit is contained in:
parent
b7ed6d9ec1
commit
2ff419a5e7
|
@ -79,9 +79,6 @@ class TelegramClient:
|
|||
self.sender = None
|
||||
self.phone_code_hashes = {}
|
||||
|
||||
# We need to be signed in before we can listen for updates
|
||||
self.signed_in = False
|
||||
|
||||
# endregion
|
||||
|
||||
# region Connecting
|
||||
|
@ -121,8 +118,6 @@ class TelegramClient:
|
|||
# although many other options are available!
|
||||
self.dc_options = result.dc_options
|
||||
|
||||
# We're signed in if we're authorized
|
||||
self.signed_in = self.is_user_authorized()
|
||||
return True
|
||||
except RPCError as error:
|
||||
print('Could not stabilise initial connection: {}'.format(error))
|
||||
|
@ -241,9 +236,6 @@ class TelegramClient:
|
|||
self.session.user = result.user
|
||||
self.session.save()
|
||||
|
||||
# Now that we're authorized, set the signed_in flag
|
||||
# to True so update handlers can be added
|
||||
self.signed_in = True
|
||||
return True
|
||||
|
||||
def sign_up(self, phone_number, code, first_name, last_name=''):
|
||||
|
@ -728,9 +720,9 @@ class TelegramClient:
|
|||
def add_update_handler(self, handler):
|
||||
"""Adds an update handler (a function which takes a TLObject,
|
||||
an update, as its parameter) and listens for updates"""
|
||||
if not self.signed_in:
|
||||
raise ValueError(
|
||||
"You cannot add update handlers until you've signed in.")
|
||||
if not self.sender:
|
||||
raise RuntimeError(
|
||||
"You should connect at least once to add update handlers.")
|
||||
|
||||
self.sender.add_update_handler(handler)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user