diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 3b6dbae7..555d1824 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -494,14 +494,14 @@ 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.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\",") 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 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/pyrogram/Client.rst b/docs/source/pyrogram/Client.rst index bf9ac2ca..45d40368 100644 --- a/docs/source/pyrogram/Client.rst +++ b/docs/source/pyrogram/Client.rst @@ -1,76 +1,133 @@ 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 + +Messages +-------- + +.. autosummary:: + :nosignatures: + + send_message + forward_messages + send_photo + send_audio + send_document + send_sticker + send_video + send_animation + 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_raw_update - add_handler - remove_handler - send - resolve_peer - get_me - send_message - forward_messages - send_photo - send_audio - send_document - 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 \ No newline at end of file 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 ===== diff --git a/docs/source/pyrogram/Handlers.rst b/docs/source/pyrogram/Handlers.rst new file mode 100644 index 00000000..9f69c2c9 --- /dev/null +++ b/docs/source/pyrogram/Handlers.rst @@ -0,0 +1,29 @@ +Handlers +======== + +.. currentmodule:: pyrogram + +.. autosummary:: + :nosignatures: + + MessageHandler + DeletedMessagesHandler + CallbackQueryHandler + DisconnectHandler + RawUpdateHandler + +.. autoclass:: MessageHandler + :members: + +.. autoclass:: DeletedMessagesHandler + :members: + +.. autoclass:: CallbackQueryHandler + :members: + +.. autoclass:: DisconnectHandler + :members: + +.. autoclass:: RawUpdateHandler + :members: + diff --git a/docs/source/pyrogram/Types.rst b/docs/source/pyrogram/Types.rst new file mode 100644 index 00000000..92093b11 --- /dev/null +++ b/docs/source/pyrogram/Types.rst @@ -0,0 +1,176 @@ +Types +===== + +.. currentmodule:: pyrogram + +Users & Chats +------------- + +.. autosummary:: + :nosignatures: + + User + Chat + ChatPhoto + ChatMember + ChatMembers + Dialog + Dialogs + +Messages & Media +---------------- + +.. autosummary:: + :nosignatures: + + Message + Messages + MessageEntity + Photo + PhotoSize + UserProfilePhotos + Audio + Document + Animation + Video + Voice + VideoNote + Contact + Location + Venue + Sticker + +Bots +---- + +.. autosummary:: + :nosignatures: + + ReplyKeyboardMarkup + KeyboardButton + ReplyKeyboardRemove + InlineKeyboardMarkup + InlineKeyboardButton + ForceReply + CallbackQuery + +Input Media +----------- + +.. autosummary:: + :nosignatures: + + InputMediaPhoto + InputMediaVideo + InputPhoneContact + +.. 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:: Animation + :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: 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: diff --git a/docs/source/pyrogram/handlers/index.rst b/docs/source/pyrogram/handlers/index.rst deleted file mode 100644 index 272e529f..00000000 --- a/docs/source/pyrogram/handlers/index.rst +++ /dev/null @@ -1,11 +0,0 @@ -:tocdepth: 1 - -Handlers -======== - -.. toctree:: - MessageHandler - DeletedMessagesHandler - CallbackQueryHandler - DisconnectHandler - RawUpdateHandler diff --git a/docs/source/pyrogram/index.rst b/docs/source/pyrogram/index.rst index c272bc42..20e7c918 100644 --- a/docs/source/pyrogram/index.rst +++ b/docs/source/pyrogram/index.rst @@ -7,9 +7,11 @@ 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 + Types + Handlers Filters ChatAction ParseMode 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/index.rst b/docs/source/pyrogram/types/index.rst deleted file mode 100644 index ff3de94e..00000000 --- a/docs/source/pyrogram/types/index.rst +++ /dev/null @@ -1,36 +0,0 @@ -:tocdepth: 1 - -Types -===== - -.. toctree:: - User - Chat - Message - MessageEntity - Messages - Photo - PhotoSize - Audio - Document - GIF - Video - Voice - VideoNote - Contact - Location - Venue - UserProfilePhotos - ChatPhoto - ChatMember - 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 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: diff --git a/docs/source/resources/TextFormatting.rst b/docs/source/resources/TextFormatting.rst index aaa78f0a..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 @@ -11,7 +14,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 +37,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 @@ -46,9 +49,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). 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() 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 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 ---------------- diff --git a/docs/source/start/Setup.rst b/docs/source/start/Setup.rst index 417d62d8..e0cccc2c 100644 --- a/docs/source/start/Setup.rst +++ b/docs/source/start/Setup.rst @@ -8,22 +8,29 @@ 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 ------------- -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 @@ -45,7 +52,8 @@ There are two ways to configure a Pyrogram application project, and you can choo 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 @@ -76,16 +84,17 @@ 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 ----------------- -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 @@ -94,9 +103,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 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 `, - :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 ` @@ -1032,38 +1030,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 await 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: await 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: diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index 2a438168..16f0e00c 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -40,7 +40,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-]+)$") @@ -59,7 +58,7 @@ class BaseClient: 5: "document", 8: "sticker", 9: "audio", - 10: "gif", + 10: "animation", 13: "video_note" } diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index c4b84528..22eba425 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -81,7 +81,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" } @@ -92,18 +93,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 @@ -305,7 +308,7 @@ async def parse_messages( venue = None audio = None voice = None - gif = None + animation = None video = None video_note = None sticker = None @@ -387,7 +390,8 @@ async 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 @@ -444,7 +448,7 @@ async 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( " type: +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) @@ -30,112 +52,118 @@ def build(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. - bot = build("Bot", lambda _, m: bool(m.from_user and m.from_user.is_bot)) + 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""" - 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.""" - gif = build("GIF", lambda _, m: bool(m.gif)) - """Filter messages that contain :obj:`GIF ` objects.""" + 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 +202,7 @@ class Filters: return bool(m.command) - return build( + return create( "Command", f, c={command if case_sensitive @@ -206,7 +234,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 +244,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 +265,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 +278,7 @@ class Filters: ) ) - service = build( + service = create( "Service", lambda _, m: bool( Filters.new_chat_members(m) @@ -268,7 +296,7 @@ class Filters: ) """Filter all service messages.""" - media = build( + media = create( "Media", lambda _, m: bool( Filters.audio(m) @@ -276,7 +304,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) 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 ): diff --git a/pyrogram/client/methods/bots/request_callback_answer.py b/pyrogram/client/methods/bots/request_callback_answer.py index ad197652..8b3135b0 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 a052f6e7..93d2d5cd 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/__init__.py b/pyrogram/client/methods/chats/__init__.py index 038440f6..72134abf 100644 --- a/pyrogram/client/methods/chats/__init__.py +++ b/pyrogram/client/methods/chats/__init__.py @@ -19,7 +19,9 @@ 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 .get_dialogs import GetDialogs from .join_chat import JoinChat from .kick_chat_member import KickChatMember from .leave_chat import LeaveChat @@ -43,11 +45,13 @@ class Chats( RestrictChatMember, PromoteChatMember, GetChatMembers, + GetChatMember, SetChatPhoto, DeleteChatPhoto, SetChatTitle, SetChatDescription, PinChatMessage, - UnpinChatMessage + UnpinChatMessage, + GetDialogs ): pass diff --git a/pyrogram/client/methods/chats/delete_chat_photo.py b/pyrogram/client/methods/chats/delete_chat_photo.py index d8eff6a4..aa29267d 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 050b8118..a88b2bfa 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 new file mode 100644 index 00000000..51e07f91 --- /dev/null +++ b/pyrogram/client/methods/chats/get_chat_member.py @@ -0,0 +1,75 @@ +# 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): + """Use this method to get information about one member of a chat. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + 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). + + 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) + + 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)) diff --git a/pyrogram/client/methods/chats/get_chat_members.py b/pyrogram/client/methods/chats/get_chat_members.py index 295a32c5..aa1b0392 100644 --- a/pyrogram/client/methods/chats/get_chat_members.py +++ b/pyrogram/client/methods/chats/get_chat_members.py @@ -36,6 +36,42 @@ 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. + + 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 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. + """ peer = await self.resolve_peer(chat_id) if isinstance(peer, types.InputPeerChat): diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/chats/get_dialogs.py similarity index 74% rename from pyrogram/client/methods/messages/get_dialogs.py rename to pyrogram/client/methods/chats/get_dialogs.py index d8f47059..8d9ad00f 100644 --- a/pyrogram/client/methods/messages/get_dialogs.py +++ b/pyrogram/client/methods/chats/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): + """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` + """ - async def get_dialogs(self, - limit: int = 100, - pinned_only: bool = False, - last_chunk=None): if pinned_only: r = await 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: @@ -92,7 +114,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/methods/chats/kick_chat_member.py b/pyrogram/client/methods/chats/kick_chat_member.py index 5b8dda53..6c018737 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 9e6f49c9..495acc43 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 9cfe426b..172e126a 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 a9439ed1..14bd42f3 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 8f647818..2a71b06e 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 558671b7..53882323 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 2769ccb9..15f999e5 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 ed00f428..87175c1f 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 9b6b4144..101b7bff 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/__init__.py b/pyrogram/client/methods/messages/__init__.py index 94279ffd..35dae756 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -18,17 +18,17 @@ 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 -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_gif import SendGIF from .send_location import SendLocation from .send_media_group import SendMediaGroup from .send_message import SendMessage @@ -44,16 +44,16 @@ class Messages( DeleteMessages, EditMessageCaption, EditMessageReplyMarkup, + EditMessageMedia, EditMessageText, ForwardMessages, GetHistory, GetMessages, - GetDialogs, SendAudio, SendChatAction, SendContact, SendDocument, - SendGIF, + SendAnimation, SendLocation, SendMediaGroup, SendMessage, diff --git a/pyrogram/client/methods/messages/delete_messages.py b/pyrogram/client/methods/messages/delete_messages.py index 7fa43d4e..c4db5027 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 720a1d84..38101182 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_media.py b/pyrogram/client/methods/messages/edit_message_media.py new file mode 100644 index 00000000..086d8dc2 --- /dev/null +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -0,0 +1,264 @@ +# 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 binascii +import mimetypes +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, InputMediaVideo, InputMediaAudio, + InputMediaAnimation +) + + +class EditMessageMedia(BaseClient): + def edit_message_media(self, + chat_id: int or str, + 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 + ) + ) + elif media.media.startswith("http"): + media = types.InputMediaPhotoExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else " 24 else " 24 else " 24 else "` or :obj:`HTML ` @@ -65,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. @@ -121,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 await self.save_file(thumb) - file = await self.save_file(gif, progress=progress, progress_args=progress_args) + file = await self.save_file(animation, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( mime_type=mimetypes.types_map[".mp4"], file=file, @@ -135,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 "` | ``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 e15bc501..ef9a0a75 100644 --- a/pyrogram/client/methods/messages/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -36,7 +36,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. @@ -48,7 +47,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/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index 2a88c286..15e87feb 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_location.py b/pyrogram/client/methods/messages/send_location.py index 042f67bc..b795a8d5 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 188ed70f..35cc6e87 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 0009d499..a92105cb 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. @@ -62,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 ` diff --git a/pyrogram/client/methods/messages/send_photo.py b/pyrogram/client/methods/messages/send_photo.py index c4f81ece..18ea174d 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 d2e806bb..481f47ab 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 a08b1139..f54936be 100644 --- a/pyrogram/client/methods/messages/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -22,15 +22,15 @@ from pyrogram.client.ext import BaseClient, utils class SendVenue(BaseClient): async def send_venue(self, - chat_id: int or str, - latitude: float, - longitude: float, - title: str, - address: str, - foursquare_id: str = "", - disable_notification: bool = None, - reply_to_message_id: int = None, - reply_markup=None): + chat_id: int or str, + latitude: float, + longitude: float, + title: str, + address: str, + foursquare_id: str = "", + foursquare_type: str = "",disable_notification: bool = None, + reply_to_message_id: int = None, + reply_markup=None): """Use this method to send information about a venue. Args: @@ -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. @@ -55,6 +54,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. @@ -84,7 +87,7 @@ class SendVenue(BaseClient): address=address, provider="", venue_id=foursquare_id, - venue_type="" + venue_type=foursquare_type ), message="", silent=disable_notification or None, diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index ca6eadd2..aa6908e8 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 429ef124..887c9179 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 f60bb577..5bbb92a2 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 13649751..1d711cf3 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/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 97% rename from pyrogram/client/methods/download_media.py rename to pyrogram/client/methods/utilities/download_media.py index b379dbf7..91d865f6 100644 --- a/pyrogram/client/methods/download_media.py +++ b/pyrogram/client/methods/utilities/download_media.py @@ -19,7 +19,7 @@ import asyncio from pyrogram.client import types as pyrogram_types -from ..ext import BaseClient +from ...ext import BaseClient class DownloadMedia(BaseClient): @@ -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, ( @@ -111,7 +111,7 @@ class DownloadMedia(BaseClient): pyrogram_types.Voice, pyrogram_types.VideoNote, pyrogram_types.Sticker, - pyrogram_types.GIF + pyrogram_types.Animation )): if isinstance(message, pyrogram_types.Photo): media = pyrogram_types.Document( diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index e6fcc8aa..230d5e5d 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -16,26 +16,25 @@ # 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 .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_photo import InputMediaPhoto -from .input_media_video import InputMediaVideo -from .input_phone_contact import InputPhoneContact -from .media import ( - Audio, Contact, Document, GIF, Location, Photo, PhotoSize, - Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos +from .bots import ( + CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, + KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) -from .message import Message -from .message_entity import MessageEntity -from .messages import Messages -from .reply_markup import ( +from .bots import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove ) +from .input_media import ( + InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, + InputMediaDocument, InputMediaAnimation +) +from .messages_and_media import ( + Audio, Contact, Document, Animation, Location, Photo, PhotoSize, + Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos, + Message, Messages, MessageEntity +) 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/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 diff --git a/pyrogram/client/types/input_media/__init__.py b/pyrogram/client/types/input_media/__init__.py new file mode 100644 index 00000000..5f5be30d --- /dev/null +++ b/pyrogram/client/types/input_media/__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 .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 diff --git a/pyrogram/client/types/input_media/input_media.py b/pyrogram/client/types/input_media/input_media.py new file mode 100644 index 00000000..611d5865 --- /dev/null +++ b/pyrogram/client/types/input_media/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 diff --git a/pyrogram/client/types/input_media/input_media_animation.py b/pyrogram/client/types/input_media/input_media_animation.py new file mode 100644 index 00000000..12fe0e03 --- /dev/null +++ b/pyrogram/client/types/input_media/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 diff --git a/pyrogram/client/types/input_media/input_media_audio.py b/pyrogram/client/types/input_media/input_media_audio.py new file mode 100644 index 00000000..2c644107 --- /dev/null +++ b/pyrogram/client/types/input_media/input_media_audio.py @@ -0,0 +1,61 @@ +# 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``): + 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 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. + + duration (``int``, *optional*): + Duration of the audio in seconds + + performer (``int``, *optional*): + Performer of the audio + + title (``int``, *optional*): + Title of the audio + """ + + def __init__(self, + media: str, + caption: str = "", + parse_mode: str = "", + duration: int = 0, + performer: int = "", + title: str = ""): + super().__init__(media, caption, parse_mode) + + self.duration = duration + self.performer = performer + self.title = title diff --git a/pyrogram/client/types/input_media/input_media_document.py b/pyrogram/client/types/input_media/input_media_document.py new file mode 100644 index 00000000..f64da619 --- /dev/null +++ b/pyrogram/client/types/input_media/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) diff --git a/pyrogram/client/types/input_media_photo.py b/pyrogram/client/types/input_media/input_media_photo.py similarity index 93% rename from pyrogram/client/types/input_media_photo.py rename to pyrogram/client/types/input_media/input_media_photo.py index 336ee849..d58f75a6 100644 --- a/pyrogram/client/types/input_media_photo.py +++ b/pyrogram/client/types/input_media/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) diff --git a/pyrogram/client/types/input_media_video.py b/pyrogram/client/types/input_media/input_media_video.py similarity index 95% rename from pyrogram/client/types/input_media_video.py rename to pyrogram/client/types/input_media/input_media_video.py index eb6c003e..c1f2c9ac 100644 --- a/pyrogram/client/types/input_media_video.py +++ b/pyrogram/client/types/input_media/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 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 diff --git a/pyrogram/client/types/media/__init__.py b/pyrogram/client/types/messages_and_media/__init__.py similarity index 89% rename from pyrogram/client/types/media/__init__.py rename to pyrogram/client/types/messages_and_media/__init__.py index 5b09d832..3ab359ae 100644 --- a/pyrogram/client/types/media/__init__.py +++ b/pyrogram/client/types/messages_and_media/__init__.py @@ -16,11 +16,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +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 .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/gif.py b/pyrogram/client/types/messages_and_media/animation.py similarity index 82% rename from pyrogram/client/types/media/gif.py rename to pyrogram/client/types/messages_and_media/animation.py index 5172aae2..85d5a365 100644 --- a/pyrogram/client/types/media/gif.py +++ b/pyrogram/client/types/messages_and_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/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 92% rename from pyrogram/client/types/media/contact.py rename to pyrogram/client/types/messages_and_media/contact.py index a59e2047..a7be558e 100644 --- a/pyrogram/client/types/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 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 98% rename from pyrogram/client/types/message.py rename to pyrogram/client/types/messages_and_media/message.py index 51de2a6f..ca710566 100644 --- a/pyrogram/client/types/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 .reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup +from ..bots import InlineKeyboardMarkup, ReplyKeyboardMarkup class Message(Object): @@ -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 @@ -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. 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 75% rename from pyrogram/client/types/media/venue.py rename to pyrogram/client/types/messages_and_media/venue.py index 5d9e387f..3c5b2b05 100644 --- a/pyrogram/client/types/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 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 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 78% rename from pyrogram/client/types/chat_members.py rename to pyrogram/client/types/user_and_chats/chat_members.py index 658a3086..622f8abc 100644 --- a/pyrogram/client/types/chat_members.py +++ b/pyrogram/client/types/user_and_chats/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 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 91% rename from pyrogram/client/types/dialog.py rename to pyrogram/client/types/user_and_chats/dialog.py index 60ffb76c..fa5fb2b8 100644 --- a/pyrogram/client/types/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 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