Add a custom SentCode type

This commit is contained in:
Lonami Exo
2022-02-16 12:23:19 +01:00
parent 4258ce2bc8
commit df0e710fa1
5 changed files with 138 additions and 5 deletions

View File

@@ -335,7 +335,7 @@ async def _replace_session_state(self, *, save=True, **changes):
async def send_code_request(
self: 'TelegramClient',
phone: str) -> '_tl.auth.SentCode':
phone: str) -> 'SentCode':
result = None
phone = utils.parse_phone(phone) or self._phone
phone_hash = self._phone_code_hash.get(phone)
@@ -358,7 +358,7 @@ async def send_code_request(
self._phone = phone
return result
return _custom.SentCode._new(result)
async def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> _custom.QRLogin:
qr_login = _custom.QRLogin(self, ignored_ids or [])

View File

@@ -504,7 +504,7 @@ class TelegramClient:
@forward_call(auth.send_code_request)
async def send_code_request(
self: 'TelegramClient',
phone: str) -> '_tl.auth.SentCode':
phone: str) -> 'SentCode':
"""
Sends the Telegram code needed to login to the given phone number.
@@ -513,14 +513,24 @@ class TelegramClient:
The phone to which the code will be sent.
Returns
An instance of :tl:`SentCode`.
An instance of `SentCode`.
Example
.. code-block:: python
phone = '+34 123 123 123'
sent = await client.send_code_request(phone)
print(sent)
print(sent.type)
# Wait before resending sent.next_type, if any
if sent.next_type:
await asyncio.sleep(sent.timeout or 0)
resent = await client.send_code_request(phone)
print(sent.type)
# Checking the code locally
code = input('Enter code: ')
print('Code looks OK:', resent.check(code))
"""
@forward_call(auth.qr_login)