From 04695d365702e9adea20eb8f98db9dd6dcf70cff Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 27 Mar 2018 17:52:39 +0200 Subject: [PATCH] Update docs regarding 2FA and getting entities by ID --- readthedocs/extra/basic/creating-a-client.rst | 32 ++----------------- readthedocs/extra/basic/entities.rst | 23 ++++--------- 2 files changed, 10 insertions(+), 45 deletions(-) diff --git a/readthedocs/extra/basic/creating-a-client.rst b/readthedocs/extra/basic/creating-a-client.rst index 384ebd47..ba4adc28 100644 --- a/readthedocs/extra/basic/creating-a-client.rst +++ b/readthedocs/extra/basic/creating-a-client.rst @@ -150,35 +150,9 @@ The mentioned ``.start()`` method will handle this for you as well, but you must set the ``password=`` parameter beforehand (it won't be asked). If you don't have 2FA enabled, but you would like to do so through the library, -take as example the following code snippet: - - .. code-block:: python - - import os - from hashlib import sha256 - from telethon.tl.functions import account - from telethon.tl.types.account import PasswordInputSettings - - new_salt = client(account.GetPasswordRequest()).new_salt - salt = new_salt + os.urandom(8) # new random salt - - pw = 'secret'.encode('utf-8') # type your new password here - hint = 'hint' - - pw_salted = salt + pw + salt - pw_hash = sha256(pw_salted).digest() - - result = client(account.UpdatePasswordSettingsRequest( - current_password_hash=salt, - new_settings=PasswordInputSettings( - new_salt=salt, - new_password_hash=pw_hash, - hint=hint - ) - )) - -Thanks to `Issue 259 `_ -for the tip! +use :obj:`client.edit_2fa ` +for it. Be sure to know what you're doing when using this function and you +won't run into any problems. __ https://github.com/Anorov/PySocks#installation diff --git a/readthedocs/extra/basic/entities.rst b/readthedocs/extra/basic/entities.rst index c7e55524..ab04a165 100644 --- a/readthedocs/extra/basic/entities.rst +++ b/readthedocs/extra/basic/entities.rst @@ -32,7 +32,7 @@ you're able to just do this: # Dialogs are the "conversations you have open". # This method returns a list of Dialog, which # has the .entity attribute and other information. - dialogs = client.get_dialogs(limit=200) + dialogs = client.get_dialogs() # All of these work and do the same. lonami = client.get_entity('lonami') @@ -44,27 +44,18 @@ you're able to just do this: contact = client.get_entity('+34xxxxxxxxx') friend = client.get_entity(friend_id) - # Using Peer/InputPeer (note that the API may return these) - # users, chats and channels may all have the same ID, so it's - # necessary to wrap (at least) chat and channels inside Peer. - # - # NOTICE how the IDs *must* be wrapped inside a Peer() so the - # library knows their type. + # Getting entities through their ID (User, Chat or Channel) + entity = client.get_entity(some_id) + + # You can be more explicit about the type for said ID by wrapping + # it inside a Peer instance. This is recommended but not necessary. from telethon.tl.types import PeerUser, PeerChat, PeerChannel + my_user = client.get_entity(PeerUser(some_id)) my_chat = client.get_entity(PeerChat(some_id)) my_channel = client.get_entity(PeerChannel(some_id)) -.. warning:: - - As it has been mentioned already, getting the entity of a channel - through e.g. ``client.get_entity(channel id)`` will **not** work. - You would use ``client.get_entity(types.PeerChannel(channel id))``. - Remember that supergroups are channels and normal groups are chats. - This is a common mistake! - - All methods in the :ref:`telegram-client` call ``.get_input_entity()`` prior to sending the requst to save you from the hassle of doing so manually. That way, convenience calls such as ``client.send_message('lonami', 'hi!')``