From 8e2aec4d3acdcf8853709240e3b9622d7adb3056 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 7 Jun 2018 12:54:23 +0200 Subject: [PATCH 01/43] Show TOS on sign-ins --- pyrogram/client/client.py | 2 ++ pyrogram/client/ext/base_client.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 73f45966..b148c307 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -204,6 +204,8 @@ class Client(Methods, BaseClient): self.is_started = True if self.user_id is None: + print(self.TOS) + if self.token is None: self.authorize_user() else: diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index 9c0fb26b..8d2f4860 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -26,6 +26,16 @@ from ...session.internals import MsgId class BaseClient: + TOS = ( + "By using Pyrogram you accept Telegram's Terms of Service (https://telegram.org/tos) and agree not to:\n\n" + + "- Use the library to send spam or scam users.\n" + "- Promote violence on publicly viewable Telegram bots, groups or channels.\n" + "- Post illegal pornographic content on publicly viewable Telegram bots, groups or channels.\n\n" + + "We reserve the right to update these Terms of Service later.\n" + ) + INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:t\.me/joinchat/)([\w-]+)$") BOT_TOKEN_RE = re.compile(r"^\d+:[\w-]+$") DIALOGS_AT_ONCE = 100 From f701ee46f64823a158fe01a4fbfe76dd6f799de6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 16:04:34 +0200 Subject: [PATCH 02/43] Update scheme to Layer 81 --- compiler/api/source/main_api.tl | 82 +++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 2919520e..d1f2fa33 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -60,6 +60,7 @@ inputPhoto#fb95c6c4 id:long access_hash:long = InputPhoto; inputFileLocation#14637196 volume_id:long local_id:int secret:long = InputFileLocation; inputEncryptedFileLocation#f5235d55 id:long access_hash:long = InputFileLocation; inputDocumentFileLocation#430f0724 id:long access_hash:long version:int = InputFileLocation; +inputSecureFileLocation#cbc7ee28 id:long access_hash:long = InputFileLocation; inputAppEvent#770656a8 time:double type:string peer:long data:string = InputAppEvent; @@ -149,6 +150,8 @@ messageActionPhoneCall#80e11a7f flags:# call_id:long reason:flags.0?PhoneCallDis messageActionScreenshotTaken#4792929b = MessageAction; messageActionCustomAction#fae69f56 message:string = MessageAction; messageActionBotAllowed#abe9affe domain:string = MessageAction; +messageActionSecureValuesSentMe#1b287353 values:Vector credentials:SecureCredentialsEncrypted = MessageAction; +messageActionSecureValuesSent#d95c6154 types:Vector = MessageAction; dialog#e4def5db flags:# pinned:flags.2?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage = Dialog; @@ -164,7 +167,7 @@ geoPoint#2049d70c long:double lat:double = GeoPoint; auth.checkedPhone#811ea28e phone_registered:Bool = auth.CheckedPhone; -auth.sentCode#5e002502 flags:# phone_registered:flags.0?true type:auth.SentCodeType phone_code_hash:string next_type:flags.1?auth.CodeType timeout:flags.2?int = auth.SentCode; +auth.sentCode#38faab5f flags:# phone_registered:flags.0?true type:auth.SentCodeType phone_code_hash:string next_type:flags.1?auth.CodeType timeout:flags.2?int terms_of_service:flags.3?help.TermsOfService = auth.SentCode; auth.authorization#cd050916 flags:# tmp_sessions:flags.0?int user:User = auth.Authorization; @@ -452,12 +455,12 @@ authorization#7bf2e6f6 hash:long flags:int device_model:string platform:string s account.authorizations#1250abde authorizations:Vector = account.Authorizations; -account.noPassword#96dabc18 new_salt:bytes email_unconfirmed_pattern:string = account.Password; -account.password#7c18141c current_salt:bytes new_salt:bytes hint:string has_recovery:Bool email_unconfirmed_pattern:string = account.Password; +account.noPassword#5ea182f6 new_salt:bytes new_secure_salt:bytes secure_random:bytes email_unconfirmed_pattern:string = account.Password; +account.password#ca39b447 flags:# has_recovery:flags.0?true has_secure_values:flags.1?true current_salt:bytes new_salt:bytes new_secure_salt:bytes secure_random:bytes hint:string email_unconfirmed_pattern:string = account.Password; -account.passwordSettings#b7b72ab3 email:string = account.PasswordSettings; +account.passwordSettings#7bd9c3f1 email:string secure_salt:bytes secure_secret:bytes secure_secret_id:long = account.PasswordSettings; -account.passwordInputSettings#86916deb flags:# new_salt:flags.0?bytes new_password_hash:flags.0?bytes hint:flags.0?string email:flags.1?string = account.PasswordInputSettings; +account.passwordInputSettings#21ffa60d flags:# new_salt:flags.0?bytes new_password_hash:flags.0?bytes hint:flags.0?string email:flags.1?string new_secure_salt:flags.2?bytes new_secure_secret:flags.2?bytes new_secure_secret_id:flags.2?long = account.PasswordInputSettings; auth.passwordRecovery#137948a5 email_pattern:string = auth.PasswordRecovery; @@ -545,7 +548,7 @@ channels.channelParticipantsNotModified#f0173fe9 = channels.ChannelParticipants; channels.channelParticipant#d0d9b163 participant:ChannelParticipant users:Vector = channels.ChannelParticipant; -help.termsOfService#f1ee3e90 text:string = help.TermsOfService; +help.termsOfService#780a0310 flags:# popup:flags.0?true id:DataJSON text:string entities:Vector min_age_confirm:flags.1?int = help.TermsOfService; foundGif#162ecc1f url:string thumb_url:string content_url:string content_type:string w:int h:int = FoundGif; foundGifCached#9c750409 url:string photo:Photo document:Document = FoundGif; @@ -830,6 +833,56 @@ inputClientProxy#75588b3f address:string port:int = InputClientProxy; help.proxyDataEmpty#e09e1fb8 expires:int = help.ProxyData; help.proxyDataPromo#2bf7ee23 expires:int peer:Peer chats:Vector users:Vector = help.ProxyData; +help.termsOfServiceUpdateEmpty#e3309f7f expires:int = help.TermsOfServiceUpdate; +help.termsOfServiceUpdate#28ecf961 expires:int terms_of_service:help.TermsOfService = help.TermsOfServiceUpdate; + +inputSecureFileUploaded#3334b0f0 id:long parts:int md5_checksum:string file_hash:bytes secret:bytes = InputSecureFile; +inputSecureFile#5367e5be id:long access_hash:long = InputSecureFile; + +secureFileEmpty#64199744 = SecureFile; +secureFile#e0277a62 id:long access_hash:long size:int dc_id:int date:int file_hash:bytes secret:bytes = SecureFile; + +secureData#8aeabec3 data:bytes data_hash:bytes secret:bytes = SecureData; + +securePlainPhone#7d6099dd phone:string = SecurePlainData; +securePlainEmail#21ec5a5f email:string = SecurePlainData; + +secureValueTypePersonalDetails#9d2a81e3 = SecureValueType; +secureValueTypePassport#3dac6a00 = SecureValueType; +secureValueTypeDriverLicense#6e425c4 = SecureValueType; +secureValueTypeIdentityCard#a0d0744b = SecureValueType; +secureValueTypeInternalPassport#99a48f23 = SecureValueType; +secureValueTypeAddress#cbe31e26 = SecureValueType; +secureValueTypeUtilityBill#fc36954e = SecureValueType; +secureValueTypeBankStatement#89137c0d = SecureValueType; +secureValueTypeRentalAgreement#8b883488 = SecureValueType; +secureValueTypePassportRegistration#99e3806a = SecureValueType; +secureValueTypeTemporaryRegistration#ea02ec33 = SecureValueType; +secureValueTypePhone#b320aadb = SecureValueType; +secureValueTypeEmail#8e3ca7ee = SecureValueType; + +secureValue#b4b4b699 flags:# type:SecureValueType data:flags.0?SecureData front_side:flags.1?SecureFile reverse_side:flags.2?SecureFile selfie:flags.3?SecureFile files:flags.4?Vector plain_data:flags.5?SecurePlainData hash:bytes = SecureValue; + +inputSecureValue#67872e8 flags:# type:SecureValueType data:flags.0?SecureData front_side:flags.1?InputSecureFile reverse_side:flags.2?InputSecureFile selfie:flags.3?InputSecureFile files:flags.4?Vector plain_data:flags.5?SecurePlainData = InputSecureValue; + +secureValueHash#ed1ecdb0 type:SecureValueType hash:bytes = SecureValueHash; + +secureValueErrorData#e8a40bd9 type:SecureValueType data_hash:bytes field:string text:string = SecureValueError; +secureValueErrorFrontSide#be3dfa type:SecureValueType file_hash:bytes text:string = SecureValueError; +secureValueErrorReverseSide#868a2aa5 type:SecureValueType file_hash:bytes text:string = SecureValueError; +secureValueErrorSelfie#e537ced6 type:SecureValueType file_hash:bytes text:string = SecureValueError; +secureValueErrorFile#7a700873 type:SecureValueType file_hash:bytes text:string = SecureValueError; +secureValueErrorFiles#666220e9 type:SecureValueType file_hash:Vector text:string = SecureValueError; + +secureCredentialsEncrypted#33f0ea47 data:bytes hash:bytes secret:bytes = SecureCredentialsEncrypted; + +account.authorizationForm#cb976d53 flags:# selfie_required:flags.1?true required_types:Vector values:Vector errors:Vector users:Vector privacy_policy_url:flags.0?string = account.AuthorizationForm; + +account.sentEmailCode#811f854f email_pattern:string length:int = account.SentEmailCode; + +help.deepLinkInfoEmpty#66afa166 = help.DeepLinkInfo; +help.deepLinkInfo#6a4ee832 flags:# update_app:flags.0?true message:string entities:flags.1?Vector = help.DeepLinkInfo; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -885,9 +938,20 @@ account.getTmpPassword#4a82327e password_hash:bytes period:int = account.TmpPass account.getWebAuthorizations#182e6d6f = account.WebAuthorizations; account.resetWebAuthorization#2d01b9ef hash:long = Bool; account.resetWebAuthorizations#682d2594 = Bool; +account.getAllSecureValues#b288bc7d = Vector; +account.getSecureValue#73665bc2 types:Vector = Vector; +account.saveSecureValue#899fe31d value:InputSecureValue secure_secret_id:long = SecureValue; +account.deleteSecureValue#b880bc4b types:Vector = Bool; +account.getAuthorizationForm#b86ba8e1 bot_id:int scope:string public_key:string = account.AuthorizationForm; +account.acceptAuthorization#e7027c94 bot_id:int scope:string public_key:string value_hashes:Vector credentials:SecureCredentialsEncrypted = Bool; +account.sendVerifyPhoneCode#823380b4 flags:# allow_flashcall:flags.0?true phone_number:string current_number:flags.0?Bool = auth.SentCode; +account.verifyPhone#4dd3a7f6 phone_number:string phone_code_hash:string phone_code:string = Bool; +account.sendVerifyEmailCode#7011509f email:string = account.SentEmailCode; +account.verifyEmail#ecba39db email:string code:string = Bool; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#ca30a5b1 id:InputUser = UserFull; +users.setSecureValueErrors#90c894b5 id:InputUser errors:Vector = Bool; contacts.getStatuses#c4a353ee = Vector; contacts.getContacts#c023849f hash:int = contacts.Contacts; @@ -1027,11 +1091,13 @@ help.saveAppLog#6f02f748 events:Vector = Bool; help.getInviteText#4d392343 = help.InviteText; help.getSupport#9cdf08cd = help.Support; help.getAppChangelog#9010ef6f prev_app_version:string = Updates; -help.getTermsOfService#8e59b7e7 country_iso2:string = help.TermsOfService; help.setBotUpdatesStatus#ec22cfcd pending_updates_count:int message:string = Bool; help.getCdnConfig#52029342 = CdnConfig; help.getRecentMeUrls#3dc0f114 referer:string = help.RecentMeUrls; help.getProxyData#3d7758e1 = help.ProxyData; +help.getTermsOfServiceUpdate#2ca51fd1 = help.TermsOfServiceUpdate; +help.acceptTermsOfService#ee72f79a id:DataJSON = Bool; +help.getDeepLinkInfo#3fedc75f path:string = help.DeepLinkInfo; channels.readHistory#cc104937 channel:InputChannel max_id:int = Bool; channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector = messages.AffectedMessages; @@ -1095,4 +1161,4 @@ langpack.getStrings#2e1ee318 lang_code:string keys:Vector = Vector; -// LAYER 79 +// LAYER 81 From fc541221eddbb4f29b3fba13f5a533c8c8514279 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 16:08:28 +0200 Subject: [PATCH 03/43] Accept terms of service after successfully signing in --- pyrogram/client/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 24bf09eb..17833310 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -456,6 +456,7 @@ class Client(Methods, BaseClient): phone_registered = r.phone_registered phone_code_hash = r.phone_code_hash + terms_of_service = r.terms_of_service if self.force_sms: self.send( @@ -562,6 +563,8 @@ class Client(Methods, BaseClient): else: break + assert self.send(functions.help.AcceptTermsOfService(terms_of_service.id)) + self.password = None self.user_id = r.user.id From 602f4581c6e446720dfd0bb5cb42dce827fb20d1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 16:15:09 +0200 Subject: [PATCH 04/43] Remove custom TOS --- pyrogram/client/ext/base_client.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index a3279157..578cf168 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -26,16 +26,6 @@ from ...session.internals import MsgId class BaseClient: - TOS = ( - "By using Pyrogram you accept Telegram's Terms of Service (https://telegram.org/tos) and agree not to:\n\n" - - "- Use the library to send spam or scam users.\n" - "- Promote violence on publicly viewable Telegram bots, groups or channels.\n" - "- Post illegal pornographic content on publicly viewable Telegram bots, groups or channels.\n\n" - - "We reserve the right to update these Terms of Service later.\n" - ) - INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/joinchat/)([\w-]+)$") BOT_TOKEN_RE = re.compile(r"^\d+:[\w-]+$") DIALOGS_AT_ONCE = 100 From 0cd479531815cdc744732a462faaa1462a60f225 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 16:15:44 +0200 Subject: [PATCH 05/43] Use TOS provided by Telegram --- pyrogram/client/client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index a6250d74..4787c7af 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -199,8 +199,6 @@ class Client(Methods, BaseClient): self.is_started = True if self.user_id is None: - print(self.TOS) - if self.token is None: self.authorize_user() else: @@ -460,6 +458,9 @@ class Client(Methods, BaseClient): phone_code_hash = r.phone_code_hash terms_of_service = r.terms_of_service + if terms_of_service: + print("\n" + terms_of_service.text + "\n") + if self.force_sms: self.send( functions.auth.ResendCode( @@ -565,7 +566,8 @@ class Client(Methods, BaseClient): else: break - assert self.send(functions.help.AcceptTermsOfService(terms_of_service.id)) + if terms_of_service: + assert self.send(functions.help.AcceptTermsOfService(terms_of_service.id)) self.password = None self.user_id = r.user.id From 355281f081d9d047650ba572771043b8306641db Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Jun 2018 00:49:01 +0200 Subject: [PATCH 06/43] Update README.rst --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index e704d46a..0b9efb76 100644 --- a/README.rst +++ b/README.rst @@ -26,7 +26,7 @@ Features - **Easy to use**: You can easily install Pyrogram using pip and start building your app right away. - **High-level**: The low-level details of MTProto are abstracted and automatically handled. - **Fast**: Crypto parts are boosted up by TgCrypto_, a high-performance library written in pure C. -- **Updated** to the latest Telegram API version, currently Layer 79 on top of MTProto 2.0. +- **Updated** to the latest Telegram API version, currently Layer 81 on top of MTProto 2.0. - **Documented**: The Pyrogram API is well documented and resembles the Telegram Bot API. - **Full API**, allowing to execute any advanced action an official client is able to do, and more. @@ -100,7 +100,7 @@ Copyright & License

- Scheme Layer @@ -115,7 +115,7 @@ Copyright & License .. |description| replace:: **Telegram MTProto API Client Library for Python** -.. |scheme| image:: "https://img.shields.io/badge/SCHEME-LAYER%2079-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30" +.. |scheme| image:: "https://img.shields.io/badge/SCHEME-LAYER%2081-eda738.svg?longCache=true&style=for-the-badge&colorA=262b30" :target: compiler/api/source/main_api.tl :alt: Scheme Layer From 04a86054b09ea2589703aea274907c4836a69b4f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Jun 2018 00:53:45 +0200 Subject: [PATCH 07/43] Update to dev version 0.7.5.dev5 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index dce17c91..daddb08f 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès Date: Mon, 25 Jun 2018 18:06:00 +0200 Subject: [PATCH 08/43] Add CustomizeSessions page --- docs/source/index.rst | 1 + docs/source/resources/CustomizeSessions.rst | 68 +++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 docs/source/resources/CustomizeSessions.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index c52e239b..cffa851d 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -89,6 +89,7 @@ To get started, press the Next button. resources/AutoAuthorization resources/TextFormatting resources/BotsInteraction + resources/CustomizeSessions resources/ErrorHandling .. toctree:: diff --git a/docs/source/resources/CustomizeSessions.rst b/docs/source/resources/CustomizeSessions.rst new file mode 100644 index 00000000..4564eaf0 --- /dev/null +++ b/docs/source/resources/CustomizeSessions.rst @@ -0,0 +1,68 @@ +Customize Sessions +================== + +As you may probably know, Telegram allows Users (and Bots) having more than one session (authorizations) registered +in the system at the same time. + +Briefly explaining, sessions are simply new logins in your account and can be reviewed in the settings of an official +app or by invoking `GetAuthorizations <../functions/account/GetAuthorizations>`_ with Pyrogram. + + +.. figure:: https://i.imgur.com/lzGPCdZ.png + :width: 70% + :align: center + + A Pyrogram session running on Linux, Python 3.6. + +That's how a session looks like on the Android app, showing the three main pieces of information. + +- ``app_version``: **Pyrogram 🔥 0.7.5** +- ``device_model``: **CPython 3.6.5** +- ``system_version``: **Linux 4.15.0-23-generic** + +Set Custom Values +----------------- + +To set custom values, you can either make use of the ``config.ini`` file, this way: + +.. code-block:: ini + + [pyrogram] + app_version = 1.2.3 + device_model = PC + system_version = Linux + +Or, pass the arguments directly in the Client's constructor. + +.. code-block:: python + + app = Client( + "my_account", + app_version="1.2.3", + device_model="PC", + system_version="Linux" + ) + +Set Custom Languages +-------------------- + +These are two extra parameters you can change: ``system_lang_code`` (OS language) and ``lang_code`` (Client language). +They exist to tell Telegram in which language it should speak to you (terms of service, service messages, ...) and are +usually both set to the same value, in `ISO 639-1 `_ standard. +Pyrogram uses "en" (English) for both by default. + +With the following code we make Telegram know we want it to speak in Italian (it): + +.. code-block:: ini + + [pyrogram] + system_lang_code = it + lang_code = it + +.. code-block:: python + + app = Client( + "my_account", + system_lang_code="it", + lang_code="it", + ) \ No newline at end of file From 9d31673f2c4a3ba5bc82c4672d11f8ee8a94d3dc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Jun 2018 18:06:15 +0200 Subject: [PATCH 09/43] Make example more readable --- docs/source/resources/BotsInteraction.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/source/resources/BotsInteraction.rst b/docs/source/resources/BotsInteraction.rst index cbbe23c1..de7925a2 100644 --- a/docs/source/resources/BotsInteraction.rst +++ b/docs/source/resources/BotsInteraction.rst @@ -28,8 +28,12 @@ Inline Bots .. code-block:: python - # Send the first result (bot_results.results[0]) to your own chat (Saved Messages) - app.send_inline_bot_result("me", bot_results.query_id, bot_results.results[0].id) + # Send the first result to your own chat + app.send_inline_bot_result( + "me", + bot_results.query_id, + bot_results.results[0].id + ) .. figure:: https://i.imgur.com/wwxr7B7.png :width: 90% From 1510bc12a8eaf47fb1dbdf97eafff57917f71737 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 25 Jun 2018 18:27:30 +0200 Subject: [PATCH 10/43] Cleanup docs --- docs/source/resources/UpdateHandling.rst | 1 + docs/source/start/Setup.rst | 2 +- docs/source/start/Usage.rst | 6 ++---- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/source/resources/UpdateHandling.rst b/docs/source/resources/UpdateHandling.rst index ffa01be9..0aa6457f 100644 --- a/docs/source/resources/UpdateHandling.rst +++ b/docs/source/resources/UpdateHandling.rst @@ -9,6 +9,7 @@ from, one for each kind of update: - `DeletedMessagesHandler <../pyrogram/handlers/DeletedMessagesHandler.html>`_ - `CallbackQueryHandler <../pyrogram/handlers/CallbackQueryHandler.html>`_ - `RawUpdateHandler <../pyrogram/handlers/RawUpdateHandler.html>`_ +- `DisconnectHandler <../pyrogram/handlers/DisconnectHandler.html>`_ Registering an Handler ---------------------- diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 8b7c0597..417d62d8 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -54,7 +54,7 @@ User Authorization In order to use the API, Telegram requires that Users be authorized via their phone numbers. Pyrogram automatically manages this access, all you need to do is create an instance of the :class:`Client ` class by passing to it a ``session_name`` of your choice -(e.g.: "my_account") and call the :meth:`start() ` method: +(e.g.: "my_account") and call the :meth:`run() ` method: .. code-block:: python diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index d9cb8fe1..531e997f 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -10,10 +10,6 @@ High-level API The easiest and recommended way to interact with Telegram is via the high-level Pyrogram methods_ and types_, which are named after the `Telegram Bot API`_. -.. hint:: If you can't find an high-level method you want to use, chances are it's not implemented yet. - In this case, you must use the `Raw Functions`_. Meanwhile, feel free to join our Community_ if you get stuck - or want to propose a new method! - Examples (more on `GitHub `_): - Get information about the authorized user: @@ -45,8 +41,10 @@ you have to use the raw :mod:`functions ` and :mod:`type method provided by the Client class. .. hint:: Every high-level method mentioned in the section above is built on top of these raw functions. + Nothing stops you from using the raw functions only, but they are rather complex and `plenty of them`_ are already re-implemented by providing a much simpler and cleaner interface which is very similar to the Bot API. + If you think a raw function should be wrapped and added as a high-level method, feel free to ask in our Community_! Examples (more on `GitHub `_): From 1cc66c898d3b47601e2e3b1ad4b840afffe1b121 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 26 Jun 2018 14:05:45 +0200 Subject: [PATCH 11/43] Fix request_callback_answer call with wrong kwarg --- pyrogram/client/types/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index ce6d158f..d80c657d 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -561,7 +561,7 @@ class Message(Object): return self._client.request_callback_answer( chat_id=self.chat.id, message_id=self.message_id, - data=button.callback_data + callback_data=button.callback_data ) elif button.url: return button.url From fc1c653c05717e55cd2a237b0c40532d309293b3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 26 Jun 2018 16:16:10 +0200 Subject: [PATCH 12/43] Add TimeoutError on possible raises of Message.click() --- pyrogram/client/types/message.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index d80c657d..b969865c 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -516,7 +516,8 @@ class Message(Object): Raises: :class:`Error ` - ``ValueError``: If the provided index or position is out of range or the button label was not found. + ``ValueError``: If the provided index or position is out of range or the button label was not found + ``TimeoutError``: If, after clicking an inline button, the bot fails to answer within 10 seconds """ if isinstance(self.reply_markup, ReplyKeyboardMarkup): if quote is None: From ef69dbd396934e669bc0a73e54aed98e29a63fce Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 00:02:54 +0200 Subject: [PATCH 13/43] Use shields.io badges --- docs/source/index.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index cffa851d..fb7022ab 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -26,11 +26,11 @@ Welcome to Pyrogram

- Scheme Layer 75 + - TgCrypto

@@ -56,7 +56,7 @@ button at the end of each page. But first, here's a brief overview of what is th About ----- -Pyrogram is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building +**Pyrogram** is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building custom Telegram applications that interact with the MTProto API as both User and Bot. Features @@ -65,8 +65,8 @@ Features - **Easy to use**: You can easily install Pyrogram using pip and start building your app right away. - **High-level**: The low-level details of MTProto are abstracted and automatically handled. - **Fast**: Crypto parts are boosted up by TgCrypto_, a high-performance library written in pure C. -- **Updated** to the latest Telegram API version, currently Layer 76 running on MTProto 2.0. -- **Documented**: Pyrogram API methods are documented and resemble the Telegram Bot API. +- **Updated** to the latest Telegram API version, currently Layer 81 on top of MTProto 2.0. +- **Documented**: The Pyrogram API is well documented and resembles the Telegram Bot API. - **Full API**, allowing to execute any advanced action an official client is able to do, and more. To get started, press the Next button. From 36519cb3ca9f373a2d5cde6ac297bbae2e0bbaa9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 00:11:53 +0200 Subject: [PATCH 14/43] Sort Resources --- docs/source/index.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index fb7022ab..4143cfee 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -84,12 +84,12 @@ To get started, press the Next button. :caption: Resources resources/UpdateHandling - resources/SOCKS5Proxy - resources/TgCrypto resources/AutoAuthorization - resources/TextFormatting - resources/BotsInteraction resources/CustomizeSessions + resources/TgCrypto + resources/TextFormatting + resources/SOCKS5Proxy + resources/BotsInteraction resources/ErrorHandling .. toctree:: From 27020ca1bb594492ac4edb9b6390be0b045cc355 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 00:12:09 +0200 Subject: [PATCH 15/43] Rename Raw Functions section --- docs/source/start/Usage.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index 531e997f..6c20decd 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -30,10 +30,8 @@ Examples (more on `GitHub ` and :mod:`types ` exposed by the From ecaba45523170f4d4de4c8c386a24d3fa95a98f8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 00:42:32 +0200 Subject: [PATCH 16/43] Keep only lang_code --- pyrogram/client/client.py | 8 +------- pyrogram/session/session.py | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 2cb153db..f21d2ef2 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -86,10 +86,6 @@ class Client(Methods, BaseClient): Operating System version. Defaults to *platform.system() + " " + platform.release()* This is an alternative way to set it if you don't want to use the *config.ini* file. - system_lang_code (``str``, *optional*): - Code of the language used on the system, in ISO 639-1 standard. Defaults to "en". - This is an alternative way to set it if you don't want to use the *config.ini* file. - lang_code (``str``, *optional*): Code of the language used on the client, in ISO 639-1 standard. Defaults to "en". This is an alternative way to set it if you don't want to use the *config.ini* file. @@ -149,7 +145,6 @@ class Client(Methods, BaseClient): app_version: str = None, device_model: str = None, system_version: str = None, - system_lang_code: str = None, lang_code: str = None, proxy: dict = None, test_mode: bool = False, @@ -170,7 +165,6 @@ class Client(Methods, BaseClient): self.app_version = app_version self.device_model = device_model self.system_version = system_version - self.system_lang_code = system_lang_code self.lang_code = lang_code # TODO: Make code consistent, use underscore for private/protected fields self._proxy = proxy @@ -889,7 +883,7 @@ class Client(Methods, BaseClient): "More info: https://docs.pyrogram.ml/start/ProjectSetup#configuration" ) - for option in {"app_version", "device_model", "system_version", "system_lang_code", "lang_code"}: + for option in {"app_version", "device_model", "system_version", "lang_code"}: if getattr(self, option): pass else: diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 7bafd71f..ef7b565c 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -145,7 +145,7 @@ class Session: app_version=self.client.app_version, device_model=self.client.device_model, system_version=self.client.system_version, - system_lang_code=self.client.system_lang_code, + system_lang_code=self.client.lang_code, lang_code=self.client.lang_code, lang_pack="", query=functions.help.GetConfig(), From 7ed9cd6759dd18cabf037fe5014f669c81a19e9a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 14:42:04 +0200 Subject: [PATCH 17/43] Add "Login successful" message upon login --- pyrogram/client/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index f21d2ef2..20a3e50c 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -585,6 +585,8 @@ class Client(Methods, BaseClient): self.password = None self.user_id = r.user.id + print("Login successful") + def fetch_peers(self, entities: list): for entity in entities: if isinstance(entity, types.User): From c0ad63f72cec666f98c0c3f52dd0d31bef2a6448 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 14:45:56 +0200 Subject: [PATCH 18/43] Update CustomizeSessions page --- docs/source/resources/CustomizeSessions.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/source/resources/CustomizeSessions.rst b/docs/source/resources/CustomizeSessions.rst index 4564eaf0..498003d4 100644 --- a/docs/source/resources/CustomizeSessions.rst +++ b/docs/source/resources/CustomizeSessions.rst @@ -4,8 +4,9 @@ Customize Sessions As you may probably know, Telegram allows Users (and Bots) having more than one session (authorizations) registered in the system at the same time. -Briefly explaining, sessions are simply new logins in your account and can be reviewed in the settings of an official -app or by invoking `GetAuthorizations <../functions/account/GetAuthorizations>`_ with Pyrogram. +Briefly explaining, sessions are simply new logins in your account. They can be reviewed in the settings of an official +app (or by invoking `GetAuthorizations <../functions/account/GetAuthorizations>`_ with Pyrogram) and store some useful +information about the client who generated them. .. figure:: https://i.imgur.com/lzGPCdZ.png @@ -46,23 +47,20 @@ Or, pass the arguments directly in the Client's constructor. Set Custom Languages -------------------- -These are two extra parameters you can change: ``system_lang_code`` (OS language) and ``lang_code`` (Client language). -They exist to tell Telegram in which language it should speak to you (terms of service, service messages, ...) and are -usually both set to the same value, in `ISO 639-1 `_ standard. -Pyrogram uses "en" (English) for both by default. +To tell Telegram in which language should speak to you (terms of service, bots, service messages, ...) you can +set ``lang_code`` in `ISO 639-1 `_ standard (defaults to "en", +English). With the following code we make Telegram know we want it to speak in Italian (it): .. code-block:: ini [pyrogram] - system_lang_code = it lang_code = it .. code-block:: python app = Client( "my_account", - system_lang_code="it", lang_code="it", ) \ No newline at end of file From c1cd8ec12dee39b8153d6f670518090b4dda3c53 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 14:52:13 +0200 Subject: [PATCH 19/43] Tiny fix --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 4143cfee..051b5af8 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -26,7 +26,7 @@ Welcome to Pyrogram

- Scheme Layer From ec667035cd53c407cdb912f320af01019dfc57bf Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 15:27:15 +0200 Subject: [PATCH 20/43] Sort docs entries alphabetically --- compiler/docs/compiler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 494697de..73b5a578 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -77,7 +77,8 @@ def generate(source_path, base): build(source_path) - for k, v in all_entities.items(): + for k, v in sorted(all_entities.items()): + v = sorted(v) entities = [] for i in v: From a65376a52be0c26c2e5cab6bea5589bbd5d754be Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 15:46:38 +0200 Subject: [PATCH 21/43] Fix broken link --- docs/source/resources/CustomizeSessions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/resources/CustomizeSessions.rst b/docs/source/resources/CustomizeSessions.rst index 498003d4..e98792b7 100644 --- a/docs/source/resources/CustomizeSessions.rst +++ b/docs/source/resources/CustomizeSessions.rst @@ -5,7 +5,7 @@ As you may probably know, Telegram allows Users (and Bots) having more than one in the system at the same time. Briefly explaining, sessions are simply new logins in your account. They can be reviewed in the settings of an official -app (or by invoking `GetAuthorizations <../functions/account/GetAuthorizations>`_ with Pyrogram) and store some useful +app (or by invoking `GetAuthorizations <../functions/account/GetAuthorizations.html>`_ with Pyrogram) and store some useful information about the client who generated them. From 37aae4382e67c45b27eec33250d8934999ec2465 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 27 Jun 2018 16:38:41 +0200 Subject: [PATCH 22/43] Update to v0.7.5 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index daddb08f..96fb4a76 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès Date: Wed, 27 Jun 2018 16:53:18 +0200 Subject: [PATCH 23/43] Add missing method to docs --- docs/source/pyrogram/Client.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 0448c3cb..0000b35f 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -62,6 +62,7 @@ Client get_inline_bot_results send_inline_bot_result answer_callback_query + request_callback_answer get_users get_chat get_messages From 7d8ebdc0dd6fd51f461b60a5f95d73f0e4b66de5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 00:11:48 +0200 Subject: [PATCH 24/43] Add "406 Not Acceptable" error class --- compiler/error/source/406_NOT_ACCEPTABLE.tsv | 1 + 1 file changed, 1 insertion(+) create mode 100644 compiler/error/source/406_NOT_ACCEPTABLE.tsv diff --git a/compiler/error/source/406_NOT_ACCEPTABLE.tsv b/compiler/error/source/406_NOT_ACCEPTABLE.tsv new file mode 100644 index 00000000..d82f6e11 --- /dev/null +++ b/compiler/error/source/406_NOT_ACCEPTABLE.tsv @@ -0,0 +1 @@ +id message From 38b7abec3546603697094a22182ec374265c56b3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 00:15:53 +0200 Subject: [PATCH 25/43] Add AUTH_KEY_DUPLICATED error --- compiler/error/source/406_NOT_ACCEPTABLE.tsv | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/error/source/406_NOT_ACCEPTABLE.tsv b/compiler/error/source/406_NOT_ACCEPTABLE.tsv index d82f6e11..3a88a7b6 100644 --- a/compiler/error/source/406_NOT_ACCEPTABLE.tsv +++ b/compiler/error/source/406_NOT_ACCEPTABLE.tsv @@ -1 +1,2 @@ id message +AUTH_KEY_DUPLICATED Authorization error. You must log out and log in again with your phone number. We apologize for the inconvenience. \ No newline at end of file From 6e4c608875885c7753af1862614255b120323865 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 00:16:12 +0200 Subject: [PATCH 26/43] Handle AUTH_KEY_DUPLICATED error --- pyrogram/session/session.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index ef7b565c..b7645b11 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -31,7 +31,7 @@ from pyrogram import __copyright__, __license__, __version__ from pyrogram.api import functions, types, core from pyrogram.api.all import layer from pyrogram.api.core import Message, Object, MsgContainer, Long, FutureSalt, Int -from pyrogram.api.errors import Error, InternalServerError +from pyrogram.api.errors import Error, InternalServerError, AuthKeyDuplicated from pyrogram.connection import Connection from pyrogram.crypto import AES, KDF from .internals import MsgId, MsgFactory, DataCenter @@ -157,6 +157,9 @@ class Session: self.ping_thread.start() log.info("Connection inited: Layer {}".format(layer)) + except AuthKeyDuplicated as e: + self.stop() + raise e except (OSError, TimeoutError, Error): self.stop() except Exception as e: From 0935c4837f2c9cf9f66b69c48ddea81f0d1a6d53 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 18:41:16 +0200 Subject: [PATCH 27/43] Fix ReplyKeyboardRemove id --- pyrogram/client/types/reply_markup/reply_keyboard_remove.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/reply_markup/reply_keyboard_remove.py b/pyrogram/client/types/reply_markup/reply_keyboard_remove.py index de32f740..3e2aebf5 100644 --- a/pyrogram/client/types/reply_markup/reply_keyboard_remove.py +++ b/pyrogram/client/types/reply_markup/reply_keyboard_remove.py @@ -35,7 +35,7 @@ class ReplyKeyboardRemove(Object): keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. """ - ID = 0xb0700002 + ID = 0xb0700023 def __init__(self, selective: bool = None): self.selective = selective From be451a3bb2d055101c5440786ae1680fb30bf307 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 18:49:09 +0200 Subject: [PATCH 28/43] Rename parse_photos to parse_profile_photos --- pyrogram/client/ext/utils.py | 2 +- pyrogram/client/methods/users/get_user_profile_photos.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 2913c38b..3d2f88c1 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -757,7 +757,7 @@ def get_offset_date(dialogs): return 0 -def parse_photos(photos): +def parse_profile_photos(photos): if isinstance(photos, types.photos.Photos): total_count = len(photos.photos) else: diff --git a/pyrogram/client/methods/users/get_user_profile_photos.py b/pyrogram/client/methods/users/get_user_profile_photos.py index 42fb84bb..5613c21d 100644 --- a/pyrogram/client/methods/users/get_user_profile_photos.py +++ b/pyrogram/client/methods/users/get_user_profile_photos.py @@ -48,7 +48,7 @@ class GetUserProfilePhotos(BaseClient): Raises: :class:`Error ` """ - return utils.parse_photos( + return utils.parse_profile_photos( self.send( functions.photos.GetUserPhotos( user_id=self.resolve_peer(user_id), From 5f87bbc962d35e33e0faeba5c06a3c0f2bc6e916 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:04:45 +0200 Subject: [PATCH 29/43] Add the new Photo type --- compiler/api/compiler.py | 9 +++---- pyrogram/client/types/__init__.py | 1 + pyrogram/client/types/photo.py | 41 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 pyrogram/client/types/photo.py diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index d1bf8cfa..7c1412d1 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -494,17 +494,16 @@ def start(): f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",") f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",") f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",") - f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") - f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") - f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",") f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",") f.write("\n 0xb0700020: \"pyrogram.client.types.reply_markup.InlineKeyboardMarkup\",") f.write("\n 0xb0700021: \"pyrogram.client.types.reply_markup.KeyboardButton\",") f.write("\n 0xb0700022: \"pyrogram.client.types.reply_markup.ReplyKeyboardMarkup\",") f.write("\n 0xb0700023: \"pyrogram.client.types.reply_markup.ReplyKeyboardRemove\",") - - f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\"") + f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\",") + f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") + f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") + f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",") f.write("\n}\n") diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index acd001dd..84c12a44 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -31,6 +31,7 @@ from .location import Location from .message import Message from .message_entity import MessageEntity from .messages import Messages +from .photo import Photo from .photo_size import PhotoSize from .reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/photo.py b/pyrogram/client/types/photo.py new file mode 100644 index 00000000..39fb8d94 --- /dev/null +++ b/pyrogram/client/types/photo.py @@ -0,0 +1,41 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api.core import Object + + +class Photo(Object): + """This object represents a Photo + + Args: + id (``str``): + Unique identifier for this photo. + + date (``int``): + Date the photo was sent in Unix time + + sizes (List of :obj:`PhotoSize ): + Available sizes of this photo + """ + + ID = 0xb0700027 + + def __init__(self, id: str, date: int, sizes: list): + self.id = id + self.date = date + self.sizes = sizes From 971299f59283278d296d365e2f125c5a9f97f58a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:05:08 +0200 Subject: [PATCH 30/43] PhotoSize won't store date info anymore --- pyrogram/client/types/photo_size.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/types/photo_size.py b/pyrogram/client/types/photo_size.py index 7e9b3cba..65691de0 100644 --- a/pyrogram/client/types/photo_size.py +++ b/pyrogram/client/types/photo_size.py @@ -32,18 +32,14 @@ class PhotoSize(Object): height (``int``): Photo height. - file_size (``int``, *optional*): + file_size (``int``): File size. - - date (``int``, *optional*): - Date the photo was sent in Unix time """ ID = 0xb0700005 - def __init__(self, file_id, width, height, file_size=None, date=None): - self.file_id = file_id # string - self.width = width # int - self.height = height # int - self.file_size = file_size # flags.0?int - self.date = date + def __init__(self, file_id: str, width: int, height: int, file_size: int): + self.file_id = file_id + self.width = width + self.height = height + self.file_size = file_size From fb10b3b0e7e767610a7774a7e933185c9046151e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:05:47 +0200 Subject: [PATCH 31/43] UserProfilePhoto.photos is now a list of Photo objects --- pyrogram/client/types/user_profile_photos.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/user_profile_photos.py b/pyrogram/client/types/user_profile_photos.py index 1b7ecbb4..c8ca9e39 100644 --- a/pyrogram/client/types/user_profile_photos.py +++ b/pyrogram/client/types/user_profile_photos.py @@ -26,12 +26,12 @@ class UserProfilePhotos(Object): total_count (``int``): Total number of profile pictures the target user has. - photos (List of List of :obj:`PhotoSize `): - Requested profile pictures (in up to 4 sizes each). + photos (List of :obj:`Photo `): + Requested profile pictures. """ ID = 0xb0700014 def __init__(self, total_count: int, photos: list): - self.total_count = total_count # int - self.photos = photos # Vector> + self.total_count = total_count + self.photos = photos From a3761144b37e24a0d1f956ea1d29e42c936f053a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:07:02 +0200 Subject: [PATCH 32/43] Use Photo as type for media messages --- pyrogram/client/ext/utils.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 3d2f88c1..105d0f0c 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -329,13 +329,23 @@ def parse_messages( ), width=size.w, height=size.h, - file_size=file_size, - date=photo.date + file_size=file_size ) photo_sizes.append(photo_size) - photo = photo_sizes + photo = pyrogram_types.Photo( + id=b64encode( + pack( + " Date: Thu, 28 Jun 2018 19:14:29 +0200 Subject: [PATCH 37/43] Add Photo type to docs --- docs/source/pyrogram/types/Photo.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/source/pyrogram/types/Photo.rst diff --git a/docs/source/pyrogram/types/Photo.rst b/docs/source/pyrogram/types/Photo.rst new file mode 100644 index 00000000..78fe13f4 --- /dev/null +++ b/docs/source/pyrogram/types/Photo.rst @@ -0,0 +1,5 @@ +Photo +===== + +.. autoclass:: pyrogram.Photo + :members: From 30497b0e91635a9808904aeb846a14b70fa6e289 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 19:59:26 +0200 Subject: [PATCH 38/43] Add delete_profile_photos method --- pyrogram/client/methods/users/__init__.py | 2 + .../methods/users/delete_profile_photos.py | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 pyrogram/client/methods/users/delete_profile_photos.py diff --git a/pyrogram/client/methods/users/__init__.py b/pyrogram/client/methods/users/__init__.py index 7a82667d..f7c32b3b 100644 --- a/pyrogram/client/methods/users/__init__.py +++ b/pyrogram/client/methods/users/__init__.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from .delete_profile_photos import DeleteProfilePhotos from .get_me import GetMe from .get_user_profile_photos import GetUserProfilePhotos from .get_users import GetUsers @@ -23,6 +24,7 @@ from .get_users import GetUsers class Users( GetUserProfilePhotos, + DeleteProfilePhotos, GetUsers, GetMe ): diff --git a/pyrogram/client/methods/users/delete_profile_photos.py b/pyrogram/client/methods/users/delete_profile_photos.py new file mode 100644 index 00000000..47a6682a --- /dev/null +++ b/pyrogram/client/methods/users/delete_profile_photos.py @@ -0,0 +1,58 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from base64 import b64decode +from struct import unpack + +from pyrogram.api import functions, types +from ...ext import BaseClient + + +class DeleteProfilePhotos(BaseClient): + def delete_profile_photos(self, id: str or list): + """Use this method to delete your own profile photos + + Args: + id (``str`` | ``list``): + A single :obj:`Photo ` id as string or multiple ids as list of strings for deleting + more than one photos at once. + + Returns: + True on success. + + Raises: + :class:`Error ` + """ + id = id if isinstance(id, list) else [id] + input_photos = [] + + for i in id: + s = unpack(" Date: Thu, 28 Jun 2018 19:59:53 +0200 Subject: [PATCH 39/43] Add delete_profile_photos method to docs --- docs/source/pyrogram/Client.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 0000b35f..2fbd5879 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -42,6 +42,7 @@ Client send_chat_action download_media get_user_profile_photos + delete_profile_photos edit_message_text edit_message_caption edit_message_reply_markup From 29d45be0a5681445c42b34bb264f2f11ea24f10d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:00:48 +0200 Subject: [PATCH 40/43] Add Photo to types list --- docs/source/pyrogram/types/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/types/index.rst index 2fc74e49..ff3de94e 100644 --- a/docs/source/pyrogram/types/index.rst +++ b/docs/source/pyrogram/types/index.rst @@ -9,6 +9,7 @@ Types Message MessageEntity Messages + Photo PhotoSize Audio Document From bae7b4c85127a6d8d0caf963c441912d1140cdd8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:02:31 +0200 Subject: [PATCH 41/43] Make Photo importable from the top level package --- pyrogram/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 96fb4a76..16204830 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -29,8 +29,8 @@ from .api.errors import Error from .client.types import ( Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, - PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video, - VideoNote, Voice, CallbackQuery, Messages + Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, + Video, VideoNote, Voice, CallbackQuery, Messages ) from .client.types.reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, From b6206b7938431a24ed81aff35eced0643a44c26e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:03:50 +0200 Subject: [PATCH 42/43] Fix small docstring issue --- pyrogram/client/types/photo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/photo.py b/pyrogram/client/types/photo.py index 39fb8d94..f5494f13 100644 --- a/pyrogram/client/types/photo.py +++ b/pyrogram/client/types/photo.py @@ -29,7 +29,7 @@ class Photo(Object): date (``int``): Date the photo was sent in Unix time - sizes (List of :obj:`PhotoSize ): + sizes (List of :obj:`PhotoSize `): Available sizes of this photo """ From 6943e16636c04c0a31f1418caa7396a3a4b9a0d9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 28 Jun 2018 20:04:46 +0200 Subject: [PATCH 43/43] Change new_chat_photo type. It is now Photo --- pyrogram/client/types/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index b9048f1e..112bc0bf 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -132,7 +132,7 @@ class Message(Object): new_chat_title (``str``, *optional*): A chat title was changed to this value. - new_chat_photo (List of :obj:`PhotoSize `, *optional*): + new_chat_photo (:obj:`Photo `, *optional*): A chat photo was change to this value. delete_chat_photo (``bool``, *optional*):