Change QrLogin to reduce room for error

This commit is contained in:
Lonami Exo
2022-02-24 11:07:13 +01:00
parent 48bd061562
commit d5cdda28c5
7 changed files with 115 additions and 57 deletions

View File

@@ -531,7 +531,7 @@ class TelegramClient:
"""
@forward_call(auth.qr_login)
async def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> _custom.QRLogin:
def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> _custom.QrLogin:
"""
Initiates the QR login procedure.
@@ -542,15 +542,18 @@ class TelegramClient:
whether it's the URL, using the token bytes directly, or generating
a QR code and displaying it by other means.
See the documentation for `QRLogin` to see how to proceed after this.
See the documentation for `QrLogin` to see how to proceed after this.
Note that the login completes once the context manager exits,
not after the ``wait`` method returns.
Arguments
ignored_ids (List[`int`]):
List of already logged-in user IDs, to prevent logging in
List of already logged-in session IDs, to prevent logging in
twice with the same user.
Returns
An instance of `QRLogin`.
An instance of `QrLogin`.
Example
.. code-block:: python
@@ -558,11 +561,16 @@ class TelegramClient:
def display_url_as_qr(url):
pass # do whatever to show url as a qr to the user
qr_login = await client.qr_login()
display_url_as_qr(qr_login.url)
async with client.qr_login() as qr_login:
display_url_as_qr(qr_login.url)
# Important! You need to wait for the login to complete!
await qr_login.wait()
# Important! You need to wait for the login to complete!
# If the context manager exits before the user logs in, the client won't be logged in.
try:
user = await qr_login.wait()
print('Welcome,', user.first_name)
except asyncio.TimeoutError:
print('User did not login in time')
"""
@forward_call(auth.log_out)