mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-10 18:59:33 +00:00
Add a custom SentCode type
This commit is contained in:
@@ -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 [])
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user