From b77771497dbb40d7bebc8440486eb54da523be25 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 17 Jul 2018 09:09:04 +0200 Subject: [PATCH 01/85] Document get_chat_members --- .../client/methods/chats/get_chat_members.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index a851ef58..99e1c12d 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -36,6 +36,37 @@ class GetChatMembers(BaseClient): limit: int = 200, query: str = "", filter: str = Filters.ALL): + """Use this method to get the members list of a chat. + + A chat can be either a basic group, a supergroup or a channel. + You must be admin to retrieve the members (also known as "subscribers") list of a channel. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + offset (``int``, *optional*): + Sequential number of the first member to be returned. + Defaults to 0 [1]_. + + limit (``int``, *optional*): + Limits the number of members to be retrieved. + Defaults to 200, which is also the maximum limit allowed per method call. + + query (``str``, *optional*): + Query string to filter members based on their display names and usernames. + Defaults to "" (empty string) [2]_. + + filter (``str``, *optional*): + Filter used to select the kind of members you want to retrieve. Only applicable for supergroups + and channels. It can be any of "all", "kicked", "restricted", "bots", "recent" and "administrators". + Defaults to "all". + + .. [1] On supergroups and channels you can get up to 10,000 members for a single query string. + + .. [2] A query string is applicable only for "all", "kicked" and "restricted" filters only. + """ peer = self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): From de0cc60ec60bb3292bcae32a1eaf3037677d23c5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 18 Jul 2018 02:14:36 +0200 Subject: [PATCH 02/85] Add USER_NOT_PARTICIPANT error --- compiler/error/source/400_BAD_REQUEST.tsv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index e00c10c5..ed332838 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -65,4 +65,5 @@ PEER_FLOOD The method can't be used because your account is limited MEDIA_CAPTION_TOO_LONG The media caption is longer than 200 characters USER_NOT_MUTUAL_CONTACT The user is not a mutual contact USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups -API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side \ No newline at end of file +API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side +USER_NOT_PARTICIPANT The user is not a member of this chat \ No newline at end of file From e5915505a15516b9014e1beda9e3199e41d458c8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 19 Jul 2018 23:26:20 +0200 Subject: [PATCH 03/85] Add get_chat_member method --- pyrogram/client/methods/chats/__init__.py | 2 + .../client/methods/chats/get_chat_member.py | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 pyrogram/client/methods/chats/get_chat_member.py diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index 038440f6..ce56f16b 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -19,6 +19,7 @@ from .delete_chat_photo import DeleteChatPhoto from .export_chat_invite_link import ExportChatInviteLink from .get_chat import GetChat +from .get_chat_member import GetChatMember from .get_chat_members import GetChatMembers from .join_chat import JoinChat from .kick_chat_member import KickChatMember @@ -43,6 +44,7 @@ class Chats( RestrictChatMember, PromoteChatMember, GetChatMembers, + GetChatMember, SetChatPhoto, DeleteChatPhoto, SetChatTitle, diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py new file mode 100644 index 00000000..082d1671 --- /dev/null +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -0,0 +1,59 @@ +# 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 import functions, types, errors +from ...ext import BaseClient, utils + + +class GetChatMember(BaseClient): + def get_chat_member(self, + chat_id: int or str, + user_id: int or str): + # TODO: docstrings + chat_id = self.resolve_peer(chat_id) + user_id = self.resolve_peer(user_id) + + if isinstance(chat_id, types.InputPeerChat): + full_chat = self.send( + functions.messages.GetFullChat( + chat_id=chat_id.chat_id + ) + ) + + for member in utils.parse_chat_members(full_chat).chat_members: + if member.user.id == user_id.user_id: + return member + else: + raise errors.UserNotParticipant + elif isinstance(chat_id, types.InputPeerChannel): + r = self.send( + functions.channels.GetParticipant( + channel=chat_id, + user_id=user_id + ) + ) + + return utils.parse_chat_members( + types.channels.ChannelParticipants( + count=1, + participants=[r.participant], + users=r.users + ) + ).chat_members[0] + else: + raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id)) From 418740a3e69021fea78b0591c06c47d80c0ffb15 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 20 Jul 2018 00:08:32 +0200 Subject: [PATCH 04/85] Add get_chat_member and get_chat_members to docs --- docs/source/pyrogram/Client.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index bf9ac2ca..fec829f6 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -73,4 +73,6 @@ Client set_chat_title set_chat_description pin_chat_message - unpin_chat_message \ No newline at end of file + unpin_chat_message + get_chat_member + get_chat_members \ No newline at end of file From 1eaafb8e413bafe40063ef6b040f2fe980d6efab Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 21 Jul 2018 14:09:34 +0200 Subject: [PATCH 05/85] Clearer documentation for get_chat_members --- pyrogram/client/methods/chats/get_chat_members.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index 99e1c12d..cfc9861e 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -60,12 +60,18 @@ class GetChatMembers(BaseClient): filter (``str``, *optional*): Filter used to select the kind of members you want to retrieve. Only applicable for supergroups - and channels. It can be any of "all", "kicked", "restricted", "bots", "recent" and "administrators". - Defaults to "all". + and channels. It can be any of the followings: + *"all"* - all kind of members, + *"kicked"* - kicked (banned) members only, + *"restricted"* - restricted members only, + *"bots"* - bots only, + *"recent"* - recent members only, + *"administrators"* - chat administrators only. + Defaults to *"all"*. .. [1] On supergroups and channels you can get up to 10,000 members for a single query string. - .. [2] A query string is applicable only for "all", "kicked" and "restricted" filters only. + .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only. """ peer = self.resolve_peer(chat_id) From 215f54f32b17fb2e7c1ed577908d4d449fdd567d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 22 Jul 2018 02:07:44 +0200 Subject: [PATCH 06/85] Add get_chat_member documentation --- .../client/methods/chats/get_chat_member.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index 082d1671..c4fe0715 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -24,7 +24,25 @@ class GetChatMember(BaseClient): def get_chat_member(self, chat_id: int or str, user_id: int or str): - # TODO: docstrings + """Use this method to get information about a single member of a chat. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + user_id (``int`` | ``str``):: + Unique identifier (int) or username (str) of the target chat. + For your personal cloud (Saved Messages) you can simply use "me" or "self". + For a contact that exists in your Telegram address book you can use his phone number (str). + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + Returns: + On success, a :obj:`ChatMember ` object is returned. + + Raises: + :class:`Error ` + """ chat_id = self.resolve_peer(chat_id) user_id = self.resolve_peer(user_id) From 73361fef4718d39ec63f8123d9f8ab6c2101fe1c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 23 Jul 2018 22:52:54 +0200 Subject: [PATCH 07/85] Add missing methods to docs --- docs/source/pyrogram/Client.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index fec829f6..96388364 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -20,6 +20,8 @@ Client run on_message on_callback_query + on_deleted_messages + on_disconnect on_raw_update add_handler remove_handler @@ -31,6 +33,7 @@ Client send_photo send_audio send_document + send_gif send_sticker send_video send_voice @@ -75,4 +78,5 @@ Client pin_chat_message unpin_chat_message get_chat_member - get_chat_members \ No newline at end of file + get_chat_members + get_dialogs \ No newline at end of file From df2f302c721771e8705aca2a94c11cd199ddc01f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 24 Jul 2018 20:43:49 +0200 Subject: [PATCH 08/85] Better organize Client's methods --- docs/source/pyrogram/Client.rst | 203 ++++++++++++++++++++------------ 1 file changed, 128 insertions(+), 75 deletions(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 96388364..642d43d8 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -1,82 +1,135 @@ Client ====== -.. currentmodule:::: pyrogram.Client +.. currentmodule:: pyrogram.Client + +.. autoclass:: pyrogram.Client + +Utilities +--------- + +.. autosummary:: + :nosignatures: + + start + stop + idle + run + add_handler + remove_handler + send + resolve_peer + download_media + +Decorators +---------- + +.. autosummary:: + :nosignatures: + + on_message + on_callback_query + on_deleted_messages + on_disconnect + on_raw_update + +.. _available-methods: + +Messages +-------- + +.. autosummary:: + :nosignatures: + + send_message + forward_messages + send_photo + send_audio + send_document + send_sticker + send_video + send_gif + send_voice + send_video_note + send_media_group + send_location + send_venue + send_contact + send_chat_action + edit_message_text + edit_message_caption + edit_message_reply_markup + delete_messages + get_messages + get_history + get_dialogs + +Chats +----- + +.. autosummary:: + :nosignatures: + + join_chat + leave_chat + kick_chat_member + unban_chat_member + restrict_chat_member + promote_chat_member + export_chat_invite_link + set_chat_photo + delete_chat_photo + set_chat_title + set_chat_description + pin_chat_message + unpin_chat_message + get_chat + get_chat_member + get_chat_members + +Users +----- + +.. autosummary:: + :nosignatures: + + get_me + get_users + get_user_profile_photos + delete_profile_photos + +Contacts +-------- + +.. autosummary:: + :nosignatures: + + add_contacts + get_contacts + delete_contacts + +Password +-------- + +.. autosummary:: + :nosignatures: + + enable_cloud_password + change_cloud_password + remove_cloud_password + +Bots +---- + +.. autosummary:: + :nosignatures: + + get_inline_bot_results + send_inline_bot_result + answer_callback_query + request_callback_answer + .. autoclass:: pyrogram.Client :inherited-members: :members: - - .. _available-methods: - - **Available methods** - - .. autosummary:: - :nosignatures: - - start - stop - idle - run - on_message - on_callback_query - on_deleted_messages - on_disconnect - on_raw_update - add_handler - remove_handler - send - resolve_peer - get_me - send_message - forward_messages - send_photo - send_audio - send_document - send_gif - send_sticker - send_video - send_voice - send_video_note - send_media_group - send_location - send_venue - send_contact - send_chat_action - download_media - get_user_profile_photos - delete_profile_photos - edit_message_text - edit_message_caption - edit_message_reply_markup - delete_messages - join_chat - leave_chat - export_chat_invite_link - enable_cloud_password - change_cloud_password - remove_cloud_password - kick_chat_member - unban_chat_member - restrict_chat_member - promote_chat_member - add_contacts - get_contacts - delete_contacts - get_inline_bot_results - send_inline_bot_result - answer_callback_query - request_callback_answer - get_users - get_chat - get_messages - get_history - set_chat_photo - delete_chat_photo - set_chat_title - set_chat_description - pin_chat_message - unpin_chat_message - get_chat_member - get_chat_members - get_dialogs \ No newline at end of file From 0c8278259028be87291626aa4e32de7c37fa4a30 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 24 Jul 2018 20:46:25 +0200 Subject: [PATCH 09/85] Don't show sub-sections --- docs/source/pyrogram/index.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/pyrogram/index.rst b/docs/source/pyrogram/index.rst index c272bc42..af8b281a 100644 --- a/docs/source/pyrogram/index.rst +++ b/docs/source/pyrogram/index.rst @@ -7,6 +7,8 @@ In this section you can find a detailed description of the Pyrogram package and after the well established `Telegram Bot API`_ methods, thus offering a familiar look to Bot developers. .. toctree:: + :maxdepth: 1 + Client types/index handlers/index From 5546765c4f04c0af99ab3653a0fef3c8606c4bd0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 25 Jul 2018 22:22:57 +0200 Subject: [PATCH 10/85] Delete Types doc files --- docs/source/pyrogram/types/Audio.rst | 5 ----- docs/source/pyrogram/types/CallbackQuery.rst | 5 ----- docs/source/pyrogram/types/Chat.rst | 5 ----- docs/source/pyrogram/types/ChatMember.rst | 5 ----- docs/source/pyrogram/types/ChatPhoto.rst | 5 ----- docs/source/pyrogram/types/Contact.rst | 5 ----- docs/source/pyrogram/types/Document.rst | 5 ----- docs/source/pyrogram/types/GIF.rst | 5 ----- docs/source/pyrogram/types/InputMediaPhoto.rst | 5 ----- docs/source/pyrogram/types/InputMediaVideo.rst | 5 ----- docs/source/pyrogram/types/InputPhoneContact.rst | 5 ----- docs/source/pyrogram/types/Location.rst | 5 ----- docs/source/pyrogram/types/Message.rst | 5 ----- docs/source/pyrogram/types/MessageEntity.rst | 5 ----- docs/source/pyrogram/types/Messages.rst | 5 ----- docs/source/pyrogram/types/Photo.rst | 5 ----- docs/source/pyrogram/types/PhotoSize.rst | 5 ----- docs/source/pyrogram/types/Sticker.rst | 5 ----- docs/source/pyrogram/types/Update.rst | 5 ----- docs/source/pyrogram/types/User.rst | 5 ----- docs/source/pyrogram/types/UserProfilePhotos.rst | 5 ----- docs/source/pyrogram/types/Venue.rst | 5 ----- docs/source/pyrogram/types/Video.rst | 5 ----- docs/source/pyrogram/types/VideoNote.rst | 5 ----- docs/source/pyrogram/types/Voice.rst | 5 ----- docs/source/pyrogram/types/reply_markup/ForceReply.rst | 5 ----- .../pyrogram/types/reply_markup/InlineKeyboardButton.rst | 5 ----- .../pyrogram/types/reply_markup/InlineKeyboardMarkup.rst | 5 ----- docs/source/pyrogram/types/reply_markup/KeyboardButton.rst | 5 ----- .../pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst | 5 ----- .../pyrogram/types/reply_markup/ReplyKeyboardRemove.rst | 5 ----- 31 files changed, 155 deletions(-) delete mode 100644 docs/source/pyrogram/types/Audio.rst delete mode 100644 docs/source/pyrogram/types/CallbackQuery.rst delete mode 100644 docs/source/pyrogram/types/Chat.rst delete mode 100644 docs/source/pyrogram/types/ChatMember.rst delete mode 100644 docs/source/pyrogram/types/ChatPhoto.rst delete mode 100644 docs/source/pyrogram/types/Contact.rst delete mode 100644 docs/source/pyrogram/types/Document.rst delete mode 100644 docs/source/pyrogram/types/GIF.rst delete mode 100644 docs/source/pyrogram/types/InputMediaPhoto.rst delete mode 100644 docs/source/pyrogram/types/InputMediaVideo.rst delete mode 100644 docs/source/pyrogram/types/InputPhoneContact.rst delete mode 100644 docs/source/pyrogram/types/Location.rst delete mode 100644 docs/source/pyrogram/types/Message.rst delete mode 100644 docs/source/pyrogram/types/MessageEntity.rst delete mode 100644 docs/source/pyrogram/types/Messages.rst delete mode 100644 docs/source/pyrogram/types/Photo.rst delete mode 100644 docs/source/pyrogram/types/PhotoSize.rst delete mode 100644 docs/source/pyrogram/types/Sticker.rst delete mode 100644 docs/source/pyrogram/types/Update.rst delete mode 100644 docs/source/pyrogram/types/User.rst delete mode 100644 docs/source/pyrogram/types/UserProfilePhotos.rst delete mode 100644 docs/source/pyrogram/types/Venue.rst delete mode 100644 docs/source/pyrogram/types/Video.rst delete mode 100644 docs/source/pyrogram/types/VideoNote.rst delete mode 100644 docs/source/pyrogram/types/Voice.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/ForceReply.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/InlineKeyboardButton.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/InlineKeyboardMarkup.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/KeyboardButton.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst delete mode 100644 docs/source/pyrogram/types/reply_markup/ReplyKeyboardRemove.rst diff --git a/docs/source/pyrogram/types/Audio.rst b/docs/source/pyrogram/types/Audio.rst deleted file mode 100644 index 66ccb32a..00000000 --- a/docs/source/pyrogram/types/Audio.rst +++ /dev/null @@ -1,5 +0,0 @@ -Audio -===== - -.. autoclass:: pyrogram.Audio - :members: diff --git a/docs/source/pyrogram/types/CallbackQuery.rst b/docs/source/pyrogram/types/CallbackQuery.rst deleted file mode 100644 index 9ce0a578..00000000 --- a/docs/source/pyrogram/types/CallbackQuery.rst +++ /dev/null @@ -1,5 +0,0 @@ -CallbackQuery -============= - -.. autoclass:: pyrogram.CallbackQuery - :members: diff --git a/docs/source/pyrogram/types/Chat.rst b/docs/source/pyrogram/types/Chat.rst deleted file mode 100644 index 50a26838..00000000 --- a/docs/source/pyrogram/types/Chat.rst +++ /dev/null @@ -1,5 +0,0 @@ -Chat -==== - -.. autoclass:: pyrogram.Chat - :members: diff --git a/docs/source/pyrogram/types/ChatMember.rst b/docs/source/pyrogram/types/ChatMember.rst deleted file mode 100644 index 0c4f45a3..00000000 --- a/docs/source/pyrogram/types/ChatMember.rst +++ /dev/null @@ -1,5 +0,0 @@ -ChatMember -========== - -.. autoclass:: pyrogram.ChatMember - :members: diff --git a/docs/source/pyrogram/types/ChatPhoto.rst b/docs/source/pyrogram/types/ChatPhoto.rst deleted file mode 100644 index 2b6b49e5..00000000 --- a/docs/source/pyrogram/types/ChatPhoto.rst +++ /dev/null @@ -1,5 +0,0 @@ -ChatPhoto -========= - -.. autoclass:: pyrogram.ChatPhoto - :members: diff --git a/docs/source/pyrogram/types/Contact.rst b/docs/source/pyrogram/types/Contact.rst deleted file mode 100644 index 7d8b0fb2..00000000 --- a/docs/source/pyrogram/types/Contact.rst +++ /dev/null @@ -1,5 +0,0 @@ -Contact -======= - -.. autoclass:: pyrogram.Contact - :members: diff --git a/docs/source/pyrogram/types/Document.rst b/docs/source/pyrogram/types/Document.rst deleted file mode 100644 index 03a57753..00000000 --- a/docs/source/pyrogram/types/Document.rst +++ /dev/null @@ -1,5 +0,0 @@ -Document -======== - -.. autoclass:: pyrogram.Document - :members: diff --git a/docs/source/pyrogram/types/GIF.rst b/docs/source/pyrogram/types/GIF.rst deleted file mode 100644 index 501f187f..00000000 --- a/docs/source/pyrogram/types/GIF.rst +++ /dev/null @@ -1,5 +0,0 @@ -GIF -=== - -.. autoclass:: pyrogram.GIF - :members: diff --git a/docs/source/pyrogram/types/InputMediaPhoto.rst b/docs/source/pyrogram/types/InputMediaPhoto.rst deleted file mode 100644 index aaf8548f..00000000 --- a/docs/source/pyrogram/types/InputMediaPhoto.rst +++ /dev/null @@ -1,5 +0,0 @@ -InputMediaPhoto -=============== - -.. autoclass:: pyrogram.InputMediaPhoto - :members: diff --git a/docs/source/pyrogram/types/InputMediaVideo.rst b/docs/source/pyrogram/types/InputMediaVideo.rst deleted file mode 100644 index 4df4d128..00000000 --- a/docs/source/pyrogram/types/InputMediaVideo.rst +++ /dev/null @@ -1,5 +0,0 @@ -InputMediaVideo -=============== - -.. autoclass:: pyrogram.InputMediaVideo - :members: diff --git a/docs/source/pyrogram/types/InputPhoneContact.rst b/docs/source/pyrogram/types/InputPhoneContact.rst deleted file mode 100644 index bc4e38bc..00000000 --- a/docs/source/pyrogram/types/InputPhoneContact.rst +++ /dev/null @@ -1,5 +0,0 @@ -InputPhoneContact -================= - -.. autoclass:: pyrogram.InputPhoneContact - :members: diff --git a/docs/source/pyrogram/types/Location.rst b/docs/source/pyrogram/types/Location.rst deleted file mode 100644 index 99aeaa70..00000000 --- a/docs/source/pyrogram/types/Location.rst +++ /dev/null @@ -1,5 +0,0 @@ -Location -======== - -.. autoclass:: pyrogram.Location - :members: diff --git a/docs/source/pyrogram/types/Message.rst b/docs/source/pyrogram/types/Message.rst deleted file mode 100644 index 432693fd..00000000 --- a/docs/source/pyrogram/types/Message.rst +++ /dev/null @@ -1,5 +0,0 @@ -Message -======= - -.. autoclass:: pyrogram.Message - :members: diff --git a/docs/source/pyrogram/types/MessageEntity.rst b/docs/source/pyrogram/types/MessageEntity.rst deleted file mode 100644 index 4f2f3be0..00000000 --- a/docs/source/pyrogram/types/MessageEntity.rst +++ /dev/null @@ -1,5 +0,0 @@ -MessageEntity -============= - -.. autoclass:: pyrogram.MessageEntity - :members: diff --git a/docs/source/pyrogram/types/Messages.rst b/docs/source/pyrogram/types/Messages.rst deleted file mode 100644 index f740d092..00000000 --- a/docs/source/pyrogram/types/Messages.rst +++ /dev/null @@ -1,5 +0,0 @@ -Messages -======== - -.. autoclass:: pyrogram.Messages - :members: diff --git a/docs/source/pyrogram/types/Photo.rst b/docs/source/pyrogram/types/Photo.rst deleted file mode 100644 index 78fe13f4..00000000 --- a/docs/source/pyrogram/types/Photo.rst +++ /dev/null @@ -1,5 +0,0 @@ -Photo -===== - -.. autoclass:: pyrogram.Photo - :members: diff --git a/docs/source/pyrogram/types/PhotoSize.rst b/docs/source/pyrogram/types/PhotoSize.rst deleted file mode 100644 index 7ced6190..00000000 --- a/docs/source/pyrogram/types/PhotoSize.rst +++ /dev/null @@ -1,5 +0,0 @@ -PhotoSize -========= - -.. autoclass:: pyrogram.PhotoSize - :members: diff --git a/docs/source/pyrogram/types/Sticker.rst b/docs/source/pyrogram/types/Sticker.rst deleted file mode 100644 index d2646c99..00000000 --- a/docs/source/pyrogram/types/Sticker.rst +++ /dev/null @@ -1,5 +0,0 @@ -Sticker -======= - -.. autoclass:: pyrogram.Sticker - :members: diff --git a/docs/source/pyrogram/types/Update.rst b/docs/source/pyrogram/types/Update.rst deleted file mode 100644 index 1fb22b00..00000000 --- a/docs/source/pyrogram/types/Update.rst +++ /dev/null @@ -1,5 +0,0 @@ -Update -====== - -.. autoclass:: pyrogram.Update - :members: diff --git a/docs/source/pyrogram/types/User.rst b/docs/source/pyrogram/types/User.rst deleted file mode 100644 index f0074a93..00000000 --- a/docs/source/pyrogram/types/User.rst +++ /dev/null @@ -1,5 +0,0 @@ -User -==== - -.. autoclass:: pyrogram.User - :members: diff --git a/docs/source/pyrogram/types/UserProfilePhotos.rst b/docs/source/pyrogram/types/UserProfilePhotos.rst deleted file mode 100644 index 8c9c4d75..00000000 --- a/docs/source/pyrogram/types/UserProfilePhotos.rst +++ /dev/null @@ -1,5 +0,0 @@ -UserProfilePhotos -================= - -.. autoclass:: pyrogram.UserProfilePhotos - :members: diff --git a/docs/source/pyrogram/types/Venue.rst b/docs/source/pyrogram/types/Venue.rst deleted file mode 100644 index 471ab026..00000000 --- a/docs/source/pyrogram/types/Venue.rst +++ /dev/null @@ -1,5 +0,0 @@ -Venue -===== - -.. autoclass:: pyrogram.Venue - :members: diff --git a/docs/source/pyrogram/types/Video.rst b/docs/source/pyrogram/types/Video.rst deleted file mode 100644 index de28ae1c..00000000 --- a/docs/source/pyrogram/types/Video.rst +++ /dev/null @@ -1,5 +0,0 @@ -Video -===== - -.. autoclass:: pyrogram.Video - :members: diff --git a/docs/source/pyrogram/types/VideoNote.rst b/docs/source/pyrogram/types/VideoNote.rst deleted file mode 100644 index 69667454..00000000 --- a/docs/source/pyrogram/types/VideoNote.rst +++ /dev/null @@ -1,5 +0,0 @@ -VideoNote -========= - -.. autoclass:: pyrogram.VideoNote - :members: diff --git a/docs/source/pyrogram/types/Voice.rst b/docs/source/pyrogram/types/Voice.rst deleted file mode 100644 index c80ce124..00000000 --- a/docs/source/pyrogram/types/Voice.rst +++ /dev/null @@ -1,5 +0,0 @@ -Voice -===== - -.. autoclass:: pyrogram.Voice - :members: diff --git a/docs/source/pyrogram/types/reply_markup/ForceReply.rst b/docs/source/pyrogram/types/reply_markup/ForceReply.rst deleted file mode 100644 index db70a834..00000000 --- a/docs/source/pyrogram/types/reply_markup/ForceReply.rst +++ /dev/null @@ -1,5 +0,0 @@ -ForceReply -========== - -.. autoclass:: pyrogram.ForceReply - :members: diff --git a/docs/source/pyrogram/types/reply_markup/InlineKeyboardButton.rst b/docs/source/pyrogram/types/reply_markup/InlineKeyboardButton.rst deleted file mode 100644 index 2e536596..00000000 --- a/docs/source/pyrogram/types/reply_markup/InlineKeyboardButton.rst +++ /dev/null @@ -1,5 +0,0 @@ -InlineKeyboardButton -==================== - -.. autoclass:: pyrogram.InlineKeyboardButton - :members: diff --git a/docs/source/pyrogram/types/reply_markup/InlineKeyboardMarkup.rst b/docs/source/pyrogram/types/reply_markup/InlineKeyboardMarkup.rst deleted file mode 100644 index 7ffa2582..00000000 --- a/docs/source/pyrogram/types/reply_markup/InlineKeyboardMarkup.rst +++ /dev/null @@ -1,5 +0,0 @@ -InlineKeyboardMarkup -==================== - -.. autoclass:: pyrogram.InlineKeyboardMarkup - :members: diff --git a/docs/source/pyrogram/types/reply_markup/KeyboardButton.rst b/docs/source/pyrogram/types/reply_markup/KeyboardButton.rst deleted file mode 100644 index 69488656..00000000 --- a/docs/source/pyrogram/types/reply_markup/KeyboardButton.rst +++ /dev/null @@ -1,5 +0,0 @@ -KeyboardButton -============== - -.. autoclass:: pyrogram.KeyboardButton - :members: diff --git a/docs/source/pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst b/docs/source/pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst deleted file mode 100644 index 2b1e6d16..00000000 --- a/docs/source/pyrogram/types/reply_markup/ReplyKeyboardMarkup.rst +++ /dev/null @@ -1,5 +0,0 @@ -ReplyKeyboardMarkup -=================== - -.. autoclass:: pyrogram.ReplyKeyboardMarkup - :members: diff --git a/docs/source/pyrogram/types/reply_markup/ReplyKeyboardRemove.rst b/docs/source/pyrogram/types/reply_markup/ReplyKeyboardRemove.rst deleted file mode 100644 index 4146d564..00000000 --- a/docs/source/pyrogram/types/reply_markup/ReplyKeyboardRemove.rst +++ /dev/null @@ -1,5 +0,0 @@ -ReplyKeyboardRemove -=================== - -.. autoclass:: pyrogram.ReplyKeyboardRemove - :members: From fb9fa41c37ad86e108602c17df145411a7427e59 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 25 Jul 2018 22:23:17 +0200 Subject: [PATCH 11/85] Add new Types index page --- docs/source/pyrogram/types/index.rst | 170 ++++++++++++++++++++++++--- 1 file changed, 155 insertions(+), 15 deletions(-) diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/types/index.rst index ff3de94e..d93ecceb 100644 --- a/docs/source/pyrogram/types/index.rst +++ b/docs/source/pyrogram/types/index.rst @@ -1,16 +1,34 @@ -:tocdepth: 1 - Types ===== -.. toctree:: +.. currentmodule:: pyrogram + +Users & Chats +------------- + +.. autosummary:: + :nosignatures: + User Chat + ChatPhoto + ChatMember + ChatMembers + Dialog + Dialogs + +Messages & Media +---------------- + +.. autosummary:: + :nosignatures: + Message - MessageEntity Messages + MessageEntity Photo PhotoSize + UserProfilePhotos Audio Document GIF @@ -20,17 +38,139 @@ Types Contact Location Venue - UserProfilePhotos - ChatPhoto - ChatMember + Sticker + +Bots +---- + +.. autosummary:: + :nosignatures: + + ReplyKeyboardMarkup + KeyboardButton + ReplyKeyboardRemove + InlineKeyboardMarkup + InlineKeyboardButton + ForceReply + CallbackQuery + +Input Media +----------- + +.. autosummary:: + :nosignatures: + InputMediaPhoto InputMediaVideo InputPhoneContact - Sticker - reply_markup/ForceReply - reply_markup/InlineKeyboardButton - reply_markup/InlineKeyboardMarkup - reply_markup/KeyboardButton - reply_markup/ReplyKeyboardMarkup - reply_markup/ReplyKeyboardRemove - CallbackQuery \ No newline at end of file + +.. User & Chats + ------------ + +.. autoclass:: User + :members: + +.. autoclass:: Chat + :members: + +.. autoclass:: ChatPhoto + :members: + +.. autoclass:: ChatMember + :members: + +.. autoclass:: ChatMembers + :members: + +.. autoclass:: Dialog + :members: + +.. autoclass:: Dialogs + :members: + +.. Messages & Media + ---------------- + +.. autoclass:: Message + :members: + +.. autoclass:: Messages + :members: + +.. autoclass:: MessageEntity + :members: + +.. autoclass:: Photo + :members: + +.. autoclass:: PhotoSize + :members: + +.. autoclass:: UserProfilePhotos + :members: + +.. autoclass:: Audio + :members: + +.. autoclass:: Document + :members: + +.. autoclass:: GIF + :members: + +.. autoclass:: Video + :members: + +.. autoclass:: Voice + :members: + +.. autoclass:: VideoNote + :members: + +.. autoclass:: Contact + :members: + +.. autoclass:: Location + :members: + +.. autoclass:: Venue + :members: + +.. autoclass:: Sticker + :members: + +.. Bots + ---- + +.. autoclass:: ReplyKeyboardMarkup + :members: + +.. autoclass:: KeyboardButton + :members: + +.. autoclass:: ReplyKeyboardRemove + :members: + +.. autoclass:: InlineKeyboardMarkup + :members: + +.. autoclass:: InlineKeyboardButton + :members: + +.. autoclass:: ForceReply + :members: + +.. autoclass:: CallbackQuery + :members: + +.. Input Media + ----------- + +.. autoclass:: InputMediaPhoto + :members: + +.. autoclass:: InputMediaVideo + :members: + +.. autoclass:: InputPhoneContact + :members: From e9cba4609a8b6b97ecde2565dba0f1e45162d47e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 26 Jul 2018 19:32:12 +0200 Subject: [PATCH 12/85] Update get_chat_member docstrings --- pyrogram/client/methods/chats/get_chat_member.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index c4fe0715..be2a77b9 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -24,7 +24,7 @@ class GetChatMember(BaseClient): def get_chat_member(self, chat_id: int or str, user_id: int or str): - """Use this method to get information about a single member of a chat. + """Use this method to get information about one member of a chat. Args: chat_id (``int`` | ``str``): From f4175b041c34cc42715ce0488fad83a87867407a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 26 Jul 2018 19:34:21 +0200 Subject: [PATCH 13/85] Document ChatMembers --- pyrogram/client/types/chat_members.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/chat_members.py b/pyrogram/client/types/chat_members.py index 658a3086..622f8abc 100644 --- a/pyrogram/client/types/chat_members.py +++ b/pyrogram/client/types/chat_members.py @@ -20,7 +20,15 @@ from pyrogram.api.core import Object class ChatMembers(Object): - # TODO: Docstrings + """This object contains information about the members list of a chat. + + Args: + total_count (``int``): + Total number of members the chat has. + + chat_members (List of :obj:`ChatMember `): + Requested chat members. + """ ID = 0xb0700030 From 32468e5ab0359f2eba1d79f29b0c66210520f976 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 27 Jul 2018 00:40:08 +0200 Subject: [PATCH 14/85] Remove hints about using t.me/joinchat/ links as chat ids Such links don't work reliably with the current implementation --- pyrogram/client/methods/bots/request_callback_answer.py | 1 - pyrogram/client/methods/bots/send_inline_bot_result.py | 1 - pyrogram/client/methods/chats/delete_chat_photo.py | 1 - pyrogram/client/methods/chats/get_chat.py | 1 - pyrogram/client/methods/chats/get_chat_member.py | 2 -- pyrogram/client/methods/chats/get_chat_members.py | 1 - pyrogram/client/methods/chats/kick_chat_member.py | 1 - pyrogram/client/methods/chats/pin_chat_message.py | 1 - pyrogram/client/methods/chats/promote_chat_member.py | 1 - pyrogram/client/methods/chats/restrict_chat_member.py | 1 - pyrogram/client/methods/chats/set_chat_description.py | 1 - pyrogram/client/methods/chats/set_chat_photo.py | 1 - pyrogram/client/methods/chats/set_chat_title.py | 1 - pyrogram/client/methods/chats/unban_chat_member.py | 1 - pyrogram/client/methods/chats/unpin_chat_message.py | 1 - pyrogram/client/methods/messages/delete_messages.py | 1 - pyrogram/client/methods/messages/edit_message_caption.py | 1 - pyrogram/client/methods/messages/edit_message_reply_markup.py | 1 - pyrogram/client/methods/messages/edit_message_text.py | 1 - pyrogram/client/methods/messages/forward_messages.py | 2 -- pyrogram/client/methods/messages/get_history.py | 1 - pyrogram/client/methods/messages/get_messages.py | 1 - pyrogram/client/methods/messages/send_audio.py | 1 - pyrogram/client/methods/messages/send_chat_action.py | 1 - pyrogram/client/methods/messages/send_contact.py | 1 - pyrogram/client/methods/messages/send_document.py | 1 - pyrogram/client/methods/messages/send_gif.py | 1 - pyrogram/client/methods/messages/send_location.py | 1 - pyrogram/client/methods/messages/send_media_group.py | 1 - pyrogram/client/methods/messages/send_message.py | 1 - pyrogram/client/methods/messages/send_photo.py | 1 - pyrogram/client/methods/messages/send_sticker.py | 1 - pyrogram/client/methods/messages/send_venue.py | 1 - pyrogram/client/methods/messages/send_video.py | 1 - pyrogram/client/methods/messages/send_video_note.py | 1 - pyrogram/client/methods/messages/send_voice.py | 1 - pyrogram/client/methods/users/get_user_profile_photos.py | 1 - pyrogram/client/types/message.py | 1 - 38 files changed, 40 deletions(-) diff --git a/pyrogram/client/methods/bots/request_callback_answer.py b/pyrogram/client/methods/bots/request_callback_answer.py index 52dab58c..b242f4af 100644 --- a/pyrogram/client/methods/bots/request_callback_answer.py +++ b/pyrogram/client/methods/bots/request_callback_answer.py @@ -33,7 +33,6 @@ class RequestCallbackAnswer(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): The message id the inline keyboard is attached on. diff --git a/pyrogram/client/methods/bots/send_inline_bot_result.py b/pyrogram/client/methods/bots/send_inline_bot_result.py index c194298a..bdfcc65c 100644 --- a/pyrogram/client/methods/bots/send_inline_bot_result.py +++ b/pyrogram/client/methods/bots/send_inline_bot_result.py @@ -35,7 +35,6 @@ class SendInlineBotResult(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. query_id (``int``): Unique identifier for the answered query. diff --git a/pyrogram/client/methods/chats/delete_chat_photo.py b/pyrogram/client/methods/chats/delete_chat_photo.py index 57d90b11..31e02923 100644 --- a/pyrogram/client/methods/chats/delete_chat_photo.py +++ b/pyrogram/client/methods/chats/delete_chat_photo.py @@ -33,7 +33,6 @@ class DeleteChatPhoto(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. Returns: True on success. diff --git a/pyrogram/client/methods/chats/get_chat.py b/pyrogram/client/methods/chats/get_chat.py index 588ac468..5cb22db1 100644 --- a/pyrogram/client/methods/chats/get_chat.py +++ b/pyrogram/client/methods/chats/get_chat.py @@ -28,7 +28,6 @@ class GetChat(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. Returns: On success, a :obj:`Chat ` object is returned. diff --git a/pyrogram/client/methods/chats/get_chat_member.py b/pyrogram/client/methods/chats/get_chat_member.py index be2a77b9..51e07f91 100644 --- a/pyrogram/client/methods/chats/get_chat_member.py +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -29,13 +29,11 @@ class GetChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``):: Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. Returns: On success, a :obj:`ChatMember ` object is returned. diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index cfc9861e..818c667e 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -44,7 +44,6 @@ class GetChatMembers(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. offset (``int``, *optional*): Sequential number of the first member to be returned. diff --git a/pyrogram/client/methods/chats/kick_chat_member.py b/pyrogram/client/methods/chats/kick_chat_member.py index 6275718c..1c849285 100644 --- a/pyrogram/client/methods/chats/kick_chat_member.py +++ b/pyrogram/client/methods/chats/kick_chat_member.py @@ -38,7 +38,6 @@ class KickChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/client/methods/chats/pin_chat_message.py b/pyrogram/client/methods/chats/pin_chat_message.py index e9bc533e..eb653f3c 100644 --- a/pyrogram/client/methods/chats/pin_chat_message.py +++ b/pyrogram/client/methods/chats/pin_chat_message.py @@ -29,7 +29,6 @@ class PinChatMessage(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): Identifier of a message to pin. diff --git a/pyrogram/client/methods/chats/promote_chat_member.py b/pyrogram/client/methods/chats/promote_chat_member.py index eb70578a..134d1ba3 100644 --- a/pyrogram/client/methods/chats/promote_chat_member.py +++ b/pyrogram/client/methods/chats/promote_chat_member.py @@ -39,7 +39,6 @@ class PromoteChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/client/methods/chats/restrict_chat_member.py b/pyrogram/client/methods/chats/restrict_chat_member.py index ae1e4d9c..fb11a989 100644 --- a/pyrogram/client/methods/chats/restrict_chat_member.py +++ b/pyrogram/client/methods/chats/restrict_chat_member.py @@ -36,7 +36,6 @@ class RestrictChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/client/methods/chats/set_chat_description.py b/pyrogram/client/methods/chats/set_chat_description.py index c9597a62..f9b5c7a2 100644 --- a/pyrogram/client/methods/chats/set_chat_description.py +++ b/pyrogram/client/methods/chats/set_chat_description.py @@ -28,7 +28,6 @@ class SetChatDescription(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. description (``str``): New chat description, 0-255 characters. diff --git a/pyrogram/client/methods/chats/set_chat_photo.py b/pyrogram/client/methods/chats/set_chat_photo.py index d98fefde..224a8d99 100644 --- a/pyrogram/client/methods/chats/set_chat_photo.py +++ b/pyrogram/client/methods/chats/set_chat_photo.py @@ -37,7 +37,6 @@ class SetChatPhoto(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. photo (``str``): New chat photo. You can pass a :class:`Photo` id or a file path to upload a new photo. diff --git a/pyrogram/client/methods/chats/set_chat_title.py b/pyrogram/client/methods/chats/set_chat_title.py index f6644a01..98da8737 100644 --- a/pyrogram/client/methods/chats/set_chat_title.py +++ b/pyrogram/client/methods/chats/set_chat_title.py @@ -33,7 +33,6 @@ class SetChatTitle(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. title (``str``): New chat title, 1-255 characters. diff --git a/pyrogram/client/methods/chats/unban_chat_member.py b/pyrogram/client/methods/chats/unban_chat_member.py index b0916eb4..e191a0b7 100644 --- a/pyrogram/client/methods/chats/unban_chat_member.py +++ b/pyrogram/client/methods/chats/unban_chat_member.py @@ -31,7 +31,6 @@ class UnbanChatMember(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. user_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target user. diff --git a/pyrogram/client/methods/chats/unpin_chat_message.py b/pyrogram/client/methods/chats/unpin_chat_message.py index b1eeec79..4b0ee46b 100644 --- a/pyrogram/client/methods/chats/unpin_chat_message.py +++ b/pyrogram/client/methods/chats/unpin_chat_message.py @@ -29,7 +29,6 @@ class UnpinChatMessage(BaseClient): Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. - For a private channel/supergroup you can use its *t.me/joinchat/* link. Returns: True on success. diff --git a/pyrogram/client/methods/messages/delete_messages.py b/pyrogram/client/methods/messages/delete_messages.py index a4c97c76..8932a699 100644 --- a/pyrogram/client/methods/messages/delete_messages.py +++ b/pyrogram/client/methods/messages/delete_messages.py @@ -38,7 +38,6 @@ class DeleteMessages(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_ids (``iterable``): A list of Message identifiers to delete or a single message id. diff --git a/pyrogram/client/methods/messages/edit_message_caption.py b/pyrogram/client/methods/messages/edit_message_caption.py index 25276dc2..a83c670e 100644 --- a/pyrogram/client/methods/messages/edit_message_caption.py +++ b/pyrogram/client/methods/messages/edit_message_caption.py @@ -34,7 +34,6 @@ class EditMessageCaption(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): Message identifier in the chat specified in chat_id. diff --git a/pyrogram/client/methods/messages/edit_message_reply_markup.py b/pyrogram/client/methods/messages/edit_message_reply_markup.py index b840adab..6d846ca4 100644 --- a/pyrogram/client/methods/messages/edit_message_reply_markup.py +++ b/pyrogram/client/methods/messages/edit_message_reply_markup.py @@ -32,7 +32,6 @@ class EditMessageReplyMarkup(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): Message identifier in the chat specified in chat_id. diff --git a/pyrogram/client/methods/messages/edit_message_text.py b/pyrogram/client/methods/messages/edit_message_text.py index 741c0890..379a1988 100644 --- a/pyrogram/client/methods/messages/edit_message_text.py +++ b/pyrogram/client/methods/messages/edit_message_text.py @@ -35,7 +35,6 @@ class EditMessageText(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_id (``int``): Message identifier in the chat specified in chat_id. diff --git a/pyrogram/client/methods/messages/forward_messages.py b/pyrogram/client/methods/messages/forward_messages.py index 606e54b5..2b24aadf 100644 --- a/pyrogram/client/methods/messages/forward_messages.py +++ b/pyrogram/client/methods/messages/forward_messages.py @@ -33,13 +33,11 @@ class ForwardMessages(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. from_chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the source chat where the original message was sent. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_ids (``iterable``): A list of Message identifiers in the chat specified in *from_chat_id* or a single message id. diff --git a/pyrogram/client/methods/messages/get_history.py b/pyrogram/client/methods/messages/get_history.py index 4089dde9..66949a1c 100644 --- a/pyrogram/client/methods/messages/get_history.py +++ b/pyrogram/client/methods/messages/get_history.py @@ -37,7 +37,6 @@ class GetHistory(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. offset (``int``, *optional*) Sequential number of the first message to be returned. diff --git a/pyrogram/client/methods/messages/get_messages.py b/pyrogram/client/methods/messages/get_messages.py index 3c8b4dbe..c2751d74 100644 --- a/pyrogram/client/methods/messages/get_messages.py +++ b/pyrogram/client/methods/messages/get_messages.py @@ -33,7 +33,6 @@ class GetMessages(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. message_ids (``iterable``): A list of Message identifiers in the chat specified in *chat_id* or a single message id, as integer. diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index 7d590b79..f31ffa21 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -49,7 +49,6 @@ class SendAudio(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. audio (``str``): Audio file to send. diff --git a/pyrogram/client/methods/messages/send_chat_action.py b/pyrogram/client/methods/messages/send_chat_action.py index 49625b48..1117a2dd 100644 --- a/pyrogram/client/methods/messages/send_chat_action.py +++ b/pyrogram/client/methods/messages/send_chat_action.py @@ -32,7 +32,6 @@ class SendChatAction(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. action (:obj:`ChatAction ` | ``str``): Type of action to broadcast. diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index 1a894e30..99a96abc 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -37,7 +37,6 @@ class SendContact(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. phone_number (``str``): Contact's phone number. diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index b2b5c532..01c3eca5 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -44,7 +44,6 @@ class SendDocument(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. document (``str``): File to send. diff --git a/pyrogram/client/methods/messages/send_gif.py b/pyrogram/client/methods/messages/send_gif.py index a4a14d84..ca323f1d 100644 --- a/pyrogram/client/methods/messages/send_gif.py +++ b/pyrogram/client/methods/messages/send_gif.py @@ -48,7 +48,6 @@ class SendGIF(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. gif (``str``): GIF to send. diff --git a/pyrogram/client/methods/messages/send_location.py b/pyrogram/client/methods/messages/send_location.py index a3db2561..49a41256 100644 --- a/pyrogram/client/methods/messages/send_location.py +++ b/pyrogram/client/methods/messages/send_location.py @@ -35,7 +35,6 @@ class SendLocation(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. latitude (``float``): Latitude of the location. diff --git a/pyrogram/client/methods/messages/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py index 297d8f83..5465c9f2 100644 --- a/pyrogram/client/methods/messages/send_media_group.py +++ b/pyrogram/client/methods/messages/send_media_group.py @@ -44,7 +44,6 @@ class SendMediaGroup(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. media (``list``): A list containing either :obj:`InputMediaPhoto ` or diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index 44acaa2e..b770133e 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -37,7 +37,6 @@ class SendMessage(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. text (``str``): Text of the message to be sent. diff --git a/pyrogram/client/methods/messages/send_photo.py b/pyrogram/client/methods/messages/send_photo.py index a6264bf3..2d0036f2 100644 --- a/pyrogram/client/methods/messages/send_photo.py +++ b/pyrogram/client/methods/messages/send_photo.py @@ -44,7 +44,6 @@ class SendPhoto(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. photo (``str``): Photo to send. diff --git a/pyrogram/client/methods/messages/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py index fbf7a205..9f1f64da 100644 --- a/pyrogram/client/methods/messages/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -41,7 +41,6 @@ class SendSticker(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. sticker (``str``): Sticker to send. diff --git a/pyrogram/client/methods/messages/send_venue.py b/pyrogram/client/methods/messages/send_venue.py index 50946e86..39ae0ca2 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -38,7 +38,6 @@ class SendVenue(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. latitude (``float``): Latitude of the venue. diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index b86b4702..87063ee3 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -49,7 +49,6 @@ class SendVideo(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. video (``str``): Video to send. diff --git a/pyrogram/client/methods/messages/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py index a266e5dd..6adc6497 100644 --- a/pyrogram/client/methods/messages/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -44,7 +44,6 @@ class SendVideoNote(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. video_note (``str``): Video note to send. diff --git a/pyrogram/client/methods/messages/send_voice.py b/pyrogram/client/methods/messages/send_voice.py index f4fe4229..5b577672 100644 --- a/pyrogram/client/methods/messages/send_voice.py +++ b/pyrogram/client/methods/messages/send_voice.py @@ -45,7 +45,6 @@ class SendVoice(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. voice (``str``): Audio file to send. diff --git a/pyrogram/client/methods/users/get_user_profile_photos.py b/pyrogram/client/methods/users/get_user_profile_photos.py index 5613c21d..127ad232 100644 --- a/pyrogram/client/methods/users/get_user_profile_photos.py +++ b/pyrogram/client/methods/users/get_user_profile_photos.py @@ -32,7 +32,6 @@ class GetUserProfilePhotos(BaseClient): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. offset (``int``, *optional*): Sequential number of the first photo to be returned. diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index db13ccd6..e471c8a5 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -404,7 +404,6 @@ class Message(Object): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - For a private channel/supergroup you can use its *t.me/joinchat/* link. disable_notification (``bool``, *optional*): Sends the message silently. From d270d0d2aa5ad819f4058773a237471b53e97425 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 28 Jul 2018 23:09:44 +0200 Subject: [PATCH 15/85] Remove support for t.me/joinchat/ links in resolve_peer for now Another way, which is 100% reliable, will be implemented Also clean the method a bit by removing useless checks --- pyrogram/client/client.py | 41 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 709ea95a..3af60931 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1011,21 +1011,19 @@ class Client(Methods, BaseClient): self.get_initial_dialogs_chunk() def resolve_peer(self, peer_id: int or str): - """Use this method to get the *InputPeer* of a known *peer_id*. + """Use this method to get the InputPeer of a known peer_id. - It is intended to be used when working with Raw Functions (i.e: a Telegram API method you wish to use which is - not available yet in the Client class as an easy-to-use method). + This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method + you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer + type is required. Args: - peer_id (``int`` | ``str`` | ``Peer``): - The Peer ID you want to extract the InputPeer from. Can be one of these types: ``int`` (direct ID), - ``str`` (@username), :obj:`PeerUser `, - :obj:`PeerChat `, :obj:`PeerChannel ` + peer_id (``int`` | ``str``): + The peer id you want to extract the InputPeer from. + Can be a direct id (int), a username (str) or a phone number (str). Returns: - :obj:`InputPeerUser ` or - :obj:`InputPeerChat ` or - :obj:`InputPeerChannel ` depending on the *peer_id*. + On success, the resolved peer id is returned in form of an InputPeer object. Raises: :class:`Error ` @@ -1034,38 +1032,21 @@ class Client(Methods, BaseClient): if peer_id in ("self", "me"): return types.InputPeerSelf() - match = self.INVITE_LINK_RE.match(peer_id) - - try: - decoded = base64.b64decode(match.group(1) + "=" * (-len(match.group(1)) % 4), "-_") - return self.resolve_peer(struct.unpack(">2iq", decoded)[1]) - except (AttributeError, binascii.Error, struct.error): - pass - peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) try: int(peer_id) except ValueError: - try: - return self.peers_by_username[peer_id] - except KeyError: + if peer_id not in self.peers_by_username: self.send(functions.contacts.ResolveUsername(peer_id)) - return self.peers_by_username[peer_id] + + return self.peers_by_username[peer_id] else: try: return self.peers_by_phone[peer_id] except KeyError: raise PeerIdInvalid - if type(peer_id) is not int: - if isinstance(peer_id, types.PeerUser): - peer_id = peer_id.user_id - elif isinstance(peer_id, types.PeerChat): - peer_id = -peer_id.chat_id - elif isinstance(peer_id, types.PeerChannel): - peer_id = int("-100" + str(peer_id.channel_id)) - try: # User return self.peers_by_id[peer_id] except KeyError: From e682046713174951d341ef4f0fae9563b0bb3dac Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 29 Jul 2018 03:37:50 +0200 Subject: [PATCH 16/85] Fix sphinx compilation warnings --- docs/source/resources/TextFormatting.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/resources/TextFormatting.rst b/docs/source/resources/TextFormatting.rst index aaa78f0a..9b4e2e4c 100644 --- a/docs/source/resources/TextFormatting.rst +++ b/docs/source/resources/TextFormatting.rst @@ -11,7 +11,7 @@ Markdown Style To use this mode, pass :obj:`MARKDOWN ` or "markdown" in the *parse_mode* field when using :obj:`send_message() `. Use the following syntax in your message: -.. code-block:: txt +.. code-block:: text **bold text** @@ -34,7 +34,7 @@ HTML Style To use this mode, pass :obj:`HTML ` or "html" in the *parse_mode* field when using :obj:`send_message() `. The following tags are currently supported: -.. code-block:: txt +.. code-block:: text bold, bold From faef1526a9a1f423c489bd6bd91eeaba81d2087b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 29 Jul 2018 03:38:30 +0200 Subject: [PATCH 17/85] Tidy up HTML syntax example --- docs/source/resources/TextFormatting.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/source/resources/TextFormatting.rst b/docs/source/resources/TextFormatting.rst index 9b4e2e4c..dd619469 100644 --- a/docs/source/resources/TextFormatting.rst +++ b/docs/source/resources/TextFormatting.rst @@ -46,9 +46,7 @@ To use this mode, pass :obj:`HTML ` or "html" in the *p inline fixed-width code -
pre-formatted fixed-width
-    code block
-    
+
pre-formatted fixed-width code block
.. note:: Mentions are only guaranteed to work if you have already met the user (in groups or private chats). From 97f3921729692bf985f8efa3dec4107e8771882b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 29 Jul 2018 03:40:04 +0200 Subject: [PATCH 18/85] Use clearer words and spacing --- docs/source/resources/TextFormatting.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/source/resources/TextFormatting.rst b/docs/source/resources/TextFormatting.rst index dd619469..0ab08694 100644 --- a/docs/source/resources/TextFormatting.rst +++ b/docs/source/resources/TextFormatting.rst @@ -1,8 +1,11 @@ Text Formatting =============== -Pyrogram, just like `Telegram Bot API`_, supports basic Markdown and HTML formatting styles for text messages and -media captions; Markdown uses the same syntax as Telegram Desktop's and is enabled by default. +Pyrogram, just like the `Telegram Bot API`_, natively supports basic Markdown and HTML formatting styles for text +messages and media captions. + +Markdown style uses the same syntax as Telegram Desktop's and is enabled by default. + Beside bold, italic, and pre-formatted code, **Pyrogram does also support inline URLs and inline mentions of users**. Markdown Style From 9d9fc1f94f8547790826b9dcacea3366c1c82542 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 30 Jul 2018 22:59:30 +0200 Subject: [PATCH 19/85] Add InputMedia base class --- pyrogram/client/types/input_media.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pyrogram/client/types/input_media.py diff --git a/pyrogram/client/types/input_media.py b/pyrogram/client/types/input_media.py new file mode 100644 index 00000000..611d5865 --- /dev/null +++ b/pyrogram/client/types/input_media.py @@ -0,0 +1,24 @@ +# 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 . + + +class InputMedia: + def __init__(self, media: str, caption: str, parse_mode: str): + self.media = media + self.caption = caption + self.parse_mode = parse_mode From 486c9433ace001450c9f958d713f283edb63fc67 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 30 Jul 2018 23:01:14 +0200 Subject: [PATCH 20/85] Make InputMediaPhoto inherit from InputMedia --- pyrogram/client/types/input_media_photo.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/input_media_photo.py b/pyrogram/client/types/input_media_photo.py index 336ee849..d58f75a6 100644 --- a/pyrogram/client/types/input_media_photo.py +++ b/pyrogram/client/types/input_media_photo.py @@ -16,8 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from . import InputMedia -class InputMediaPhoto: + +class InputMediaPhoto(InputMedia): """This object represents a photo to be sent inside an album. It is intended to be used with :obj:`send_media_group() `. @@ -41,6 +43,4 @@ class InputMediaPhoto: media: str, caption: str = "", parse_mode: str = ""): - self.media = media - self.caption = caption - self.parse_mode = parse_mode + super().__init__(media, caption, parse_mode) From 2a985e75455856516359563e977e21788af06885 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 30 Jul 2018 23:01:43 +0200 Subject: [PATCH 21/85] Make InputMediaVideo inherit from InputMedia --- pyrogram/client/types/input_media_video.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/input_media_video.py b/pyrogram/client/types/input_media_video.py index eb6c003e..c1f2c9ac 100644 --- a/pyrogram/client/types/input_media_video.py +++ b/pyrogram/client/types/input_media_video.py @@ -16,8 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from . import InputMedia -class InputMediaVideo: + +class InputMediaVideo(InputMedia): """This object represents a video to be sent inside an album. It is intended to be used with :obj:`send_media_group() `. @@ -57,9 +59,8 @@ class InputMediaVideo: height: int = 0, duration: int = 0, supports_streaming: bool = True): - self.media = media - self.caption = caption - self.parse_mode = parse_mode + super().__init__(media, caption, parse_mode) + self.width = width self.height = height self.duration = duration From 5bc9be08586517a5c783da3d1a539bba3734ad10 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 31 Jul 2018 00:14:21 +0200 Subject: [PATCH 22/85] Add InputMediaAudio --- pyrogram/client/types/input_media_audio.py | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 pyrogram/client/types/input_media_audio.py diff --git a/pyrogram/client/types/input_media_audio.py b/pyrogram/client/types/input_media_audio.py new file mode 100644 index 00000000..c556554f --- /dev/null +++ b/pyrogram/client/types/input_media_audio.py @@ -0,0 +1,67 @@ +# 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 . import InputMedia + + +class InputMediaAudio(InputMedia): + """This object represents a video to be sent inside an album. + It is intended to be used with :obj:`send_media_group() `. + + Args: + media (``str``): + Video to send. + Pass a file_id as string to send a video that exists on the Telegram servers or + pass a file path as string to upload a new video that exists on your local machine. + Sending video by a URL is currently unsupported. + + caption (``str``, *optional*): + Caption of the video to be sent, 0-200 characters + + parse_mode (``str``, *optional*): + Use :obj:`MARKDOWN ` or :obj:`HTML ` + if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. + Defaults to Markdown. + + width (``int``, *optional*): + Video width. + + height (``int``, *optional*): + Video height. + + duration (``int``, *optional*): + Video duration. + + supports_streaming (``bool``, *optional*): + Pass True, if the uploaded video is suitable for streaming. + """ + + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = "", + width: int = 0, + height: int = 0, + duration: int = 0, + supports_streaming: bool = True): + super().__init__(media, caption, parse_mode) + + self.width = width + self.height = height + self.duration = duration + self.supports_streaming = supports_streaming From 570128d980a0be22d1b99fe2c0c8d40f282af413 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 31 Jul 2018 00:25:41 +0200 Subject: [PATCH 23/85] Add InputMediaAnimation --- .../client/types/input_media_animation.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pyrogram/client/types/input_media_animation.py diff --git a/pyrogram/client/types/input_media_animation.py b/pyrogram/client/types/input_media_animation.py new file mode 100644 index 00000000..12fe0e03 --- /dev/null +++ b/pyrogram/client/types/input_media_animation.py @@ -0,0 +1,60 @@ +# 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 . import InputMedia + + +class InputMediaAnimation(InputMedia): + """This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. + + Args: + media (``str``): + Animation to send. + Pass a file_id as string to send a file that exists on the Telegram servers or + pass a file path as string to upload a new file that exists on your local machine. + + caption (``str``, *optional*): + Caption of the animation to be sent, 0-200 characters + + parse_mode (``str``, *optional*): + Use :obj:`MARKDOWN ` or :obj:`HTML ` + if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. + Defaults to Markdown. + + width (``int``, *optional*): + Animation width. + + height (``int``, *optional*): + Animation height. + + duration (``int``, *optional*): + Animation duration. + """ + + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = "", + width: int = 0, + height: int = 0, + duration: int = 0): + super().__init__(media, caption, parse_mode) + + self.width = width + self.height = height + self.duration = duration From c62575674717c51d9dbbf2be7d8b8e366dee29b7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 31 Jul 2018 00:29:10 +0200 Subject: [PATCH 24/85] Add InputMediaDocument --- pyrogram/client/types/input_media_document.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pyrogram/client/types/input_media_document.py diff --git a/pyrogram/client/types/input_media_document.py b/pyrogram/client/types/input_media_document.py new file mode 100644 index 00000000..f64da619 --- /dev/null +++ b/pyrogram/client/types/input_media_document.py @@ -0,0 +1,44 @@ +# 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 . import InputMedia + + +class InputMediaDocument(InputMedia): + """This object represents a general file to be sent. + + Args: + media (``str``): + File to send. + Pass a file_id as string to send a file that exists on the Telegram servers or + pass a file path as string to upload a new file that exists on your local machine. + + caption (``str``, *optional*): + Caption of the document to be sent, 0-200 characters + + parse_mode (``str``, *optional*): + Use :obj:`MARKDOWN ` or :obj:`HTML ` + if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. + Defaults to Markdown. + """ + + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = ""): + super().__init__(media, caption, parse_mode) From 92fdf79d545121e18bb5636a285339a5429ef9fc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 1 Aug 2018 21:19:11 +0200 Subject: [PATCH 25/85] Expose the new InputMedia types --- pyrogram/__init__.py | 9 ++++----- pyrogram/client/types/__init__.py | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index f1442596..24bdc1a5 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -28,11 +28,10 @@ __version__ = "0.7.6dev1" from .api.errors import Error from .client.types import ( Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMediaPhoto, - InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, - Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, - Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, - InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, - ReplyKeyboardRemove + InputMediaVideo, InputMediaDocument, InputMediaAudio, InputMediaAnimation, InputPhoneContact, + Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, + UserProfilePhotos, Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, + InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index e6fcc8aa..23c15818 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -23,6 +23,10 @@ from .chat_members import ChatMembers from .chat_photo import ChatPhoto from .dialog import Dialog from .dialogs import Dialogs +from .input_media import InputMedia +from .input_media_animation import InputMediaAnimation +from .input_media_audio import InputMediaAudio +from .input_media_document import InputMediaDocument from .input_media_photo import InputMediaPhoto from .input_media_video import InputMediaVideo from .input_phone_contact import InputPhoneContact From ea0a75bfd702f512f3a1815d82669bb913aa8a63 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 2 Aug 2018 01:10:29 +0200 Subject: [PATCH 26/85] Add edit_message_media method --- .../methods/messages/edit_message_media.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pyrogram/client/methods/messages/edit_message_media.py diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py new file mode 100644 index 00000000..56295749 --- /dev/null +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -0,0 +1,36 @@ +# 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 import functions +from pyrogram.client.ext import BaseClient + + +class EditMessageMedia(BaseClient): + def edit_message_media(self, + chat_id: int or str, + message_id: int, + media, + reply_markup=None): + r = self.send( + functions.messages.EditMessage( + peer=self.resolve_peer(chat_id), + id=message_id, + reply_markup=reply_markup.write() if reply_markup else None, + media=media + ) + ) From e7b27c2c21e567caece838f970c16995b879da1d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 2 Aug 2018 01:12:31 +0200 Subject: [PATCH 27/85] Expose edit_message_media method --- pyrogram/client/methods/messages/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 94279ffd..6de17d7c 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -18,6 +18,7 @@ from .delete_messages import DeleteMessages from .edit_message_caption import EditMessageCaption +from .edit_message_media import EditMessageMedia from .edit_message_reply_markup import EditMessageReplyMarkup from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages @@ -44,6 +45,7 @@ class Messages( DeleteMessages, EditMessageCaption, EditMessageReplyMarkup, + EditMessageMedia, EditMessageText, ForwardMessages, GetHistory, From 6015a14182644b57f76560e74006cdbac4af0574 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:36:38 +0200 Subject: [PATCH 28/85] Add ability to edit photos by uploading new files --- .../methods/messages/edit_message_media.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 56295749..dfee76a8 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -16,8 +16,13 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from pyrogram.api import functions +import os + +from pyrogram.api import functions, types from pyrogram.client.ext import BaseClient +from pyrogram.client.types import ( + InputMediaPhoto +) class EditMessageMedia(BaseClient): @@ -26,11 +31,33 @@ class EditMessageMedia(BaseClient): message_id: int, media, reply_markup=None): + style = self.html if media.parse_mode.lower() == "html" else self.markdown + caption = media.caption + + if isinstance(media, InputMediaPhoto): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedPhoto( + file=self.save_file(media.media) + ) + ) + ) + + media = types.InputMediaPhoto( + id=types.InputPhoto( + id=media.photo.id, + access_hash=media.photo.access_hash + ) + ) + r = self.send( functions.messages.EditMessage( peer=self.resolve_peer(chat_id), id=message_id, reply_markup=reply_markup.write() if reply_markup else None, - media=media + media=media, + **style.parse(caption) ) ) From 8d35559f0bee7ebcba8e8bde294033020dd3e132 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:37:10 +0200 Subject: [PATCH 29/85] Return the higher-level Message object instead of the raw update --- pyrogram/client/methods/messages/edit_message_media.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index dfee76a8..1e42c304 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -19,7 +19,7 @@ import os from pyrogram.api import functions, types -from pyrogram.client.ext import BaseClient +from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( InputMediaPhoto ) @@ -61,3 +61,11 @@ class EditMessageMedia(BaseClient): **style.parse(caption) ) ) + + for i in r.updates: + if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): + return utils.parse_messages( + self, i.message, + {i.id: i for i in r.users}, + {i.id: i for i in r.chats} + ) From a3be6a93550423b3ab35529ab397e5738266ea9f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:38:04 +0200 Subject: [PATCH 30/85] Add support for editing photos with external URLs --- pyrogram/client/methods/messages/edit_message_media.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 1e42c304..35c24f1a 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -51,6 +51,10 @@ class EditMessageMedia(BaseClient): access_hash=media.photo.access_hash ) ) + elif media.media.startswith("http"): + media = types.InputMediaPhotoExternal( + url=media.media + ) r = self.send( functions.messages.EditMessage( From 51eb2f90b983ae53f5116c2a7bfab07875efd133 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 3 Aug 2018 18:38:26 +0200 Subject: [PATCH 31/85] Add support for editing photousing file IDs --- .../methods/messages/edit_message_media.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 35c24f1a..d79ecfbe 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -16,9 +16,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import binascii import os +import struct from pyrogram.api import functions, types +from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( InputMediaPhoto @@ -55,6 +58,28 @@ class EditMessageMedia(BaseClient): media = types.InputMediaPhotoExternal( url=media.media ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Sat, 4 Aug 2018 01:23:31 +0200 Subject: [PATCH 32/85] Add ability to edit video messages --- .../methods/messages/edit_message_media.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index d79ecfbe..02b9062d 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . import binascii +import mimetypes import os import struct @@ -24,7 +25,7 @@ from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( - InputMediaPhoto + InputMediaPhoto, InputMediaVideo ) @@ -81,6 +82,34 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaVideo): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map[".mp4"], + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeVideo( + supports_streaming=media.supports_streaming or None, + duration=media.duration, + w=media.width, + h=media.height + ), + types.DocumentAttributeFilename(os.path.basename(media.media)) + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + r = self.send( functions.messages.EditMessage( peer=self.resolve_peer(chat_id), From 9f725a6bfb299bac73f6d3fe83f11d4a8d8c92c1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 4 Aug 2018 01:27:02 +0200 Subject: [PATCH 33/85] Add support for editing videos using external URLs and file IDs --- .../methods/messages/edit_message_media.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 02b9062d..2ca9ab9f 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -109,6 +109,32 @@ class EditMessageMedia(BaseClient): access_hash=media.document.access_hash ) ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Sun, 5 Aug 2018 10:15:53 +0200 Subject: [PATCH 34/85] Fix InputMediaAudio copy pasta --- pyrogram/client/types/input_media_audio.py | 34 +++++++++------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/pyrogram/client/types/input_media_audio.py b/pyrogram/client/types/input_media_audio.py index c556554f..2c644107 100644 --- a/pyrogram/client/types/input_media_audio.py +++ b/pyrogram/client/types/input_media_audio.py @@ -25,43 +25,37 @@ class InputMediaAudio(InputMedia): Args: media (``str``): - Video to send. - Pass a file_id as string to send a video that exists on the Telegram servers or - pass a file path as string to upload a new video that exists on your local machine. - Sending video by a URL is currently unsupported. + Audio to send. + Pass a file_id as string to send an audio that exists on the Telegram servers or + pass a file path as string to upload a new audio that exists on your local machine. caption (``str``, *optional*): - Caption of the video to be sent, 0-200 characters + Caption of the audio to be sent, 0-200 characters parse_mode (``str``, *optional*): Use :obj:`MARKDOWN ` or :obj:`HTML ` if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your caption. Defaults to Markdown. - width (``int``, *optional*): - Video width. - - height (``int``, *optional*): - Video height. - duration (``int``, *optional*): - Video duration. + Duration of the audio in seconds - supports_streaming (``bool``, *optional*): - Pass True, if the uploaded video is suitable for streaming. + performer (``int``, *optional*): + Performer of the audio + + title (``int``, *optional*): + Title of the audio """ def __init__(self, media: str, caption: str = "", parse_mode: str = "", - width: int = 0, - height: int = 0, duration: int = 0, - supports_streaming: bool = True): + performer: int = "", + title: str = ""): super().__init__(media, caption, parse_mode) - self.width = width - self.height = height self.duration = duration - self.supports_streaming = supports_streaming + self.performer = performer + self.title = title From f7c2dc9d30ff8cfb6a39cda9e3f1b02e5755e87a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 5 Aug 2018 10:25:37 +0200 Subject: [PATCH 35/85] Add support for editing messages with Audio --- .../methods/messages/edit_message_media.py | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 2ca9ab9f..c6b2eb97 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -25,7 +25,7 @@ from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( - InputMediaPhoto, InputMediaVideo + InputMediaPhoto, InputMediaVideo, InputMediaAudio ) @@ -136,6 +136,59 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaAudio): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map.get("." + media.media.split(".")[-1], "audio/mpeg"), + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeAudio( + duration=media.duration, + performer=media.performer, + title=media.title + ), + types.DocumentAttributeFilename(os.path.basename(media.media)) + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Mon, 6 Aug 2018 21:32:38 +0200 Subject: [PATCH 36/85] Rename media type id to animation --- pyrogram/client/ext/base_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index cd54570d..c8a6029d 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -60,7 +60,7 @@ class BaseClient: 5: "document", 8: "sticker", 9: "audio", - 10: "gif", + 10: "animation", 13: "video_note" } From b1c12c323236e9a6a8f5e60a5eb0d3aff9808ffc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 6 Aug 2018 21:38:44 +0200 Subject: [PATCH 37/85] Rename GIF to Animation --- pyrogram/__init__.py | 2 +- pyrogram/client/ext/utils.py | 6 +++--- pyrogram/client/methods/download_media.py | 2 +- pyrogram/client/types/__init__.py | 2 +- pyrogram/client/types/media/__init__.py | 2 +- .../client/types/media/{gif.py => animation.py} | 16 ++++++++-------- pyrogram/client/types/message.py | 8 ++++---- 7 files changed, 19 insertions(+), 19 deletions(-) rename pyrogram/client/types/media/{gif.py => animation.py} (82%) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 24bdc1a5..a822524c 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -30,7 +30,7 @@ from .client.types import ( Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputMediaDocument, InputMediaAudio, InputMediaAnimation, InputPhoneContact, Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, - UserProfilePhotos, Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, + UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) from .client import ( diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index a99ee066..c1d859d0 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -293,7 +293,7 @@ def parse_messages( venue = None audio = None voice = None - gif = None + animation = None video = None video_note = None sticker = None @@ -432,7 +432,7 @@ def parse_messages( elif types.DocumentAttributeAnimated in attributes: video_attributes = attributes.get(types.DocumentAttributeVideo, None) - gif = pyrogram_types.GIF( + animation = pyrogram_types.Animation( file_id=encode( pack( ". +from .animation import Animation from .audio import Audio from .contact import Contact from .document import Document -from .gif import GIF from .location import Location from .photo import Photo from .photo_size import PhotoSize diff --git a/pyrogram/client/types/media/gif.py b/pyrogram/client/types/media/animation.py similarity index 82% rename from pyrogram/client/types/media/gif.py rename to pyrogram/client/types/media/animation.py index 5172aae2..85d5a365 100644 --- a/pyrogram/client/types/media/gif.py +++ b/pyrogram/client/types/media/animation.py @@ -19,27 +19,27 @@ from pyrogram.api.core import Object -class GIF(Object): - """This object represents a GIF file. +class Animation(Object): + """This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). Args: file_id (``str``): Unique identifier for this file. width (``int``): - GIF width as defined by sender. + Animation width as defined by sender. height (``int``): - GIF height as defined by sender. + Animation height as defined by sender. duration (``int``): - Duration of the GIF in seconds as defined by sender. + Duration of the animation in seconds as defined by sender. thumb (:obj:`PhotoSize `, *optional*): - GIF thumbnail. + Animation thumbnail. file_name (``str``, *optional*): - GIF file name. + Animation file name. mime_type (``str``, *optional*): Mime type of a file as defined by sender. @@ -48,7 +48,7 @@ class GIF(Object): File size. date (``int``, *optional*): - Date the GIF was sent in Unix time. + Date the Animation was sent in Unix time. """ ID = 0xb0700025 diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index e471c8a5..7b05bfac 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -92,8 +92,8 @@ class Message(Object): sticker (:obj:`Sticker `, *optional*): Message is a sticker, information about the sticker. - gif (:obj:`Video `, *optional*): - Message is a GIF, information about the GIF. + animation (:obj:`Animation `, *optional*): + Message is an animation, information about the animation. video (:obj:`Video `, *optional*): Message is a video, information about the video. @@ -228,7 +228,7 @@ class Message(Object): game=None, photo=None, sticker=None, - gif=None, + animation=None, video=None, voice=None, video_note=None, @@ -279,7 +279,7 @@ class Message(Object): self.game = game # flags.15?Game self.photo = photo # flags.16?Vector self.sticker = sticker # flags.17?Sticker - self.gif = gif + self.animation = animation self.video = video # flags.18?Video self.voice = voice # flags.19?Voice self.video_note = video_note # flags.20?VideoNote From 2b793dd2a170dd4a0df20b7c17e9a45b4884e4d4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 7 Aug 2018 01:23:52 +0200 Subject: [PATCH 38/85] Refactor send_gif. It is now called send_animation --- pyrogram/client/methods/messages/__init__.py | 4 +- pyrogram/client/methods/messages/send_gif.py | 66 ++++++++++---------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 6de17d7c..8bf3bc14 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -29,7 +29,7 @@ from .send_audio import SendAudio from .send_chat_action import SendChatAction from .send_contact import SendContact from .send_document import SendDocument -from .send_gif import SendGIF +from .send_gif import SendAnimation from .send_location import SendLocation from .send_media_group import SendMediaGroup from .send_message import SendMessage @@ -55,7 +55,7 @@ class Messages( SendChatAction, SendContact, SendDocument, - SendGIF, + SendAnimation, SendLocation, SendMediaGroup, SendMessage, diff --git a/pyrogram/client/methods/messages/send_gif.py b/pyrogram/client/methods/messages/send_gif.py index ca323f1d..55123332 100644 --- a/pyrogram/client/methods/messages/send_gif.py +++ b/pyrogram/client/methods/messages/send_gif.py @@ -26,22 +26,22 @@ from pyrogram.api.errors import FileIdInvalid, FilePartMissing from pyrogram.client.ext import BaseClient, utils -class SendGIF(BaseClient): - def send_gif(self, - chat_id: int or str, - gif: str, - caption: str = "", - parse_mode: str = "", - duration: int = 0, - width: int = 0, - height: int = 0, - thumb: str = None, - disable_notification: bool = None, - reply_to_message_id: int = None, - reply_markup=None, - progress: callable = None, - progress_args: tuple = ()): - """Use this method to send GIF files. +class SendAnimation(BaseClient): + def send_animation(self, + chat_id: int or str, + animation: str, + caption: str = "", + parse_mode: str = "", + duration: int = 0, + width: int = 0, + height: int = 0, + thumb: str = None, + disable_notification: bool = None, + reply_to_message_id: int = None, + reply_markup=None, + progress: callable = None, + progress_args: tuple = ()): + """Use this method to send animation files (animation or H.264/MPEG-4 AVC video without sound). Args: chat_id (``int`` | ``str``): @@ -49,14 +49,14 @@ class SendGIF(BaseClient): For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). - gif (``str``): - GIF to send. - Pass a file_id as string to send a GIF that exists on the Telegram servers, - pass an HTTP URL as a string for Telegram to get a GIF from the Internet, or - pass a file path as string to upload a new GIF that exists on your local machine. + animation (``str``): + Animation to send. + Pass a file_id as string to send an animation that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get an animation from the Internet, or + pass a file path as string to upload a new animation that exists on your local machine. caption (``str``, *optional*): - GIF caption, 0-200 characters. + Animation caption, 0-200 characters. parse_mode (``str``, *optional*): Use :obj:`MARKDOWN ` or :obj:`HTML ` @@ -64,16 +64,16 @@ class SendGIF(BaseClient): Defaults to Markdown. duration (``int``, *optional*): - Duration of sent GIF in seconds. + Duration of sent animation in seconds. width (``int``, *optional*): - GIF width. + Animation width. height (``int``, *optional*): - GIF height. + Animation height. thumb (``str``, *optional*): - GIF thumbnail. + Animation thumbnail. Pass a file path as string to send an image that exists on your local machine. Thumbnail should have 90 or less pixels of width and 90 or less pixels of height. @@ -120,9 +120,9 @@ class SendGIF(BaseClient): file = None style = self.html if parse_mode.lower() == "html" else self.markdown - if os.path.exists(gif): + if os.path.exists(animation): thumb = None if thumb is None else self.save_file(thumb) - file = self.save_file(gif, progress=progress, progress_args=progress_args) + file = self.save_file(animation, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( mime_type=mimetypes.types_map[".mp4"], file=file, @@ -134,17 +134,17 @@ class SendGIF(BaseClient): w=width, h=height ), - types.DocumentAttributeFilename(os.path.basename(gif)), + types.DocumentAttributeFilename(os.path.basename(animation)), types.DocumentAttributeAnimated() ] ) - elif gif.startswith("http"): + elif animation.startswith("http"): media = types.InputMediaDocumentExternal( - url=gif + url=animation ) else: try: - decoded = utils.decode(gif) + decoded = utils.decode(animation) fmt = " 24 else " Date: Tue, 7 Aug 2018 01:25:34 +0200 Subject: [PATCH 39/85] Rename file --- pyrogram/client/methods/messages/__init__.py | 2 +- .../client/methods/messages/{send_gif.py => send_animation.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename pyrogram/client/methods/messages/{send_gif.py => send_animation.py} (100%) diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 8bf3bc14..174586bc 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -29,7 +29,7 @@ from .send_audio import SendAudio from .send_chat_action import SendChatAction from .send_contact import SendContact from .send_document import SendDocument -from .send_gif import SendAnimation +from .send_animation import SendAnimation from .send_location import SendLocation from .send_media_group import SendMediaGroup from .send_message import SendMessage diff --git a/pyrogram/client/methods/messages/send_gif.py b/pyrogram/client/methods/messages/send_animation.py similarity index 100% rename from pyrogram/client/methods/messages/send_gif.py rename to pyrogram/client/methods/messages/send_animation.py From 92a3722e56b9116df3cfce6ccc0f337678dda531 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 8 Aug 2018 15:36:48 +0200 Subject: [PATCH 40/85] Use Animation instead of GIF when creating the types list --- compiler/api/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 3b6dbae7..69713867 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -501,7 +501,7 @@ def start(): 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 0xb0700025: \"pyrogram.client.types.GIF\",") + f.write("\n 0xb0700025: \"pyrogram.client.types.Animation\",") f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",") f.write("\n 0xb0700028: \"pyrogram.client.types.Dialog\",") From 88d45b085beefc26861470fad17668a1a64d5161 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:46:14 +0200 Subject: [PATCH 41/85] Move InputMedia types in a dedicated folder --- pyrogram/client/types/__init__.py | 11 ++++----- pyrogram/client/types/input_media/__init__.py | 24 +++++++++++++++++++ .../types/{ => input_media}/input_media.py | 0 .../input_media_animation.py | 0 .../{ => input_media}/input_media_audio.py | 0 .../{ => input_media}/input_media_document.py | 0 .../{ => input_media}/input_media_photo.py | 0 .../{ => input_media}/input_media_video.py | 0 .../{ => input_media}/input_phone_contact.py | 0 9 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 pyrogram/client/types/input_media/__init__.py rename pyrogram/client/types/{ => input_media}/input_media.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_animation.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_audio.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_document.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_photo.py (100%) rename pyrogram/client/types/{ => input_media}/input_media_video.py (100%) rename pyrogram/client/types/{ => input_media}/input_phone_contact.py (100%) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index a07ee27b..46332453 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -23,13 +23,10 @@ from .chat_members import ChatMembers from .chat_photo import ChatPhoto from .dialog import Dialog from .dialogs import Dialogs -from .input_media import InputMedia -from .input_media_animation import InputMediaAnimation -from .input_media_audio import InputMediaAudio -from .input_media_document import InputMediaDocument -from .input_media_photo import InputMediaPhoto -from .input_media_video import InputMediaVideo -from .input_phone_contact import InputPhoneContact +from .input_media import ( + InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, + InputMediaDocument, InputMediaAnimation +) from .media import ( Audio, Contact, Document, Animation, Location, Photo, PhotoSize, Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos diff --git a/pyrogram/client/types/input_media/__init__.py b/pyrogram/client/types/input_media/__init__.py new file mode 100644 index 00000000..4b3d90a3 --- /dev/null +++ b/pyrogram/client/types/input_media/__init__.py @@ -0,0 +1,24 @@ +# 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 .input_media_animation import InputMediaAnimation +from .input_media_audio import InputMediaAudio +from .input_media_document import InputMediaDocument +from .input_media_photo import InputMediaPhoto +from .input_media_video import InputMediaVideo +from .input_phone_contact import InputPhoneContact diff --git a/pyrogram/client/types/input_media.py b/pyrogram/client/types/input_media/input_media.py similarity index 100% rename from pyrogram/client/types/input_media.py rename to pyrogram/client/types/input_media/input_media.py diff --git a/pyrogram/client/types/input_media_animation.py b/pyrogram/client/types/input_media/input_media_animation.py similarity index 100% rename from pyrogram/client/types/input_media_animation.py rename to pyrogram/client/types/input_media/input_media_animation.py diff --git a/pyrogram/client/types/input_media_audio.py b/pyrogram/client/types/input_media/input_media_audio.py similarity index 100% rename from pyrogram/client/types/input_media_audio.py rename to pyrogram/client/types/input_media/input_media_audio.py diff --git a/pyrogram/client/types/input_media_document.py b/pyrogram/client/types/input_media/input_media_document.py similarity index 100% rename from pyrogram/client/types/input_media_document.py rename to pyrogram/client/types/input_media/input_media_document.py diff --git a/pyrogram/client/types/input_media_photo.py b/pyrogram/client/types/input_media/input_media_photo.py similarity index 100% rename from pyrogram/client/types/input_media_photo.py rename to pyrogram/client/types/input_media/input_media_photo.py diff --git a/pyrogram/client/types/input_media_video.py b/pyrogram/client/types/input_media/input_media_video.py similarity index 100% rename from pyrogram/client/types/input_media_video.py rename to pyrogram/client/types/input_media/input_media_video.py diff --git a/pyrogram/client/types/input_phone_contact.py b/pyrogram/client/types/input_media/input_phone_contact.py similarity index 100% rename from pyrogram/client/types/input_phone_contact.py rename to pyrogram/client/types/input_media/input_phone_contact.py From eeb3b67d37411cfd68c7baae93d8d5763f34dd68 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:49:14 +0200 Subject: [PATCH 42/85] Create a new sub-folder for user and chat types --- pyrogram/client/types/__init__.py | 11 +++----- .../client/types/user_and_chats/__init__.py | 25 +++++++++++++++++++ .../client/types/{ => user_and_chats}/chat.py | 0 .../types/{ => user_and_chats}/chat_member.py | 0 .../{ => user_and_chats}/chat_members.py | 0 .../types/{ => user_and_chats}/chat_photo.py | 0 .../types/{ => user_and_chats}/dialog.py | 0 .../types/{ => user_and_chats}/dialogs.py | 0 .../client/types/{ => user_and_chats}/user.py | 0 9 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 pyrogram/client/types/user_and_chats/__init__.py rename pyrogram/client/types/{ => user_and_chats}/chat.py (100%) rename pyrogram/client/types/{ => user_and_chats}/chat_member.py (100%) rename pyrogram/client/types/{ => user_and_chats}/chat_members.py (100%) rename pyrogram/client/types/{ => user_and_chats}/chat_photo.py (100%) rename pyrogram/client/types/{ => user_and_chats}/dialog.py (100%) rename pyrogram/client/types/{ => user_and_chats}/dialogs.py (100%) rename pyrogram/client/types/{ => user_and_chats}/user.py (100%) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 46332453..13198982 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -17,12 +17,6 @@ # along with Pyrogram. If not, see . from .callback_query import CallbackQuery -from .chat import Chat -from .chat_member import ChatMember -from .chat_members import ChatMembers -from .chat_photo import ChatPhoto -from .dialog import Dialog -from .dialogs import Dialogs from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaAnimation @@ -39,4 +33,7 @@ from .reply_markup import ( KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) from .update import Update -from .user import User +from .user_and_chats import ( + Chat, ChatMember, ChatMembers, ChatPhoto, + Dialog, Dialogs, User +) diff --git a/pyrogram/client/types/user_and_chats/__init__.py b/pyrogram/client/types/user_and_chats/__init__.py new file mode 100644 index 00000000..45915edc --- /dev/null +++ b/pyrogram/client/types/user_and_chats/__init__.py @@ -0,0 +1,25 @@ +# 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 .chat import Chat +from .chat_member import ChatMember +from .chat_members import ChatMembers +from .chat_photo import ChatPhoto +from .dialog import Dialog +from .dialogs import Dialogs +from .user import User diff --git a/pyrogram/client/types/chat.py b/pyrogram/client/types/user_and_chats/chat.py similarity index 100% rename from pyrogram/client/types/chat.py rename to pyrogram/client/types/user_and_chats/chat.py diff --git a/pyrogram/client/types/chat_member.py b/pyrogram/client/types/user_and_chats/chat_member.py similarity index 100% rename from pyrogram/client/types/chat_member.py rename to pyrogram/client/types/user_and_chats/chat_member.py diff --git a/pyrogram/client/types/chat_members.py b/pyrogram/client/types/user_and_chats/chat_members.py similarity index 100% rename from pyrogram/client/types/chat_members.py rename to pyrogram/client/types/user_and_chats/chat_members.py diff --git a/pyrogram/client/types/chat_photo.py b/pyrogram/client/types/user_and_chats/chat_photo.py similarity index 100% rename from pyrogram/client/types/chat_photo.py rename to pyrogram/client/types/user_and_chats/chat_photo.py diff --git a/pyrogram/client/types/dialog.py b/pyrogram/client/types/user_and_chats/dialog.py similarity index 100% rename from pyrogram/client/types/dialog.py rename to pyrogram/client/types/user_and_chats/dialog.py diff --git a/pyrogram/client/types/dialogs.py b/pyrogram/client/types/user_and_chats/dialogs.py similarity index 100% rename from pyrogram/client/types/dialogs.py rename to pyrogram/client/types/user_and_chats/dialogs.py diff --git a/pyrogram/client/types/user.py b/pyrogram/client/types/user_and_chats/user.py similarity index 100% rename from pyrogram/client/types/user.py rename to pyrogram/client/types/user_and_chats/user.py From a93f98cfa6967006b43617a4f7e6703fcb99752b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:51:00 +0200 Subject: [PATCH 43/85] Create a new sub-folder for bot related types --- pyrogram/client/types/__init__.py | 13 ++++++++----- .../client/types/{reply_markup => bots}/__init__.py | 1 + pyrogram/client/types/{ => bots}/callback_query.py | 0 .../types/{reply_markup => bots}/force_reply.py | 0 .../inline_keyboard_button.py | 0 .../inline_keyboard_markup.py | 0 .../types/{reply_markup => bots}/keyboard_button.py | 0 .../{reply_markup => bots}/reply_keyboard_markup.py | 0 .../{reply_markup => bots}/reply_keyboard_remove.py | 0 9 files changed, 9 insertions(+), 5 deletions(-) rename pyrogram/client/types/{reply_markup => bots}/__init__.py (96%) rename pyrogram/client/types/{ => bots}/callback_query.py (100%) rename pyrogram/client/types/{reply_markup => bots}/force_reply.py (100%) rename pyrogram/client/types/{reply_markup => bots}/inline_keyboard_button.py (100%) rename pyrogram/client/types/{reply_markup => bots}/inline_keyboard_markup.py (100%) rename pyrogram/client/types/{reply_markup => bots}/keyboard_button.py (100%) rename pyrogram/client/types/{reply_markup => bots}/reply_keyboard_markup.py (100%) rename pyrogram/client/types/{reply_markup => bots}/reply_keyboard_remove.py (100%) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 13198982..3fd4a8d1 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -16,7 +16,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .callback_query import CallbackQuery +from .bots import ( + CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, + KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove +) +from .bots import ( + ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, + KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove +) from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaAnimation @@ -28,10 +35,6 @@ from .media import ( from .message import Message from .message_entity import MessageEntity from .messages import Messages -from .reply_markup import ( - ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, - KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove -) from .update import Update from .user_and_chats import ( Chat, ChatMember, ChatMembers, ChatPhoto, diff --git a/pyrogram/client/types/reply_markup/__init__.py b/pyrogram/client/types/bots/__init__.py similarity index 96% rename from pyrogram/client/types/reply_markup/__init__.py rename to pyrogram/client/types/bots/__init__.py index 62ce7152..9f7cc7e6 100644 --- a/pyrogram/client/types/reply_markup/__init__.py +++ b/pyrogram/client/types/bots/__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 .callback_query import CallbackQuery from .force_reply import ForceReply from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_markup import InlineKeyboardMarkup diff --git a/pyrogram/client/types/callback_query.py b/pyrogram/client/types/bots/callback_query.py similarity index 100% rename from pyrogram/client/types/callback_query.py rename to pyrogram/client/types/bots/callback_query.py diff --git a/pyrogram/client/types/reply_markup/force_reply.py b/pyrogram/client/types/bots/force_reply.py similarity index 100% rename from pyrogram/client/types/reply_markup/force_reply.py rename to pyrogram/client/types/bots/force_reply.py diff --git a/pyrogram/client/types/reply_markup/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py similarity index 100% rename from pyrogram/client/types/reply_markup/inline_keyboard_button.py rename to pyrogram/client/types/bots/inline_keyboard_button.py diff --git a/pyrogram/client/types/reply_markup/inline_keyboard_markup.py b/pyrogram/client/types/bots/inline_keyboard_markup.py similarity index 100% rename from pyrogram/client/types/reply_markup/inline_keyboard_markup.py rename to pyrogram/client/types/bots/inline_keyboard_markup.py diff --git a/pyrogram/client/types/reply_markup/keyboard_button.py b/pyrogram/client/types/bots/keyboard_button.py similarity index 100% rename from pyrogram/client/types/reply_markup/keyboard_button.py rename to pyrogram/client/types/bots/keyboard_button.py diff --git a/pyrogram/client/types/reply_markup/reply_keyboard_markup.py b/pyrogram/client/types/bots/reply_keyboard_markup.py similarity index 100% rename from pyrogram/client/types/reply_markup/reply_keyboard_markup.py rename to pyrogram/client/types/bots/reply_keyboard_markup.py diff --git a/pyrogram/client/types/reply_markup/reply_keyboard_remove.py b/pyrogram/client/types/bots/reply_keyboard_remove.py similarity index 100% rename from pyrogram/client/types/reply_markup/reply_keyboard_remove.py rename to pyrogram/client/types/bots/reply_keyboard_remove.py From 3a5dc20fb52d528c17f6cdd3034e5528d56b1f70 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:51:43 +0200 Subject: [PATCH 44/85] Rename reply_markup to bots --- compiler/api/compiler.py | 12 ++++++------ pyrogram/client/filters/filters.py | 2 +- pyrogram/client/types/message.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 69713867..555d1824 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -494,12 +494,12 @@ 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 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 0xb0700018: \"pyrogram.client.types.bots.ForceReply\",") + f.write("\n 0xb0700019: \"pyrogram.client.types.bots.InlineKeyboardButton\",") + f.write("\n 0xb0700020: \"pyrogram.client.types.bots.InlineKeyboardMarkup\",") + f.write("\n 0xb0700021: \"pyrogram.client.types.bots.KeyboardButton\",") + f.write("\n 0xb0700022: \"pyrogram.client.types.bots.ReplyKeyboardMarkup\",") + f.write("\n 0xb0700023: \"pyrogram.client.types.bots.ReplyKeyboardRemove\",") f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\",") f.write("\n 0xb0700025: \"pyrogram.client.types.Animation\",") f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 133ab6c2..e28fdfc5 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -19,7 +19,7 @@ import re from .filter import Filter -from ..types.reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup +from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup def build(name: str, func: callable, **kwargs) -> type: diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 7b05bfac..0a2022e8 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api.core import Object -from .reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup +from .bots import InlineKeyboardMarkup, ReplyKeyboardMarkup class Message(Object): From 2b4138ee30e02d569d606ebb59172f1adbcd7e3f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:53:49 +0200 Subject: [PATCH 45/85] Add new folder for messages and media related types --- .../client/types/{media => messages_and_media}/__init__.py | 3 +++ .../client/types/{media => messages_and_media}/animation.py | 0 pyrogram/client/types/{media => messages_and_media}/audio.py | 0 pyrogram/client/types/{media => messages_and_media}/contact.py | 0 .../client/types/{media => messages_and_media}/document.py | 0 .../client/types/{media => messages_and_media}/location.py | 0 pyrogram/client/types/{ => messages_and_media}/message.py | 0 .../client/types/{ => messages_and_media}/message_entity.py | 0 pyrogram/client/types/{ => messages_and_media}/messages.py | 0 pyrogram/client/types/{media => messages_and_media}/photo.py | 0 .../client/types/{media => messages_and_media}/photo_size.py | 0 pyrogram/client/types/{media => messages_and_media}/sticker.py | 0 .../types/{media => messages_and_media}/user_profile_photos.py | 0 pyrogram/client/types/{media => messages_and_media}/venue.py | 0 pyrogram/client/types/{media => messages_and_media}/video.py | 0 .../client/types/{media => messages_and_media}/video_note.py | 0 pyrogram/client/types/{media => messages_and_media}/voice.py | 0 17 files changed, 3 insertions(+) rename pyrogram/client/types/{media => messages_and_media}/__init__.py (92%) rename pyrogram/client/types/{media => messages_and_media}/animation.py (100%) rename pyrogram/client/types/{media => messages_and_media}/audio.py (100%) rename pyrogram/client/types/{media => messages_and_media}/contact.py (100%) rename pyrogram/client/types/{media => messages_and_media}/document.py (100%) rename pyrogram/client/types/{media => messages_and_media}/location.py (100%) rename pyrogram/client/types/{ => messages_and_media}/message.py (100%) rename pyrogram/client/types/{ => messages_and_media}/message_entity.py (100%) rename pyrogram/client/types/{ => messages_and_media}/messages.py (100%) rename pyrogram/client/types/{media => messages_and_media}/photo.py (100%) rename pyrogram/client/types/{media => messages_and_media}/photo_size.py (100%) rename pyrogram/client/types/{media => messages_and_media}/sticker.py (100%) rename pyrogram/client/types/{media => messages_and_media}/user_profile_photos.py (100%) rename pyrogram/client/types/{media => messages_and_media}/venue.py (100%) rename pyrogram/client/types/{media => messages_and_media}/video.py (100%) rename pyrogram/client/types/{media => messages_and_media}/video_note.py (100%) rename pyrogram/client/types/{media => messages_and_media}/voice.py (100%) diff --git a/pyrogram/client/types/media/__init__.py b/pyrogram/client/types/messages_and_media/__init__.py similarity index 92% rename from pyrogram/client/types/media/__init__.py rename to pyrogram/client/types/messages_and_media/__init__.py index 07d1280c..3ab359ae 100644 --- a/pyrogram/client/types/media/__init__.py +++ b/pyrogram/client/types/messages_and_media/__init__.py @@ -21,6 +21,9 @@ from .audio import Audio from .contact import Contact from .document import Document 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 .sticker import Sticker diff --git a/pyrogram/client/types/media/animation.py b/pyrogram/client/types/messages_and_media/animation.py similarity index 100% rename from pyrogram/client/types/media/animation.py rename to pyrogram/client/types/messages_and_media/animation.py diff --git a/pyrogram/client/types/media/audio.py b/pyrogram/client/types/messages_and_media/audio.py similarity index 100% rename from pyrogram/client/types/media/audio.py rename to pyrogram/client/types/messages_and_media/audio.py diff --git a/pyrogram/client/types/media/contact.py b/pyrogram/client/types/messages_and_media/contact.py similarity index 100% rename from pyrogram/client/types/media/contact.py rename to pyrogram/client/types/messages_and_media/contact.py diff --git a/pyrogram/client/types/media/document.py b/pyrogram/client/types/messages_and_media/document.py similarity index 100% rename from pyrogram/client/types/media/document.py rename to pyrogram/client/types/messages_and_media/document.py diff --git a/pyrogram/client/types/media/location.py b/pyrogram/client/types/messages_and_media/location.py similarity index 100% rename from pyrogram/client/types/media/location.py rename to pyrogram/client/types/messages_and_media/location.py diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/messages_and_media/message.py similarity index 100% rename from pyrogram/client/types/message.py rename to pyrogram/client/types/messages_and_media/message.py diff --git a/pyrogram/client/types/message_entity.py b/pyrogram/client/types/messages_and_media/message_entity.py similarity index 100% rename from pyrogram/client/types/message_entity.py rename to pyrogram/client/types/messages_and_media/message_entity.py diff --git a/pyrogram/client/types/messages.py b/pyrogram/client/types/messages_and_media/messages.py similarity index 100% rename from pyrogram/client/types/messages.py rename to pyrogram/client/types/messages_and_media/messages.py diff --git a/pyrogram/client/types/media/photo.py b/pyrogram/client/types/messages_and_media/photo.py similarity index 100% rename from pyrogram/client/types/media/photo.py rename to pyrogram/client/types/messages_and_media/photo.py diff --git a/pyrogram/client/types/media/photo_size.py b/pyrogram/client/types/messages_and_media/photo_size.py similarity index 100% rename from pyrogram/client/types/media/photo_size.py rename to pyrogram/client/types/messages_and_media/photo_size.py diff --git a/pyrogram/client/types/media/sticker.py b/pyrogram/client/types/messages_and_media/sticker.py similarity index 100% rename from pyrogram/client/types/media/sticker.py rename to pyrogram/client/types/messages_and_media/sticker.py diff --git a/pyrogram/client/types/media/user_profile_photos.py b/pyrogram/client/types/messages_and_media/user_profile_photos.py similarity index 100% rename from pyrogram/client/types/media/user_profile_photos.py rename to pyrogram/client/types/messages_and_media/user_profile_photos.py diff --git a/pyrogram/client/types/media/venue.py b/pyrogram/client/types/messages_and_media/venue.py similarity index 100% rename from pyrogram/client/types/media/venue.py rename to pyrogram/client/types/messages_and_media/venue.py diff --git a/pyrogram/client/types/media/video.py b/pyrogram/client/types/messages_and_media/video.py similarity index 100% rename from pyrogram/client/types/media/video.py rename to pyrogram/client/types/messages_and_media/video.py diff --git a/pyrogram/client/types/media/video_note.py b/pyrogram/client/types/messages_and_media/video_note.py similarity index 100% rename from pyrogram/client/types/media/video_note.py rename to pyrogram/client/types/messages_and_media/video_note.py diff --git a/pyrogram/client/types/media/voice.py b/pyrogram/client/types/messages_and_media/voice.py similarity index 100% rename from pyrogram/client/types/media/voice.py rename to pyrogram/client/types/messages_and_media/voice.py From 888b3cc6aab07b929840cf75847e75af1d1df10b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 9 Aug 2018 21:55:06 +0200 Subject: [PATCH 46/85] Add missing import --- pyrogram/client/types/input_media/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/types/input_media/__init__.py b/pyrogram/client/types/input_media/__init__.py index 4b3d90a3..5f5be30d 100644 --- a/pyrogram/client/types/input_media/__init__.py +++ b/pyrogram/client/types/input_media/__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 .input_media import InputMedia from .input_media_animation import InputMediaAnimation from .input_media_audio import InputMediaAudio from .input_media_document import InputMediaDocument From 61663b3dde608b7a3121d2197736fa5f2d1dd400 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:16:31 +0200 Subject: [PATCH 47/85] Add new utilities folder --- pyrogram/client/methods/utilities/__init__.py | 25 +++++++++++++++++++ .../methods/{ => utilities}/download_media.py | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 pyrogram/client/methods/utilities/__init__.py rename pyrogram/client/methods/{ => utilities}/download_media.py (99%) diff --git a/pyrogram/client/methods/utilities/__init__.py b/pyrogram/client/methods/utilities/__init__.py new file mode 100644 index 00000000..f8db23e5 --- /dev/null +++ b/pyrogram/client/methods/utilities/__init__.py @@ -0,0 +1,25 @@ +# 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 .download_media import DownloadMedia + + +class Utilities( + DownloadMedia +): + pass diff --git a/pyrogram/client/methods/download_media.py b/pyrogram/client/methods/utilities/download_media.py similarity index 99% rename from pyrogram/client/methods/download_media.py rename to pyrogram/client/methods/utilities/download_media.py index 816a8cba..d511667c 100644 --- a/pyrogram/client/methods/download_media.py +++ b/pyrogram/client/methods/utilities/download_media.py @@ -19,7 +19,7 @@ from threading import Event from pyrogram.client import types as pyrogram_types -from ..ext import BaseClient +from ...ext import BaseClient class DownloadMedia(BaseClient): From 4e6add7a70fd25596588761033166dd22dfb3500 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:16:57 +0200 Subject: [PATCH 48/85] Fix download_media referencing to gif instead of animation --- pyrogram/client/methods/utilities/download_media.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/utilities/download_media.py b/pyrogram/client/methods/utilities/download_media.py index d511667c..26918f27 100644 --- a/pyrogram/client/methods/utilities/download_media.py +++ b/pyrogram/client/methods/utilities/download_media.py @@ -98,8 +98,8 @@ class DownloadMedia(BaseClient): media = message.video_note elif message.sticker: media = message.sticker - elif message.gif: - media = message.gif + elif message.animation: + media = message.animation else: raise ValueError(error_message) elif isinstance(message, ( From 42d3b467fbec32b1314042271c2a08c798ce025f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:17:21 +0200 Subject: [PATCH 49/85] Fix init not having message and media types --- pyrogram/client/types/__init__.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 3fd4a8d1..230d5e5d 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -28,13 +28,11 @@ from .input_media import ( InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaDocument, InputMediaAnimation ) -from .media import ( +from .messages_and_media import ( Audio, Contact, Document, Animation, Location, Photo, PhotoSize, - Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos + Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos, + Message, Messages, MessageEntity ) -from .message import Message -from .message_entity import MessageEntity -from .messages import Messages from .update import Update from .user_and_chats import ( Chat, ChatMember, ChatMembers, ChatPhoto, From 6437c6c5be6745f6001159b58b8d8082176df8d7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:17:53 +0200 Subject: [PATCH 50/85] Move resolve_peer into utilities --- pyrogram/client/client.py | 48 ------------ .../client/methods/utilities/resolve_peer.py | 73 +++++++++++++++++++ 2 files changed, 73 insertions(+), 48 deletions(-) create mode 100644 pyrogram/client/methods/utilities/resolve_peer.py diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 3af60931..9fcf6324 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1010,54 +1010,6 @@ class Client(Methods, BaseClient): self.get_initial_dialogs_chunk() - def resolve_peer(self, peer_id: int or str): - """Use this method to get the InputPeer of a known peer_id. - - This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method - you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer - type is required. - - Args: - peer_id (``int`` | ``str``): - The peer id you want to extract the InputPeer from. - Can be a direct id (int), a username (str) or a phone number (str). - - Returns: - On success, the resolved peer id is returned in form of an InputPeer object. - - Raises: - :class:`Error ` - """ - if type(peer_id) is str: - if peer_id in ("self", "me"): - return types.InputPeerSelf() - - peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) - - try: - int(peer_id) - except ValueError: - if peer_id not in self.peers_by_username: - self.send(functions.contacts.ResolveUsername(peer_id)) - - return self.peers_by_username[peer_id] - else: - try: - return self.peers_by_phone[peer_id] - except KeyError: - raise PeerIdInvalid - - try: # User - return self.peers_by_id[peer_id] - except KeyError: - try: # Chat - return self.peers_by_id[-peer_id] - except KeyError: - try: # Channel - return self.peers_by_id[int("-100" + str(peer_id))] - except (KeyError, ValueError): - raise PeerIdInvalid - def save_file(self, path: str, file_id: int = None, diff --git a/pyrogram/client/methods/utilities/resolve_peer.py b/pyrogram/client/methods/utilities/resolve_peer.py new file mode 100644 index 00000000..7cf31078 --- /dev/null +++ b/pyrogram/client/methods/utilities/resolve_peer.py @@ -0,0 +1,73 @@ +# 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 . + +import re + +from pyrogram.api import types, functions +from pyrogram.api.errors import PeerIdInvalid +from ...ext import BaseClient + + +class ResolvePeer(BaseClient): + def resolve_peer(self, peer_id: int or str): + """Use this method to get the InputPeer of a known peer_id. + + This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method + you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer + type is required. + + Args: + peer_id (``int`` | ``str``): + The peer id you want to extract the InputPeer from. + Can be a direct id (int), a username (str) or a phone number (str). + + Returns: + On success, the resolved peer id is returned in form of an InputPeer object. + + Raises: + :class:`Error ` + """ + if type(peer_id) is str: + if peer_id in ("self", "me"): + return types.InputPeerSelf() + + peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) + + try: + int(peer_id) + except ValueError: + if peer_id not in self.peers_by_username: + self.send(functions.contacts.ResolveUsername(peer_id)) + + return self.peers_by_username[peer_id] + else: + try: + return self.peers_by_phone[peer_id] + except KeyError: + raise PeerIdInvalid + + try: # User + return self.peers_by_id[peer_id] + except KeyError: + try: # Chat + return self.peers_by_id[-peer_id] + except KeyError: + try: # Channel + return self.peers_by_id[int("-100" + str(peer_id))] + except (KeyError, ValueError): + raise PeerIdInvalid From dd422c0edfe8f2b40bfc8c40aab4b2c89da7c82d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:18:28 +0200 Subject: [PATCH 51/85] Export resolve_peer --- pyrogram/client/methods/__init__.py | 4 ++-- pyrogram/client/methods/utilities/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/methods/__init__.py b/pyrogram/client/methods/__init__.py index 396fd3c2..e245a14a 100644 --- a/pyrogram/client/methods/__init__.py +++ b/pyrogram/client/methods/__init__.py @@ -20,7 +20,7 @@ from .bots import Bots from .chats import Chats from .contacts import Contacts from .decorators import Decorators -from .download_media import DownloadMedia +from .utilities import Utilities from .messages import Messages from .password import Password from .users import Users @@ -32,7 +32,7 @@ class Methods( Password, Chats, Users, - DownloadMedia, + Utilities, Messages, Decorators ): diff --git a/pyrogram/client/methods/utilities/__init__.py b/pyrogram/client/methods/utilities/__init__.py index f8db23e5..b14c2a1f 100644 --- a/pyrogram/client/methods/utilities/__init__.py +++ b/pyrogram/client/methods/utilities/__init__.py @@ -17,9 +17,11 @@ # along with Pyrogram. If not, see . from .download_media import DownloadMedia +from .resolve_peer import ResolvePeer class Utilities( - DownloadMedia + DownloadMedia, + ResolvePeer ): pass From ef6f08054672924a8a47e6611f41828236c57924 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:29:05 +0200 Subject: [PATCH 52/85] Revert "Export resolve_peer" This reverts commit dd422c0 --- pyrogram/client/methods/__init__.py | 4 ++-- pyrogram/client/methods/utilities/__init__.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/methods/__init__.py b/pyrogram/client/methods/__init__.py index e245a14a..396fd3c2 100644 --- a/pyrogram/client/methods/__init__.py +++ b/pyrogram/client/methods/__init__.py @@ -20,7 +20,7 @@ from .bots import Bots from .chats import Chats from .contacts import Contacts from .decorators import Decorators -from .utilities import Utilities +from .download_media import DownloadMedia from .messages import Messages from .password import Password from .users import Users @@ -32,7 +32,7 @@ class Methods( Password, Chats, Users, - Utilities, + DownloadMedia, Messages, Decorators ): diff --git a/pyrogram/client/methods/utilities/__init__.py b/pyrogram/client/methods/utilities/__init__.py index b14c2a1f..f8db23e5 100644 --- a/pyrogram/client/methods/utilities/__init__.py +++ b/pyrogram/client/methods/utilities/__init__.py @@ -17,11 +17,9 @@ # along with Pyrogram. If not, see . from .download_media import DownloadMedia -from .resolve_peer import ResolvePeer class Utilities( - DownloadMedia, - ResolvePeer + DownloadMedia ): pass From da436461a88b7d8a80b05ae770ea8d9e9e82de88 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:29:13 +0200 Subject: [PATCH 53/85] Revert "Move resolve_peer into utilities" This reverts commit 6437c6c --- pyrogram/client/client.py | 48 ++++++++++++ .../client/methods/utilities/resolve_peer.py | 73 ------------------- 2 files changed, 48 insertions(+), 73 deletions(-) delete mode 100644 pyrogram/client/methods/utilities/resolve_peer.py diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 9fcf6324..3af60931 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1010,6 +1010,54 @@ class Client(Methods, BaseClient): self.get_initial_dialogs_chunk() + def resolve_peer(self, peer_id: int or str): + """Use this method to get the InputPeer of a known peer_id. + + This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method + you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer + type is required. + + Args: + peer_id (``int`` | ``str``): + The peer id you want to extract the InputPeer from. + Can be a direct id (int), a username (str) or a phone number (str). + + Returns: + On success, the resolved peer id is returned in form of an InputPeer object. + + Raises: + :class:`Error ` + """ + if type(peer_id) is str: + if peer_id in ("self", "me"): + return types.InputPeerSelf() + + peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) + + try: + int(peer_id) + except ValueError: + if peer_id not in self.peers_by_username: + self.send(functions.contacts.ResolveUsername(peer_id)) + + return self.peers_by_username[peer_id] + else: + try: + return self.peers_by_phone[peer_id] + except KeyError: + raise PeerIdInvalid + + try: # User + return self.peers_by_id[peer_id] + except KeyError: + try: # Chat + return self.peers_by_id[-peer_id] + except KeyError: + try: # Channel + return self.peers_by_id[int("-100" + str(peer_id))] + except (KeyError, ValueError): + raise PeerIdInvalid + def save_file(self, path: str, file_id: int = None, diff --git a/pyrogram/client/methods/utilities/resolve_peer.py b/pyrogram/client/methods/utilities/resolve_peer.py deleted file mode 100644 index 7cf31078..00000000 --- a/pyrogram/client/methods/utilities/resolve_peer.py +++ /dev/null @@ -1,73 +0,0 @@ -# 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 . - -import re - -from pyrogram.api import types, functions -from pyrogram.api.errors import PeerIdInvalid -from ...ext import BaseClient - - -class ResolvePeer(BaseClient): - def resolve_peer(self, peer_id: int or str): - """Use this method to get the InputPeer of a known peer_id. - - This is a utility method intended to be used only when working with Raw Functions (i.e: a Telegram API method - you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an InputPeer - type is required. - - Args: - peer_id (``int`` | ``str``): - The peer id you want to extract the InputPeer from. - Can be a direct id (int), a username (str) or a phone number (str). - - Returns: - On success, the resolved peer id is returned in form of an InputPeer object. - - Raises: - :class:`Error ` - """ - if type(peer_id) is str: - if peer_id in ("self", "me"): - return types.InputPeerSelf() - - peer_id = re.sub(r"[@+\s]", "", peer_id.lower()) - - try: - int(peer_id) - except ValueError: - if peer_id not in self.peers_by_username: - self.send(functions.contacts.ResolveUsername(peer_id)) - - return self.peers_by_username[peer_id] - else: - try: - return self.peers_by_phone[peer_id] - except KeyError: - raise PeerIdInvalid - - try: # User - return self.peers_by_id[peer_id] - except KeyError: - try: # Chat - return self.peers_by_id[-peer_id] - except KeyError: - try: # Channel - return self.peers_by_id[int("-100" + str(peer_id))] - except (KeyError, ValueError): - raise PeerIdInvalid From 7162850523adbd71d1c8f4298d7af1c8c3e44e09 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:29:55 +0200 Subject: [PATCH 54/85] Export Utility methods --- pyrogram/client/methods/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/__init__.py b/pyrogram/client/methods/__init__.py index 396fd3c2..eba768bb 100644 --- a/pyrogram/client/methods/__init__.py +++ b/pyrogram/client/methods/__init__.py @@ -20,10 +20,10 @@ from .bots import Bots from .chats import Chats from .contacts import Contacts from .decorators import Decorators -from .download_media import DownloadMedia from .messages import Messages from .password import Password from .users import Users +from .utilities import Utilities class Methods( @@ -32,7 +32,7 @@ class Methods( Password, Chats, Users, - DownloadMedia, + Utilities, Messages, Decorators ): From 9c7de81d8214826d2df3f23abcee5de90ee1f246 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Aug 2018 11:30:36 +0200 Subject: [PATCH 55/85] Fix relative imports --- pyrogram/client/types/messages_and_media/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/messages_and_media/message.py b/pyrogram/client/types/messages_and_media/message.py index 0a2022e8..3065cf9f 100644 --- a/pyrogram/client/types/messages_and_media/message.py +++ b/pyrogram/client/types/messages_and_media/message.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api.core import Object -from .bots import InlineKeyboardMarkup, ReplyKeyboardMarkup +from ..bots import InlineKeyboardMarkup, ReplyKeyboardMarkup class Message(Object): From 3ccb3de3f4413857e6cab21fbb7e95f68fba3f11 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Aug 2018 19:46:43 +0200 Subject: [PATCH 56/85] Fix docs still containing GIF instead of Animation --- docs/source/pyrogram/Client.rst | 2 +- docs/source/pyrogram/types/index.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 642d43d8..5dd42e4e 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -48,7 +48,7 @@ Messages send_document send_sticker send_video - send_gif + send_animation send_voice send_video_note send_media_group diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/types/index.rst index d93ecceb..92093b11 100644 --- a/docs/source/pyrogram/types/index.rst +++ b/docs/source/pyrogram/types/index.rst @@ -31,7 +31,7 @@ Messages & Media UserProfilePhotos Audio Document - GIF + Animation Video Voice VideoNote @@ -115,7 +115,7 @@ Input Media .. autoclass:: Document :members: -.. autoclass:: GIF +.. autoclass:: Animation :members: .. autoclass:: Video From 80179f2f25aebbd26a2b1a30580d0e558cdcc244 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Aug 2018 19:47:49 +0200 Subject: [PATCH 57/85] Rework Handler's page They are now all listed in a single page --- docs/source/pyrogram/handlers/index.rst | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/source/pyrogram/handlers/index.rst b/docs/source/pyrogram/handlers/index.rst index 272e529f..9f69c2c9 100644 --- a/docs/source/pyrogram/handlers/index.rst +++ b/docs/source/pyrogram/handlers/index.rst @@ -1,11 +1,29 @@ -:tocdepth: 1 - Handlers ======== -.. toctree:: +.. currentmodule:: pyrogram + +.. autosummary:: + :nosignatures: + MessageHandler DeletedMessagesHandler CallbackQueryHandler DisconnectHandler RawUpdateHandler + +.. autoclass:: MessageHandler + :members: + +.. autoclass:: DeletedMessagesHandler + :members: + +.. autoclass:: CallbackQueryHandler + :members: + +.. autoclass:: DisconnectHandler + :members: + +.. autoclass:: RawUpdateHandler + :members: + From 58568686a4c326579b1b8cbef7998772ef396739 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 11 Aug 2018 19:50:03 +0200 Subject: [PATCH 58/85] Delete unused files --- docs/source/pyrogram/handlers/CallbackQueryHandler.rst | 6 ------ docs/source/pyrogram/handlers/DeletedMessagesHandler.rst | 6 ------ docs/source/pyrogram/handlers/DisconnectHandler.rst | 6 ------ docs/source/pyrogram/handlers/MessageHandler.rst | 6 ------ docs/source/pyrogram/handlers/RawUpdateHandler.rst | 6 ------ 5 files changed, 30 deletions(-) delete mode 100644 docs/source/pyrogram/handlers/CallbackQueryHandler.rst delete mode 100644 docs/source/pyrogram/handlers/DeletedMessagesHandler.rst delete mode 100644 docs/source/pyrogram/handlers/DisconnectHandler.rst delete mode 100644 docs/source/pyrogram/handlers/MessageHandler.rst delete mode 100644 docs/source/pyrogram/handlers/RawUpdateHandler.rst diff --git a/docs/source/pyrogram/handlers/CallbackQueryHandler.rst b/docs/source/pyrogram/handlers/CallbackQueryHandler.rst deleted file mode 100644 index 5c9f4c17..00000000 --- a/docs/source/pyrogram/handlers/CallbackQueryHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -CallbackQueryHandler -==================== - -.. autoclass:: pyrogram.CallbackQueryHandler - :members: - :undoc-members: diff --git a/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst b/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst deleted file mode 100644 index 128bc656..00000000 --- a/docs/source/pyrogram/handlers/DeletedMessagesHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -DeletedMessagesHandler -====================== - -.. autoclass:: pyrogram.DeletedMessagesHandler - :members: - :undoc-members: diff --git a/docs/source/pyrogram/handlers/DisconnectHandler.rst b/docs/source/pyrogram/handlers/DisconnectHandler.rst deleted file mode 100644 index 594081f1..00000000 --- a/docs/source/pyrogram/handlers/DisconnectHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -DisconnectHandler -================= - -.. autoclass:: pyrogram.DisconnectHandler - :members: - :undoc-members: diff --git a/docs/source/pyrogram/handlers/MessageHandler.rst b/docs/source/pyrogram/handlers/MessageHandler.rst deleted file mode 100644 index de908bd3..00000000 --- a/docs/source/pyrogram/handlers/MessageHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -MessageHandler -============== - -.. autoclass:: pyrogram.MessageHandler - :members: - :undoc-members: diff --git a/docs/source/pyrogram/handlers/RawUpdateHandler.rst b/docs/source/pyrogram/handlers/RawUpdateHandler.rst deleted file mode 100644 index a6d21ef3..00000000 --- a/docs/source/pyrogram/handlers/RawUpdateHandler.rst +++ /dev/null @@ -1,6 +0,0 @@ -RawUpdateHandler -================ - -.. autoclass:: pyrogram.RawUpdateHandler - :members: - :undoc-members: From ece50e5f9bcff6fa90c8937492876749c8adba8f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Aug 2018 13:30:54 +0200 Subject: [PATCH 59/85] Rename Filters.gif to Filters.animation --- pyrogram/client/filters/filters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index e28fdfc5..5c2538f4 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -69,8 +69,8 @@ class Filters: sticker = build("Sticker", lambda _, m: bool(m.sticker)) """Filter messages that contain :obj:`Sticker ` objects.""" - gif = build("GIF", lambda _, m: bool(m.gif)) - """Filter messages that contain :obj:`GIF ` objects.""" + animation = build("GIF", lambda _, m: bool(m.animation)) + """Filter messages that contain :obj:`Animation ` objects.""" video = build("Video", lambda _, m: bool(m.video)) """Filter messages that contain :obj:`Video ` objects.""" @@ -276,7 +276,7 @@ class Filters: or Filters.photo(m) or Filters.sticker(m) or Filters.video(m) - or Filters.gif(m) + or Filters.animation(m) or Filters.voice(m) or Filters.video_note(m) or Filters.contact(m) From cbe34d0b28a4a3d0dcb80c96164b5c7084abdd3b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Aug 2018 13:31:24 +0200 Subject: [PATCH 60/85] Remove handlers and types doc page containing folders --- docs/source/pyrogram/{handlers/index.rst => Handlers.rst} | 0 docs/source/pyrogram/{types/index.rst => Types.rst} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename docs/source/pyrogram/{handlers/index.rst => Handlers.rst} (100%) rename docs/source/pyrogram/{types/index.rst => Types.rst} (100%) diff --git a/docs/source/pyrogram/handlers/index.rst b/docs/source/pyrogram/Handlers.rst similarity index 100% rename from docs/source/pyrogram/handlers/index.rst rename to docs/source/pyrogram/Handlers.rst diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/Types.rst similarity index 100% rename from docs/source/pyrogram/types/index.rst rename to docs/source/pyrogram/Types.rst From 7d516bfff24dbd2e4eaa0f5deeb5275d4e07cce6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Aug 2018 13:31:58 +0200 Subject: [PATCH 61/85] Fix Pyrogram doc package index page --- docs/source/pyrogram/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/pyrogram/index.rst b/docs/source/pyrogram/index.rst index af8b281a..20e7c918 100644 --- a/docs/source/pyrogram/index.rst +++ b/docs/source/pyrogram/index.rst @@ -10,8 +10,8 @@ after the well established `Telegram Bot API`_ methods, thus offering a familiar :maxdepth: 1 Client - types/index - handlers/index + Types + Handlers Filters ChatAction ParseMode From ba549c2862335bd041a2bb6f0bab6accfadd82af Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 12 Aug 2018 13:32:10 +0200 Subject: [PATCH 62/85] Remove tocdepth --- docs/source/pyrogram/Error.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/source/pyrogram/Error.rst b/docs/source/pyrogram/Error.rst index 96a140fa..b5474e73 100644 --- a/docs/source/pyrogram/Error.rst +++ b/docs/source/pyrogram/Error.rst @@ -1,5 +1,3 @@ -:tocdepth: 1 - Error ===== From 85c50ef4dd09e16840385efac39e3794dd9928d2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 13 Aug 2018 22:06:20 +0200 Subject: [PATCH 63/85] Add phone_number message entity --- pyrogram/client/ext/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index c1d859d0..9508a426 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -69,7 +69,8 @@ ENTITIES = { types.MessageEntityCode.ID: "code", types.MessageEntityPre.ID: "pre", types.MessageEntityTextUrl.ID: "text_link", - types.MessageEntityMentionName.ID: "text_mention" + types.MessageEntityMentionName.ID: "text_mention", + types.MessageEntityPhone.ID: "phone_number" } From 4fe9cffc32ad511c269774a153a173dca39a0931 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 13 Aug 2018 22:06:43 +0200 Subject: [PATCH 64/85] Code style fix --- pyrogram/client/ext/utils.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 9508a426..8f3245a9 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -81,18 +81,20 @@ def parse_entities(entities: list, users: dict) -> list: entity_type = ENTITIES.get(entity.ID, None) if entity_type: - output_entities.append(pyrogram_types.MessageEntity( - type=entity_type, - offset=entity.offset, - length=entity.length, - url=getattr(entity, "url", None), - user=parse_user( - users.get( - getattr(entity, "user_id", None), - None + output_entities.append( + pyrogram_types.MessageEntity( + type=entity_type, + offset=entity.offset, + length=entity.length, + url=getattr(entity, "url", None), + user=parse_user( + users.get( + getattr(entity, "user_id", None), + None + ) ) ) - )) + ) return output_entities From ec0d6dd6e0df8c7ab9eaab7760544531bff7044f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 14 Aug 2018 14:14:03 +0200 Subject: [PATCH 65/85] Add support for animations in edit_message_media --- .../methods/messages/edit_message_media.py | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index c6b2eb97..086d8dc2 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -25,7 +25,8 @@ from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( - InputMediaPhoto, InputMediaVideo, InputMediaAudio + InputMediaPhoto, InputMediaVideo, InputMediaAudio, + InputMediaAnimation ) @@ -189,6 +190,61 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaAnimation): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map[".mp4"], + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeVideo( + supports_streaming=True, + duration=media.duration, + w=media.width, + h=media.height + ), + types.DocumentAttributeFilename(os.path.basename(media.media)), + types.DocumentAttributeAnimated() + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " Date: Tue, 14 Aug 2018 14:25:54 +0200 Subject: [PATCH 66/85] Add foursquare_type to Venue --- pyrogram/client/ext/utils.py | 3 ++- pyrogram/client/types/messages_and_media/venue.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 8f3245a9..b98a05a8 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -378,7 +378,8 @@ def parse_messages( ), title=media.title, address=media.address, - foursquare_id=media.venue_id or None + foursquare_id=media.venue_id or None, + foursquare_type=media.venue_type ) elif isinstance(media, types.MessageMediaDocument): doc = media.document diff --git a/pyrogram/client/types/messages_and_media/venue.py b/pyrogram/client/types/messages_and_media/venue.py index 5d9e387f..3c5b2b05 100644 --- a/pyrogram/client/types/messages_and_media/venue.py +++ b/pyrogram/client/types/messages_and_media/venue.py @@ -35,12 +35,24 @@ class Venue(Object): foursquare_id (``str``, *optional*): Foursquare identifier of the venue. + foursquare_type (``str``, *optional*): + Foursquare type of the venue. + (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".) + """ ID = 0xb0700013 - def __init__(self, location, title: str, address: str, foursquare_id: str = None): + def __init__( + self, + location, + title: str, + address: str, + foursquare_id: str = None, + foursquare_type: str = None + ): self.location = location self.title = title self.address = address self.foursquare_id = foursquare_id + self.foursquare_type = foursquare_type From 49e2e529e13d23b0dbaca72eeb0a52898950724f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 14 Aug 2018 14:36:01 +0200 Subject: [PATCH 67/85] Add parameter foursquare_type to send_venue method --- pyrogram/client/methods/messages/send_venue.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/send_venue.py b/pyrogram/client/methods/messages/send_venue.py index 39ae0ca2..3decd5fb 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -28,6 +28,7 @@ class SendVenue(BaseClient): title: str, address: str, foursquare_id: str = "", + foursquare_type: str = "", disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None): @@ -54,6 +55,10 @@ class SendVenue(BaseClient): foursquare_id (``str``, *optional*): Foursquare identifier of the venue. + foursquare_type (``str``, *optional*): + Foursquare type of the venue, if known. + (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".) + disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. @@ -83,7 +88,7 @@ class SendVenue(BaseClient): address=address, provider="", venue_id=foursquare_id, - venue_type="" + venue_type=foursquare_type ), message="", silent=disable_notification or None, From 6879a4da9b107bb223ad8e3425a70a108dcf8189 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 15 Aug 2018 22:33:01 +0200 Subject: [PATCH 68/85] Update vcard docstrings for Contact type and send_contact method --- pyrogram/client/methods/messages/send_contact.py | 2 +- pyrogram/client/types/messages_and_media/contact.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyrogram/client/methods/messages/send_contact.py b/pyrogram/client/methods/messages/send_contact.py index 99a96abc..f661a31f 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -48,7 +48,7 @@ class SendContact(BaseClient): Contact's last name. vcard (``str``, *optional*): - Contact's vCard information. + Additional data about the contact in the form of a vCard, 0-2048 bytes disable_notification (``bool``, *optional*): Sends the message silently. diff --git a/pyrogram/client/types/messages_and_media/contact.py b/pyrogram/client/types/messages_and_media/contact.py index a59e2047..a7be558e 100644 --- a/pyrogram/client/types/messages_and_media/contact.py +++ b/pyrogram/client/types/messages_and_media/contact.py @@ -32,11 +32,11 @@ class Contact(Object): last_name (``str``, *optional*): Contact's last name. - vcard (``str``, *optional*): - Contact's vCard. - user_id (``int``, *optional*): Contact's user identifier in Telegram. + + vcard (``str``, *optional*): + Additional data about the contact in the form of a vCard """ ID = 0xb0700011 @@ -46,11 +46,11 @@ class Contact(Object): phone_number: str, first_name: str, last_name: str = None, - vcard: str = None, - user_id: int = None + user_id: int = None, + vcard: str = None ): self.phone_number = phone_number self.first_name = first_name self.last_name = last_name - self.vcard = vcard self.user_id = user_id + self.vcard = vcard From 30620cb783759f240a712854dcd12402a0fd116a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Aug 2018 18:53:53 +0200 Subject: [PATCH 69/85] Refine API Keys documentation section --- docs/source/start/Setup.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 417d62d8..79fb169d 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -8,14 +8,17 @@ with Pyrogram. API Keys -------- -The very first step requires you to obtain a valid Telegram API key. +The very first step requires you to obtain a valid Telegram API key (API id/hash pair). If you already have one you can skip this step, otherwise: #. Visit https://my.telegram.org/apps and log in with your Telegram Account. #. Fill out the form to register a new Telegram application. -#. Done. The Telegram API key consists of two parts: the **App api_id** and the **App api_hash**. +#. Done. The API key consists of two parts: **App api_id** and **App api_hash**. -.. important:: This key should be kept secret. + +.. important:: + + This API key is personal and should be kept secret. Configuration ------------- From a7c9dd4a59b4e0933c4a58ce985045ed046c1ecb Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Aug 2018 18:54:38 +0200 Subject: [PATCH 70/85] Make it clear that API keys are required for bots too --- docs/source/start/Setup.rst | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 79fb169d..17449911 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -23,10 +23,14 @@ If you already have one you can skip this step, otherwise: Configuration ------------- -There are two ways to configure a Pyrogram application project, and you can choose the one that fits better for you: +The API key obtained in the `previous step <#api-keys>`_ defines a token for your application allowing you to access +the Telegram database using the MTProto API — **it is therefore required for all authorizations of both Users and Bots**. + +Having it handy, it's time to configure your Pyrogram project. There are two ways to do so, and you can choose what +fits better for you: - Create a new ``config.ini`` file at the root of your working directory, copy-paste the following and replace the - **api_id** and **api_hash** values with `your own <#api-keys>`_. This is the preferred method because allows you + **api_id** and **api_hash** values with your own. This is the preferred method because allows you to keep your credentials out of your code without having to deal with how to load them: .. code-block:: ini @@ -84,11 +88,12 @@ and as long as you keep the session alive, Pyrogram won't ask you again to enter Bot Authorization ----------------- -Being written entirely from the ground up, Pyrogram is also able to authorize Bots. -Bots are a special kind of users which also make use of MTProto, the underlying Telegram protocol. -This means that you can use Pyrogram to execute API calls with a Bot identity. +Bots are a special kind of users and are authorized via their tokens (instead of phone numbers), which are created by +BotFather_. Bot tokens replace the Users' phone numbers only — you still need to +`configure a Telegram API key <#configuration>`_ with Pyrogram, even when using Bots. -Instead of phone numbers, Bots are authorized via their tokens which are created by BotFather_: +The authorization process is automatically managed. All you need to do is pass the bot token as ``session_name``. +The session file will be named after the Bot user_id, which is ``123456.session`` for the example below. .. code-block:: python @@ -97,9 +102,6 @@ Instead of phone numbers, Bots are authorized via their tokens which are created app = Client("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") app.run() -That's all, no further action is needed. The session file will be named after the Bot user_id, which is -``123456.session`` for the example above. - .. _installed Pyrogram: Installation.html .. _`Country Code`: https://en.wikipedia.org/wiki/List_of_country_calling_codes .. _BotFather: https://t.me/botfather \ No newline at end of file From 173fabd869616c82e8fd1172bf6ec4acb2012217 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 16 Aug 2018 18:55:27 +0200 Subject: [PATCH 71/85] Small Setup page fixes and refinements --- docs/source/start/Setup.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 17449911..e0cccc2c 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -52,7 +52,8 @@ fits better for you: api_hash="0123456789abcdef0123456789abcdef" ) -.. note:: The examples below assume you have created a ``config.ini`` file, thus they won't show the *api_id* +.. note:: + The examples below assume you have created a ``config.ini`` file, thus they won't show the *api_id* and *api_hash* parameters usage. User Authorization @@ -83,7 +84,7 @@ After successfully authorizing yourself, a new file called ``my_account.session` Pyrogram executing API calls with your identity. This file will be loaded again when you restart your app, and as long as you keep the session alive, Pyrogram won't ask you again to enter your phone number. -.. important:: Your ``*.session`` file(s) must be kept secret. +.. important:: Your ``*.session`` files are personal and must be kept secret. Bot Authorization ----------------- From d45caa63716e1a17d797a9f7fd8ba576a84b9ff6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 17 Aug 2018 02:02:15 +0200 Subject: [PATCH 72/85] Fix some documentation links --- docs/source/pyrogram/Client.rst | 2 -- docs/source/start/Usage.rst | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/source/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index 5dd42e4e..45d40368 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -33,8 +33,6 @@ Decorators on_disconnect on_raw_update -.. _available-methods: - Messages -------- diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index 6c20decd..6c560f90 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -108,9 +108,9 @@ Examples (more on `GitHub Date: Fri, 17 Aug 2018 02:17:48 +0200 Subject: [PATCH 73/85] Rename "build" to "create" (friendlier name) --- pyrogram/client/filters/filters.py | 84 +++++++++++++++--------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 5c2538f4..92fb278e 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -22,7 +22,7 @@ from .filter import Filter from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup -def build(name: str, func: callable, **kwargs) -> type: +def create(name: str, func: callable, **kwargs) -> type: d = {"__call__": func} d.update(kwargs) @@ -33,109 +33,109 @@ class Filters: """This class provides access to all Filters available in Pyrogram. Filters are intended to be used with the :obj:`MessageHandler `.""" - bot = build("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) + bot = create("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) """Filter messages coming from bots""" - incoming = build("Incoming", lambda _, m: not m.outgoing) + incoming = create("Incoming", lambda _, m: not m.outgoing) """Filter incoming messages.""" - outgoing = build("Outgoing", lambda _, m: m.outgoing) + outgoing = create("Outgoing", lambda _, m: m.outgoing) """Filter outgoing messages.""" - text = build("Text", lambda _, m: bool(m.text)) + text = create("Text", lambda _, m: bool(m.text)) """Filter text messages.""" - reply = build("Reply", lambda _, m: bool(m.reply_to_message)) + reply = create("Reply", lambda _, m: bool(m.reply_to_message)) """Filter messages that are replies to other messages.""" - forwarded = build("Forwarded", lambda _, m: bool(m.forward_date)) + forwarded = create("Forwarded", lambda _, m: bool(m.forward_date)) """Filter messages that are forwarded.""" - caption = build("Caption", lambda _, m: bool(m.caption)) + caption = create("Caption", lambda _, m: bool(m.caption)) """Filter media messages that contain captions.""" - edited = build("Edited", lambda _, m: bool(m.edit_date)) + edited = create("Edited", lambda _, m: bool(m.edit_date)) """Filter edited messages.""" - audio = build("Audio", lambda _, m: bool(m.audio)) + audio = create("Audio", lambda _, m: bool(m.audio)) """Filter messages that contain :obj:`Audio ` objects.""" - document = build("Document", lambda _, m: bool(m.document)) + document = create("Document", lambda _, m: bool(m.document)) """Filter messages that contain :obj:`Document ` objects.""" - photo = build("Photo", lambda _, m: bool(m.photo)) + photo = create("Photo", lambda _, m: bool(m.photo)) """Filter messages that contain :obj:`Photo ` objects.""" - sticker = build("Sticker", lambda _, m: bool(m.sticker)) + sticker = create("Sticker", lambda _, m: bool(m.sticker)) """Filter messages that contain :obj:`Sticker ` objects.""" - animation = build("GIF", lambda _, m: bool(m.animation)) + animation = create("GIF", lambda _, m: bool(m.animation)) """Filter messages that contain :obj:`Animation ` objects.""" - video = build("Video", lambda _, m: bool(m.video)) + video = create("Video", lambda _, m: bool(m.video)) """Filter messages that contain :obj:`Video ` objects.""" - voice = build("Voice", lambda _, m: bool(m.voice)) + voice = create("Voice", lambda _, m: bool(m.voice)) """Filter messages that contain :obj:`Voice ` note objects.""" - video_note = build("Voice", lambda _, m: bool(m.video_note)) + video_note = create("Voice", lambda _, m: bool(m.video_note)) """Filter messages that contain :obj:`VideoNote ` objects.""" - contact = build("Contact", lambda _, m: bool(m.contact)) + contact = create("Contact", lambda _, m: bool(m.contact)) """Filter messages that contain :obj:`Contact ` objects.""" - location = build("Location", lambda _, m: bool(m.location)) + location = create("Location", lambda _, m: bool(m.location)) """Filter messages that contain :obj:`Location ` objects.""" - venue = build("Venue", lambda _, m: bool(m.venue)) + venue = create("Venue", lambda _, m: bool(m.venue)) """Filter messages that contain :obj:`Venue ` objects.""" - private = build("Private", lambda _, m: bool(m.chat and m.chat.type == "private")) + private = create("Private", lambda _, m: bool(m.chat and m.chat.type == "private")) """Filter messages sent in private chats.""" - group = build("Group", lambda _, m: bool(m.chat and m.chat.type in {"group", "supergroup"})) + group = create("Group", lambda _, m: bool(m.chat and m.chat.type in {"group", "supergroup"})) """Filter messages sent in group or supergroup chats.""" - channel = build("Channel", lambda _, m: bool(m.chat and m.chat.type == "channel")) + channel = create("Channel", lambda _, m: bool(m.chat and m.chat.type == "channel")) """Filter messages sent in channels.""" - new_chat_members = build("NewChatMembers", lambda _, m: bool(m.new_chat_members)) + new_chat_members = create("NewChatMembers", lambda _, m: bool(m.new_chat_members)) """Filter service messages for new chat members.""" - left_chat_member = build("LeftChatMember", lambda _, m: bool(m.left_chat_member)) + left_chat_member = create("LeftChatMember", lambda _, m: bool(m.left_chat_member)) """Filter service messages for members that left the chat.""" - new_chat_title = build("NewChatTitle", lambda _, m: bool(m.new_chat_title)) + new_chat_title = create("NewChatTitle", lambda _, m: bool(m.new_chat_title)) """Filter service messages for new chat titles.""" - new_chat_photo = build("NewChatPhoto", lambda _, m: bool(m.new_chat_photo)) + new_chat_photo = create("NewChatPhoto", lambda _, m: bool(m.new_chat_photo)) """Filter service messages for new chat photos.""" - delete_chat_photo = build("DeleteChatPhoto", lambda _, m: bool(m.delete_chat_photo)) + delete_chat_photo = create("DeleteChatPhoto", lambda _, m: bool(m.delete_chat_photo)) """Filter service messages for deleted photos.""" - group_chat_created = build("GroupChatCreated", lambda _, m: bool(m.group_chat_created)) + group_chat_created = create("GroupChatCreated", lambda _, m: bool(m.group_chat_created)) """Filter service messages for group chat creations.""" - supergroup_chat_created = build("SupergroupChatCreated", lambda _, m: bool(m.supergroup_chat_created)) + supergroup_chat_created = create("SupergroupChatCreated", lambda _, m: bool(m.supergroup_chat_created)) """Filter service messages for supergroup chat creations.""" - channel_chat_created = build("ChannelChatCreated", lambda _, m: bool(m.channel_chat_created)) + channel_chat_created = create("ChannelChatCreated", lambda _, m: bool(m.channel_chat_created)) """Filter service messages for channel chat creations.""" - migrate_to_chat_id = build("MigrateToChatId", lambda _, m: bool(m.migrate_to_chat_id)) + migrate_to_chat_id = create("MigrateToChatId", lambda _, m: bool(m.migrate_to_chat_id)) """Filter service messages that contain migrate_to_chat_id.""" - migrate_from_chat_id = build("MigrateFromChatId", lambda _, m: bool(m.migrate_from_chat_id)) + migrate_from_chat_id = create("MigrateFromChatId", lambda _, m: bool(m.migrate_from_chat_id)) """Filter service messages that contain migrate_from_chat_id.""" - pinned_message = build("PinnedMessage", lambda _, m: bool(m.pinned_message)) + pinned_message = create("PinnedMessage", lambda _, m: bool(m.pinned_message)) """Filter service messages for pinned messages.""" - reply_keyboard = build("ReplyKeyboard", lambda _, m: isinstance(m.reply_markup, ReplyKeyboardMarkup)) + reply_keyboard = create("ReplyKeyboard", lambda _, m: isinstance(m.reply_markup, ReplyKeyboardMarkup)) """Filter messages containing reply keyboard markups""" - inline_keyboard = build("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup)) + inline_keyboard = create("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup)) """Filter messages containing inline keyboard markups""" @staticmethod @@ -174,7 +174,7 @@ class Filters: return bool(m.command) - return build( + return create( "Command", f, c={command if case_sensitive @@ -206,7 +206,7 @@ class Filters: m.matches = [i for i in _.p.finditer(m.text or "")] return bool(m.matches) - return build("Regex", f, p=re.compile(pattern, flags)) + return create("Regex", f, p=re.compile(pattern, flags)) @staticmethod def user(user: int or str or list): @@ -216,7 +216,7 @@ class Filters: user (``int`` | ``str`` | ``list``): The user or list of user IDs (int) or usernames (str) the filter should look for. """ - return build( + return create( "User", lambda _, m: bool(m.from_user and (m.from_user.id in _.u @@ -237,7 +237,7 @@ class Filters: chat (``int`` | ``str`` | ``list``): The chat or list of chat IDs (int) or usernames (str) the filter should look for. """ - return build( + return create( "Chat", lambda _, m: bool(m.chat and (m.chat.id in _.c @@ -250,7 +250,7 @@ class Filters: ) ) - service = build( + service = create( "Service", lambda _, m: bool( Filters.new_chat_members(m) @@ -268,7 +268,7 @@ class Filters: ) """Filter all service messages.""" - media = build( + media = create( "Media", lambda _, m: bool( Filters.audio(m) From 0c77fe91fe8be09c4dcc43904cf938298c6fe677 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 17 Aug 2018 12:17:54 +0200 Subject: [PATCH 74/85] Add TODO --- pyrogram/client/filters/filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 92fb278e..ba8e7c4b 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -23,6 +23,7 @@ from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup def create(name: str, func: callable, **kwargs) -> type: + # TODO: unpack kwargs using **kwargs into the dict itself. For Python 3.5+ only d = {"__call__": func} d.update(kwargs) From 6dfaa3ddeaa0ca26e80716efdc14236909701e76 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 18 Aug 2018 18:18:40 +0200 Subject: [PATCH 75/85] Small documentation updates --- docs/source/start/Installation.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/start/Installation.rst b/docs/source/start/Installation.rst index 8aea16de..bba927e4 100644 --- a/docs/source/start/Installation.rst +++ b/docs/source/start/Installation.rst @@ -7,7 +7,8 @@ We recommend using the latest version of Python 3 and pip. Get Python 3 from https://www.python.org/downloads/ or with your package manager and pip by following the instructions at https://pip.pypa.io/en/latest/installing/. -Pyrogram supports Python 3 only, starting from version 3.4 and PyPy. +.. note:: + Pyrogram supports Python 3 only, starting from version 3.4 and PyPy. Install Pyrogram ---------------- From ed05c56f5236e15dbe3922ae50eb522d361607a5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:22:28 +0200 Subject: [PATCH 76/85] Clearer Filters docs. Add create to Filters' namespace --- pyrogram/client/filters/filters.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index ba8e7c4b..043f29ff 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -31,8 +31,14 @@ def create(name: str, func: callable, **kwargs) -> type: class Filters: - """This class provides access to all Filters available in Pyrogram. - Filters are intended to be used with the :obj:`MessageHandler `.""" + """This class provides access to all library-defined Filters available in Pyrogram. + + The Filters listed here are intended to be used with the :obj:`MessageHandler ` only. + At the moment, if you want to filter updates coming from different `Handlers `_ you have to create + your own filters with :meth:`Filters.create` and use them in the same way. + """ + + create = create bot = create("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) """Filter messages coming from bots""" From 493fc4a6582e65fc82af6964b9c6c338329e5990 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:24:24 +0200 Subject: [PATCH 77/85] Document Filters.create() method --- pyrogram/client/filters/filters.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 043f29ff..4cd4b191 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -23,6 +23,27 @@ from ..types.bots import InlineKeyboardMarkup, ReplyKeyboardMarkup def create(name: str, func: callable, **kwargs) -> type: + """Use this method to create a Filter. + + Custom filters give you extra control over which updates are allowed or not to be processed by your handlers. + + Args: + name (``str``): + Your filter's name. Can be anything you like. + + func (``callable``): + A function that accepts two arguments *(filter, update)* and returns a Boolean: True if the update should be + handled, False otherwise. + The "update" argument type will vary depending on which `Handler `_ is coming from. + For example, in a :obj:`MessageHandler ` the update type will be + a :obj:`Message `; in a :obj:`CallbackQueryHandler ` the + update type will be a :obj:`CallbackQuery `. Your function body can then access the + incoming update and decide whether to allow it or not. + + **kwargs (``any``, *optional*): + Any keyword argument you would like to pass. Useful for custom filters that accept parameters (e.g.: + :meth:`Filters.command`, :meth:`Filters.regex`). + """ # TODO: unpack kwargs using **kwargs into the dict itself. For Python 3.5+ only d = {"__call__": func} d.update(kwargs) From de9beac2ce4614ef8265d6ba67b397489d59e3a1 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:25:09 +0200 Subject: [PATCH 78/85] Refactor UpdateHandling page --- docs/source/resources/UpdateHandling.rst | 186 ++++------------------- 1 file changed, 28 insertions(+), 158 deletions(-) diff --git a/docs/source/resources/UpdateHandling.rst b/docs/source/resources/UpdateHandling.rst index 0aa6457f..781a48af 100644 --- a/docs/source/resources/UpdateHandling.rst +++ b/docs/source/resources/UpdateHandling.rst @@ -2,188 +2,58 @@ Update Handling =============== Updates are events that happen in your Telegram account (incoming messages, new channel posts, new members join, ...) -and are handled by registering one or more callback functions with an Handler. There are multiple Handlers to choose -from, one for each kind of update: +and can be handled by registering one or more callback functions in your app by using an `Handler <../pyrogram/Handlers.html>`_. -- `MessageHandler <../pyrogram/handlers/MessageHandler.html>`_ -- `DeletedMessagesHandler <../pyrogram/handlers/DeletedMessagesHandler.html>`_ -- `CallbackQueryHandler <../pyrogram/handlers/CallbackQueryHandler.html>`_ -- `RawUpdateHandler <../pyrogram/handlers/RawUpdateHandler.html>`_ -- `DisconnectHandler <../pyrogram/handlers/DisconnectHandler.html>`_ +To put it simply, whenever an update is received from Telegram it will be dispatched and your previously defined callback +function(s) will be called back with the update itself as argument. Registering an Handler ---------------------- -We shall examine the :obj:`MessageHandler `, which will be in charge for handling -:obj:`Message ` objects. - -- The easiest and nicest way to register a MessageHandler is by decorating your function with the - :meth:`on_message() ` decorator. Here's a full example that prints out the content - of a message as soon as it arrives. - - .. code-block:: python - - from pyrogram import Client - - app = Client("my_account") +To explain how `Handlers <../pyrogram/Handlers.html>`_ work let's have a look at the most used one, the +:obj:`MessageHandler `, which will be in charge for handling :obj:`Message ` +updates coming from all around your chats. Every other handler shares the same setup logic; you should not have troubles +settings them up once you learn from this section. - @app.on_message() - def my_handler(client, message): - print(message) - - - app.run() - -- If you prefer not to use decorators, there is an alternative way for registering Handlers. - This is useful, for example, when you want to keep your callback functions in separate files. - - .. code-block:: python - - from pyrogram import Client, MessageHandler - - - def my_handler(client, message): - print(message) - - - app = Client("my_account") - - app.add_handler(MessageHandler(my_handler)) - - app.run() - -Using Filters -------------- - -For a finer grained control over what kind of messages will be allowed or not in your callback functions, you can use -:class:`Filters `. - -- This example will show you how to **only** handle messages containing an - :obj:`Audio ` object and filter out any other message: - - .. code-block:: python - - from pyrogram import Filters - - - @app.on_message(Filters.audio) - def my_handler(client, message): - print(message) - -- or, without decorators: - - .. code-block:: python - - from pyrogram import Filters, MessageHandler - - - def my_handler(client, message): - print(message) - - - app.add_handler(MessageHandler(my_handler, Filters.audio)) - -Combining Filters ------------------ - -Filters can also be used in a more advanced way by combining more filters together using bitwise operators: - -- Use ``~`` to invert a filter (behaves like the ``not`` operator). -- Use ``&`` and ``|`` to merge two filters (behave like ``and``, ``or`` operators respectively). - -Here are some examples: - -- Message is a **text** message **and** is **not edited**. - - .. code-block:: python - - @app.on_message(Filters.text & ~Filters.edited) - def my_handler(client, message): - print(message) - -- Message is a **sticker** **and** is coming from a **channel or** a **private** chat. - - .. code-block:: python - - @app.on_message(Filters.sticker & (Filters.channel | Filters.private)) - def my_handler(client, message): - print(message) - -Advanced Filters +Using Decorators ---------------- -Some filters, like :obj:`command() ` or :obj:`regex() ` -can also accept arguments: - -- Message is either a */start* or */help* **command**. - - .. code-block:: python - - @app.on_message(Filters.command(["start", "help"])) - def my_handler(client, message): - print(message) - -- Message is a **text** message matching the given **regex** pattern. - - .. code-block:: python - - @app.on_message(Filters.regex("pyrogram")) - def my_handler(client, message): - print(message) - -More handlers using different filters can also live together. +The easiest and nicest way to register a MessageHandler is by decorating your function with the +:meth:`on_message() ` decorator. Here's a full example that prints out the content +of a message as soon as it arrives. .. code-block:: python - @app.on_message(Filters.command("start")) - def start_command(client, message): - print("This is the /start command") + from pyrogram import Client + + app = Client("my_account") - @app.on_message(Filters.command("help")) - def help_command(client, message): - print("This is the /help command") + @app.on_message() + def my_handler(client, message): + print(message) - @app.on_message(Filters.chat("PyrogramChat")) - def from_pyrogramchat(client, message): - print("New message in @PyrogramChat") + app.run() -Handler Groups --------------- +Using add_handler() +------------------- -If you register handlers with overlapping filters, only the first one is executed and any other handler will be ignored. - -In order to process the same message more than once, you can register your handler in a different group. -Groups are identified by a number (number 0 being the default) and are sorted. This means that a lower group number has -a higher priority. - -For example, in: +If you prefer not to use decorators for any reason, there is an alternative way for registering Handlers. +This is useful, for example, when you want to keep your callback functions in separate files. .. code-block:: python - @app.on_message(Filters.text | Filters.sticker) - def text_or_sticker(client, message): - print("Text or Sticker") + from pyrogram import Client, MessageHandler - @app.on_message(Filters.text) - def just_text(client, message): - print("Just Text") + def my_handler(client, message): + print(message) -``just_text`` is never executed. To enable it, simply register the function using a different group: -.. code-block:: python + app = Client("my_account") - @app.on_message(Filters.text, group=1) - def just_text(client, message): - print("Just Text") + app.add_handler(MessageHandler(my_handler)) -or, if you want ``just_text`` to be fired *before* ``text_or_sticker``: - -.. code-block:: python - - @app.on_message(Filters.text, group=-1) - def just_text(client, message): - print("Just Text") \ No newline at end of file + app.run() From 1666eaac7753a4f8c6275ba6e28b546330ed3557 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 17:25:39 +0200 Subject: [PATCH 79/85] Add UsingFilter doc page --- docs/source/index.rst | 1 + docs/source/resources/UsingFilters.rst | 228 +++++++++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 docs/source/resources/UsingFilters.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 051b5af8..ec6b24f2 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -84,6 +84,7 @@ To get started, press the Next button. :caption: Resources resources/UpdateHandling + resources/UsingFilters resources/AutoAuthorization resources/CustomizeSessions resources/TgCrypto diff --git a/docs/source/resources/UsingFilters.rst b/docs/source/resources/UsingFilters.rst new file mode 100644 index 00000000..79ecd24f --- /dev/null +++ b/docs/source/resources/UsingFilters.rst @@ -0,0 +1,228 @@ +Using Filters +============= + +For a finer grained control over what kind of messages will be allowed or not in your callback functions, you can use +:class:`Filters `. + +.. note:: + This section makes use of Handlers to handle updates. Learn more at `Update Handling `_. + +- This example will show you how to **only** handle messages containing an :obj:`Audio ` object and + ignore any other message: + + .. code-block:: python + + from pyrogram import Filters + + + @app.on_message(Filters.audio) + def my_handler(client, message): + print(message) + +- or, without decorators: + + .. code-block:: python + + from pyrogram import Filters, MessageHandler + + + def my_handler(client, message): + print(message) + + + app.add_handler(MessageHandler(my_handler, Filters.audio)) + +Combining Filters +----------------- + +Filters can also be used in a more advanced way by inverting and combining more filters together using bitwise +operators: + +- Use ``~`` to invert a filter (behaves like the ``not`` operator). +- Use ``&`` and ``|`` to merge two filters (behave like ``and``, ``or`` operators respectively). + +Here are some examples: + +- Message is a **text** message **and** is **not edited**. + + .. code-block:: python + + @app.on_message(Filters.text & ~Filters.edited) + def my_handler(client, message): + print(message) + +- Message is a **sticker** **and** is coming from a **channel or** a **private** chat. + + .. code-block:: python + + @app.on_message(Filters.sticker & (Filters.channel | Filters.private)) + def my_handler(client, message): + print(message) + +Advanced Filters +---------------- + +Some filters, like :meth:`command() ` or :meth:`regex() ` +can also accept arguments: + +- Message is either a */start* or */help* **command**. + + .. code-block:: python + + @app.on_message(Filters.command(["start", "help"])) + def my_handler(client, message): + print(message) + +- Message is a **text** message matching the given **regex** pattern. + + .. code-block:: python + + @app.on_message(Filters.regex("pyrogram")) + def my_handler(client, message): + print(message) + +More handlers using different filters can also live together. + +.. code-block:: python + + @app.on_message(Filters.command("start")) + def start_command(client, message): + print("This is the /start command") + + + @app.on_message(Filters.command("help")) + def help_command(client, message): + print("This is the /help command") + + + @app.on_message(Filters.chat("PyrogramChat")) + def from_pyrogramchat(client, message): + print("New message in @PyrogramChat") + +Handler Groups +-------------- + +If you register handlers with overlapping filters, only the first one is executed and any other handler will be ignored. + +In order to process the same message more than once, you can register your handler in a different group. +Groups are identified by a number (number 0 being the default) and are sorted. This means that a lower group number has +a higher priority. + +For example, in: + +.. code-block:: python + + @app.on_message(Filters.text | Filters.sticker) + def text_or_sticker(client, message): + print("Text or Sticker") + + + @app.on_message(Filters.text) + def just_text(client, message): + print("Just Text") + +``just_text`` is never executed because ``text_or_sticker`` already handles texts. To enable it, simply register the +function using a different group: + +.. code-block:: python + + @app.on_message(Filters.text, group=1) + def just_text(client, message): + print("Just Text") + +or, if you want ``just_text`` to be fired *before* ``text_or_sticker`` (note ``-1``, which is less than ``0``): + +.. code-block:: python + + @app.on_message(Filters.text, group=-1) + def just_text(client, message): + print("Just Text") + +Custom Filters +-------------- + +Pyrogram already provides lots of built-in :class:`Filters ` to work with, but in case you can't find +a specific one for your needs or want to build a custom filter by yourself (to be used in a different handler, for +example) you can use :meth:`Filters.create() `. + +.. note:: + At the moment, the built-in filters are intended to be used with the :obj:`MessageHandler ` + only. + +An example to demonstrate how custom filters work is to show how to create and use one for the +:obj:`CallbackQueryHandler `. Note that callback queries updates are only received by Bots; +create and `authorize your bot <../start/Setup.html#bot-authorization>`_, then send a message with an inline keyboard to +yourself. This allows you to test your filter by pressing the inline button: + +.. code-block:: python + + from pyrogram import InlineKeyboardMarkup, InlineKeyboardButton + + app.send_message( + "username", # Change this to your username or id + "Pyrogram's custom filter test", + reply_markup=InlineKeyboardMarkup( + [[InlineKeyboardButton("Press me", "pyrogram")]] + ) + ) + +Basic Filters +^^^^^^^^^^^^^ + +For this basic filter we will be using only the first two parameters of :meth:`Filters.create() `. + +The code below creates a simple filter for hardcoded callback data. This filter will only allow callback queries +containing "pyrogram" as data: + +.. code-block:: python + + hardcoded_data = Filters.create( + name="HardcodedData", + func=lambda filter, callback_query: callback_query.data == "pyrogram" + ) + +The ``lambda`` operator in python is used to create small anonymous functions and is perfect for this example, the same +could be achieved with a normal function, but we don't really need it as it makes sense only inside the filter itself: + +.. code-block:: python + + def func(filter, callback_query): + return callback_query.data == "pyrogram" + + hardcoded_data = Filters.create( + name="HardcodedData", + func=func + ) + +The filter usage remains the same: + +.. code-block:: python + + @app.on_callback_query(hardcoded_data) + def pyrogram_data(client, callback_query): + client.answer_callback_query(callback_query.id, "it works!") + +Filters with Arguments +^^^^^^^^^^^^^^^^^^^^^^ + +A much cooler filter would be one that accepts "pyrogram" or any other data as argument at usage time. +A dynamic filter like this will make use of the third parameter of :meth:`Filters.create() `. + +This is how a dynamic custom filter looks like: + +.. code-block:: python + + def dynamic_data(data): + return Filters.create( + name="DynamicData", + func=lambda filter, callback_query: filter.data == callback_query.data, + data=data # "data" kwarg is accessed with "filter.data" + ) + +And its usage: + +.. code-block:: python + + @app.on_callback_query(dynamic_data("pyrogram")) + def pyrogram_data(client, callback_query): + client.answer_callback_query(callback_query.id, "it works!") \ No newline at end of file From 21d914e414ef36a09017d42b40e7bfe638f0f5cd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 19 Aug 2018 19:40:23 +0200 Subject: [PATCH 80/85] Remove unused constant --- pyrogram/client/ext/base_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index c8a6029d..c78997c1 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -41,7 +41,6 @@ class BaseClient: platform.release() ) - SYSTEM_LANG_CODE = "en" LANG_CODE = "en" INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/joinchat/)([\w-]+)$") From 088a4c35c973723ebe0ecf3cc0ce9d5046de8274 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Aug 2018 02:12:21 +0200 Subject: [PATCH 81/85] Add is_pinned attribute to Dialog --- pyrogram/client/methods/messages/get_dialogs.py | 3 ++- pyrogram/client/types/user_and_chats/dialog.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py index f43ca6a5..e7b3e2a8 100644 --- a/pyrogram/client/methods/messages/get_dialogs.py +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -92,7 +92,8 @@ class GetDialogs(BaseClient): top_message=messages.get(chat_id), unread_messages_count=dialog.unread_count, unread_mentions_count=dialog.unread_mentions_count, - unread_mark=dialog.unread_mark + unread_mark=dialog.unread_mark, + is_pinned=dialog.pinned ) ) diff --git a/pyrogram/client/types/user_and_chats/dialog.py b/pyrogram/client/types/user_and_chats/dialog.py index 60ffb76c..fa5fb2b8 100644 --- a/pyrogram/client/types/user_and_chats/dialog.py +++ b/pyrogram/client/types/user_and_chats/dialog.py @@ -37,6 +37,9 @@ class Dialog(Object): unread_mark (``bool``): True, if the dialog has the unread mark set. + + is_pinned (``bool``): + True, if the dialog is pinned. """ ID = 0xb0700028 @@ -45,9 +48,11 @@ class Dialog(Object): top_message, unread_messages_count: int, unread_mentions_count: int, - unread_mark: bool): + unread_mark: bool, + is_pinned: bool): self.chat = chat self.top_message = top_message self.unread_messages_count = unread_messages_count self.unread_mentions_count = unread_mentions_count self.unread_mark = unread_mark + self.is_pinned = is_pinned From 9c0f8b2f3b4a9fdec002f35dfa165d4bdab838b7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Aug 2018 11:24:00 +0200 Subject: [PATCH 82/85] Document get_dialogs() method --- .../client/methods/messages/get_dialogs.py | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py index e7b3e2a8..e22f7e2f 100644 --- a/pyrogram/client/methods/messages/get_dialogs.py +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -22,19 +22,41 @@ from ...ext import BaseClient, utils class GetDialogs(BaseClient): - # TODO docstrings - def get_dialogs(self, + offset_dialogs=None, limit: int = 100, - pinned_only: bool = False, - last_chunk=None): + pinned_only: bool = False): + """Use this method to get the user's dialogs + + You can get up to 100 dialogs at once. + + Args: + limit (``str``, *optional*): + Limits the number of dialogs to be retrieved. + Defaults to 100 + + pinned_only (``bool``, *optional*): + Pass True if you want to get only pinned dialogs. + Defaults to False. + + offset_dialogs (:obj:`Dialogs`): + Pass the previous dialogs object to retrieve the next dialogs chunk starting from the last dialog. + Defaults to None (start from the beginning). + + Returns: + On success, a :obj:`Dialogs` object is returned. + + Raises: + :class:`Error` + """ + if pinned_only: r = self.send(functions.messages.GetPinnedDialogs()) else: offset_date = 0 - if last_chunk: - for dialog in reversed(last_chunk.dialogs): + if offset_dialogs: + for dialog in reversed(offset_dialogs.dialogs): top_message = dialog.top_message if top_message: From 2d8792a7cd09f5c169287c2e4dc60d89dea5a19c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 20 Aug 2018 11:24:47 +0200 Subject: [PATCH 83/85] Move get_dialogs() from "messages" to "chats" namespace --- pyrogram/client/methods/chats/__init__.py | 4 +++- pyrogram/client/methods/{messages => chats}/get_dialogs.py | 0 pyrogram/client/methods/messages/__init__.py | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-) rename pyrogram/client/methods/{messages => chats}/get_dialogs.py (100%) diff --git a/pyrogram/client/methods/chats/__init__.py b/pyrogram/client/methods/chats/__init__.py index ce56f16b..72134abf 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -21,6 +21,7 @@ from .export_chat_invite_link import ExportChatInviteLink from .get_chat import GetChat from .get_chat_member import GetChatMember from .get_chat_members import GetChatMembers +from .get_dialogs import GetDialogs from .join_chat import JoinChat from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat @@ -50,6 +51,7 @@ class Chats( SetChatTitle, SetChatDescription, PinChatMessage, - UnpinChatMessage + UnpinChatMessage, + GetDialogs ): pass diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/chats/get_dialogs.py similarity index 100% rename from pyrogram/client/methods/messages/get_dialogs.py rename to pyrogram/client/methods/chats/get_dialogs.py diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index 174586bc..35dae756 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -22,14 +22,13 @@ from .edit_message_media import EditMessageMedia from .edit_message_reply_markup import EditMessageReplyMarkup from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages -from .get_dialogs import GetDialogs from .get_history import GetHistory from .get_messages import GetMessages +from .send_animation import SendAnimation from .send_audio import SendAudio from .send_chat_action import SendChatAction from .send_contact import SendContact from .send_document import SendDocument -from .send_animation import SendAnimation from .send_location import SendLocation from .send_media_group import SendMediaGroup from .send_message import SendMessage @@ -50,7 +49,6 @@ class Messages( ForwardMessages, GetHistory, GetMessages, - GetDialogs, SendAudio, SendChatAction, SendContact, From 03b17d5bcefa42e3c413ffde253bb0166aaa96ad Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 21 Aug 2018 21:18:06 +0200 Subject: [PATCH 84/85] Fix clickable link --- pyrogram/client/methods/messages/send_message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/send_message.py b/pyrogram/client/methods/messages/send_message.py index b770133e..00087307 100644 --- a/pyrogram/client/methods/messages/send_message.py +++ b/pyrogram/client/methods/messages/send_message.py @@ -61,7 +61,7 @@ class SendMessage(BaseClient): instructions to remove reply keyboard or to force a reply from the user. Returns: - On success, the sent Message is returned. + On success, the sent :obj:`Message` is returned. Raises: :class:`Error ` From c501eeb5a2ee164e656742903953cc93e45a9da9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 21 Aug 2018 21:23:19 +0200 Subject: [PATCH 85/85] Update to v0.8.0dev1 There are a quite lot of changes it deserves a new "minor" update. --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index a822524c..7ef07777 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès