Fix is_connected intent and calls from 6226fa9

This commit is contained in:
Lonami Exo 2019-06-15 20:54:47 +02:00
parent 80e86e98ff
commit 0b69d7fd7b
4 changed files with 7 additions and 6 deletions

View File

@ -137,7 +137,7 @@ class AuthMethods(MessageParseMethods, UserMethods):
async def _start( async def _start(
self, phone, password, bot_token, force_sms, self, phone, password, bot_token, force_sms,
code_callback, first_name, last_name, max_attempts): code_callback, first_name, last_name, max_attempts):
if not self.is_connected(): if not self.is_connected:
await self.connect() await self.connect()
if await self.is_user_authorized(): if await self.is_user_authorized():

View File

@ -432,6 +432,7 @@ class TelegramBaseClient(abc.ABC):
self._updates_handle = self._loop.create_task(self._update_loop()) self._updates_handle = self._loop.create_task(self._update_loop())
@property
def is_connected(self: 'TelegramClient') -> bool: def is_connected(self: 'TelegramClient') -> bool:
""" """
Returns ``True`` if the user has connected. Returns ``True`` if the user has connected.
@ -441,11 +442,11 @@ class TelegramBaseClient(abc.ABC):
Example Example
.. code-block:: python .. code-block:: python
while client.is_connected(): while client.is_connected:
await asyncio.sleep(1) await asyncio.sleep(1)
""" """
sender = getattr(self, '_sender', None) sender = getattr(self, '_sender', None)
return sender and sender.is_connected() return sender and sender.is_connected
def disconnect(self: 'TelegramClient'): def disconnect(self: 'TelegramClient'):
""" """

View File

@ -323,7 +323,7 @@ class UpdateMethods(UserMethods):
async def _update_loop(self: 'TelegramClient'): async def _update_loop(self: 'TelegramClient'):
# Pings' ID don't really need to be secure, just "random" # Pings' ID don't really need to be secure, just "random"
rnd = lambda: random.randrange(-2**63, 2**63) rnd = lambda: random.randrange(-2**63, 2**63)
while self.is_connected(): while self.is_connected:
try: try:
await asyncio.wait_for( await asyncio.wait_for(
self.disconnected, timeout=60, loop=self._loop self.disconnected, timeout=60, loop=self._loop
@ -425,7 +425,7 @@ class UpdateMethods(UserMethods):
) )
break break
except Exception as e: except Exception as e:
if not isinstance(e, asyncio.CancelledError) or self.is_connected(): if not isinstance(e, asyncio.CancelledError) or self.is_connected:
name = getattr(callback, '__name__', repr(callback)) name = getattr(callback, '__name__', repr(callback))
self._log[__name__].exception('Unhandled exception on %s', self._log[__name__].exception('Unhandled exception on %s',
name) name)

View File

@ -228,7 +228,7 @@ class App(tkinter.Tk):
""" """
Sends a message. Does nothing if the client is not connected. Sends a message. Does nothing if the client is not connected.
""" """
if not self.cl.is_connected(): if not self.cl.is_connected:
return return
# The user needs to configure a chat where the message should be sent. # The user needs to configure a chat where the message should be sent.