mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-04 04:00:18 +03:00
First pony commit
This commit is contained in:
parent
82304b18eb
commit
9259811d96
|
@ -92,8 +92,8 @@ If you've installed Telethon via pip, launch an interactive python3 session and
|
|||
True
|
||||
>>>
|
||||
>>> if not client.is_user_authorized():
|
||||
>>> client.send_code_request('+34600000000')
|
||||
>>> client.sign_in('+34600000000', input('Enter code: '))
|
||||
>>> client.sign_in(code='+34600000000')
|
||||
>>> client.sign_in(code=input('Enter code: '))
|
||||
...
|
||||
>>> # Now you can use the connected client as you wish
|
||||
>>> dialogs, entities = client.get_dialogs(10)
|
||||
|
|
|
@ -32,8 +32,8 @@ Creating a client
|
|||
client.connect()
|
||||
|
||||
# If you already have a previous 'session_name.session' file, skip this.
|
||||
client.send_code_request(phone)
|
||||
me = client.sign_in(phone, 77777) # Put whatever code you received here.
|
||||
client.sign_in(phone=phone)
|
||||
me = client.sign_in(code=77777) # Put whatever code you received here.
|
||||
|
||||
|
||||
Doing stuff
|
||||
|
|
|
@ -230,7 +230,7 @@ class TelegramBareClient:
|
|||
|
||||
# region Working with different Data Centers
|
||||
|
||||
def _get_dc(self, dc_id, ipv6=True, cdn=False):
|
||||
def _get_dc(self, dc_id, ipv6=False, cdn=False):
|
||||
"""Gets the Data Center (DC) associated to 'dc_id'"""
|
||||
if not self.dc_options:
|
||||
raise ConnectionError(
|
||||
|
|
|
@ -124,7 +124,8 @@ class TelegramClient(TelegramBareClient):
|
|||
system_lang_code if system_lang_code else self.session.lang_code
|
||||
|
||||
self._updates_thread = None
|
||||
self._phone_code_hashes = {}
|
||||
self._phone_code_hash = None
|
||||
self._phone_number = None
|
||||
|
||||
# Uploaded files cache so subsequent calls are instant
|
||||
self._upload_cache = {}
|
||||
|
@ -257,8 +258,9 @@ class TelegramClient(TelegramBareClient):
|
|||
"""Sends a code request to the specified phone number"""
|
||||
result = self(
|
||||
SendCodeRequest(phone_number, self.api_id, self.api_hash))
|
||||
|
||||
self._phone_code_hashes[phone_number] = result.phone_code_hash
|
||||
self._phone_number = phone_number
|
||||
self._phone_code_hash = result.phone_code_hash
|
||||
return result
|
||||
|
||||
def sign_in(self, phone_number=None, code=None,
|
||||
password=None, bot_token=None):
|
||||
|
@ -275,8 +277,11 @@ class TelegramClient(TelegramBareClient):
|
|||
|
||||
If the login succeeds, the logged in user is returned.
|
||||
"""
|
||||
if phone_number and code:
|
||||
if phone_number not in self._phone_code_hashes:
|
||||
|
||||
if phone_number:
|
||||
return self.send_code_request(phone_number)
|
||||
elif code:
|
||||
if self._phone_number == None:
|
||||
raise ValueError(
|
||||
'Please make sure to call send_code_request first.')
|
||||
|
||||
|
@ -284,7 +289,7 @@ class TelegramClient(TelegramBareClient):
|
|||
if isinstance(code, int):
|
||||
code = str(code)
|
||||
result = self(SignInRequest(
|
||||
phone_number, self._phone_code_hashes[phone_number], code
|
||||
self._phone_number, self._phone_code_hash, code
|
||||
))
|
||||
|
||||
except (PhoneCodeEmptyError, PhoneCodeExpiredError,
|
||||
|
@ -312,8 +317,8 @@ class TelegramClient(TelegramBareClient):
|
|||
"""Signs up to Telegram. Make sure you sent a code request first!"""
|
||||
result = self(
|
||||
SignUpRequest(
|
||||
phone_number=phone_number,
|
||||
phone_code_hash=self._phone_code_hashes[phone_number],
|
||||
phone_number=self._phone_number,
|
||||
phone_code_hash=self._phone_code_hash,
|
||||
phone_code=code,
|
||||
first_name=first_name,
|
||||
last_name=last_name))
|
||||
|
|
Loading…
Reference in New Issue
Block a user