├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── feature_request.md │ └── feature_request.yml └── workflows │ ├── codeql-analysis.yml │ └── python.yml ├── .gitignore ├── COPYING ├── COPYING.lesser ├── MANIFEST.in ├── Makefile ├── NOTICE ├── README.md ├── compiler ├── __init__.py ├── api │ ├── __init__.py │ ├── compiler.py │ ├── source │ │ ├── auth_key.tl │ │ ├── main_api.tl │ │ └── sys_msgs.tl │ └── template │ │ ├── combinator.txt │ │ └── type.txt └── errors │ ├── __init__.py │ ├── compiler.py │ ├── sort.py │ ├── source │ ├── 303_SEE_OTHER.tsv │ ├── 400_BAD_REQUEST.tsv │ ├── 401_UNAUTHORIZED.tsv │ ├── 403_FORBIDDEN.tsv │ ├── 406_NOT_ACCEPTABLE.tsv │ ├── 420_FLOOD.tsv │ ├── 500_INTERNAL_SERVER_ERROR.tsv │ └── 503_SERVICE_UNAVAILABLE.tsv │ └── template │ ├── class.txt │ └── sub_class.txt ├── dev-requirements.txt ├── pyrogram ├── __init__.py ├── client.py ├── connection │ ├── __init__.py │ ├── connection.py │ └── transport │ │ ├── __init__.py │ │ └── tcp │ │ ├── __init__.py │ │ ├── tcp.py │ │ ├── tcp_abridged.py │ │ ├── tcp_abridged_o.py │ │ ├── tcp_full.py │ │ ├── tcp_intermediate.py │ │ └── tcp_intermediate_o.py ├── crypto │ ├── __init__.py │ ├── aes.py │ ├── mtproto.py │ ├── prime.py │ └── rsa.py ├── dispatcher.py ├── emoji.py ├── enums │ ├── __init__.py │ ├── auto_name.py │ ├── chat_action.py │ ├── chat_event_action.py │ ├── chat_member_status.py │ ├── chat_members_filter.py │ ├── chat_type.py │ ├── message_entity_type.py │ ├── message_media_type.py │ ├── message_service_type.py │ ├── messages_filter.py │ ├── next_code_type.py │ ├── parse_mode.py │ ├── poll_type.py │ ├── sent_code_type.py │ └── user_status.py ├── errors │ ├── __init__.py │ └── rpc_error.py ├── file_id.py ├── filters.py ├── handlers │ ├── __init__.py │ ├── callback_query_handler.py │ ├── chat_join_request_handler.py │ ├── chat_member_updated_handler.py │ ├── chosen_inline_result_handler.py │ ├── deleted_messages_handler.py │ ├── disconnect_handler.py │ ├── edited_message_handler.py │ ├── handler.py │ ├── inline_query_handler.py │ ├── message_handler.py │ ├── poll_handler.py │ ├── raw_update_handler.py │ └── user_status_handler.py ├── methods │ ├── __init__.py │ ├── advanced │ │ ├── __init__.py │ │ ├── invoke.py │ │ ├── resolve_peer.py │ │ └── save_file.py │ ├── auth │ │ ├── __init__.py │ │ ├── accept_terms_of_service.py │ │ ├── check_password.py │ │ ├── connect.py │ │ ├── disconnect.py │ │ ├── get_password_hint.py │ │ ├── initialize.py │ │ ├── log_out.py │ │ ├── recover_password.py │ │ ├── resend_code.py │ │ ├── send_code.py │ │ ├── send_recovery_code.py │ │ ├── sign_in.py │ │ ├── sign_in_bot.py │ │ ├── sign_up.py │ │ └── terminate.py │ ├── bots │ │ ├── __init__.py │ │ ├── answer_callback_query.py │ │ ├── answer_inline_query.py │ │ ├── answer_web_app_query.py │ │ ├── delete_bot_commands.py │ │ ├── get_bot_commands.py │ │ ├── get_bot_default_privileges.py │ │ ├── get_chat_menu_button.py │ │ ├── get_game_high_scores.py │ │ ├── get_inline_bot_results.py │ │ ├── request_callback_answer.py │ │ ├── send_game.py │ │ ├── send_inline_bot_result.py │ │ ├── set_bot_commands.py │ │ ├── set_bot_default_privileges.py │ │ ├── set_chat_menu_button.py │ │ └── set_game_score.py │ ├── chats │ │ ├── __init__.py │ │ ├── add_chat_members.py │ │ ├── archive_chats.py │ │ ├── ban_chat_member.py │ │ ├── create_channel.py │ │ ├── create_group.py │ │ ├── create_group_call.py │ │ ├── create_supergroup.py │ │ ├── delete_channel.py │ │ ├── delete_chat_photo.py │ │ ├── delete_supergroup.py │ │ ├── delete_user_history.py │ │ ├── get_chat.py │ │ ├── get_chat_event_log.py │ │ ├── get_chat_member.py │ │ ├── get_chat_members.py │ │ ├── get_chat_members_count.py │ │ ├── get_chat_online_count.py │ │ ├── get_dialogs.py │ │ ├── get_dialogs_count.py │ │ ├── get_group_call_stream_channels.py │ │ ├── get_group_call_stream_rtmp_url.py │ │ ├── get_nearby_chats.py │ │ ├── get_send_as_chats.py │ │ ├── join_chat.py │ │ ├── leave_chat.py │ │ ├── mark_chat_unread.py │ │ ├── pin_chat_message.py │ │ ├── promote_chat_member.py │ │ ├── restrict_chat_member.py │ │ ├── set_administrator_title.py │ │ ├── set_chat_description.py │ │ ├── set_chat_permissions.py │ │ ├── set_chat_photo.py │ │ ├── set_chat_protected_content.py │ │ ├── set_chat_reactions.py │ │ ├── set_chat_title.py │ │ ├── set_chat_username.py │ │ ├── set_send_as_chat.py │ │ ├── set_slow_mode.py │ │ ├── unarchive_chats.py │ │ ├── unban_chat_member.py │ │ ├── unpin_all_chat_messages.py │ │ └── unpin_chat_message.py │ ├── contacts │ │ ├── __init__.py │ │ ├── add_contact.py │ │ ├── delete_contacts.py │ │ ├── get_contacts.py │ │ ├── get_contacts_count.py │ │ └── import_contacts.py │ ├── decorators │ │ ├── __init__.py │ │ ├── on_callback_query.py │ │ ├── on_chat_join_request.py │ │ ├── on_chat_member_updated.py │ │ ├── on_chosen_inline_result.py │ │ ├── on_deleted_messages.py │ │ ├── on_disconnect.py │ │ ├── on_edited_message.py │ │ ├── on_inline_query.py │ │ ├── on_message.py │ │ ├── on_poll.py │ │ ├── on_raw_update.py │ │ └── on_user_status.py │ ├── invite_links │ │ ├── __init__.py │ │ ├── approve_all_chat_join_requests.py │ │ ├── approve_chat_join_request.py │ │ ├── create_chat_invite_link.py │ │ ├── decline_all_chat_join_requests.py │ │ ├── decline_chat_join_request.py │ │ ├── delete_chat_admin_invite_links.py │ │ ├── delete_chat_invite_link.py │ │ ├── edit_chat_invite_link.py │ │ ├── export_chat_invite_link.py │ │ ├── get_chat_admin_invite_links.py │ │ ├── get_chat_admin_invite_links_count.py │ │ ├── get_chat_admins_with_invite_links.py │ │ ├── get_chat_invite_link.py │ │ ├── get_chat_invite_link_joiners.py │ │ ├── get_chat_invite_link_joiners_count.py │ │ ├── get_chat_join_requests.py │ │ └── revoke_chat_invite_link.py │ ├── messages │ │ ├── __init__.py │ │ ├── copy_media_group.py │ │ ├── copy_message.py │ │ ├── delete_messages.py │ │ ├── download_media.py │ │ ├── edit_inline_caption.py │ │ ├── edit_inline_media.py │ │ ├── edit_inline_reply_markup.py │ │ ├── edit_inline_text.py │ │ ├── edit_message_caption.py │ │ ├── edit_message_media.py │ │ ├── edit_message_reply_markup.py │ │ ├── edit_message_text.py │ │ ├── forward_messages.py │ │ ├── get_chat_history.py │ │ ├── get_chat_history_count.py │ │ ├── get_custom_emoji_stickers.py │ │ ├── get_discussion_message.py │ │ ├── get_discussion_replies.py │ │ ├── get_discussion_replies_count.py │ │ ├── get_media_group.py │ │ ├── get_messages.py │ │ ├── inline_session.py │ │ ├── read_chat_history.py │ │ ├── retract_vote.py │ │ ├── search_global.py │ │ ├── search_global_count.py │ │ ├── search_messages.py │ │ ├── search_messages_count.py │ │ ├── send_animation.py │ │ ├── send_audio.py │ │ ├── send_cached_media.py │ │ ├── send_chat_action.py │ │ ├── send_contact.py │ │ ├── send_dice.py │ │ ├── send_document.py │ │ ├── send_location.py │ │ ├── send_media_group.py │ │ ├── send_message.py │ │ ├── send_photo.py │ │ ├── send_poll.py │ │ ├── send_reaction.py │ │ ├── send_sticker.py │ │ ├── send_venue.py │ │ ├── send_video.py │ │ ├── send_video_note.py │ │ ├── send_voice.py │ │ ├── stop_poll.py │ │ ├── stream_media.py │ │ └── vote_poll.py │ ├── password │ │ ├── __init__.py │ │ ├── change_cloud_password.py │ │ ├── enable_cloud_password.py │ │ └── remove_cloud_password.py │ ├── users │ │ ├── __init__.py │ │ ├── block_user.py │ │ ├── delete_profile_photos.py │ │ ├── get_chat_photos.py │ │ ├── get_chat_photos_count.py │ │ ├── get_common_chats.py │ │ ├── get_default_emoji_statuses.py │ │ ├── get_me.py │ │ ├── get_users.py │ │ ├── set_emoji_status.py │ │ ├── set_profile_photo.py │ │ ├── set_username.py │ │ ├── unblock_user.py │ │ └── update_profile.py │ └── utilities │ │ ├── __init__.py │ │ ├── add_handler.py │ │ ├── compose.py │ │ ├── export_session_string.py │ │ ├── idle.py │ │ ├── remove_handler.py │ │ ├── restart.py │ │ ├── run.py │ │ ├── start.py │ │ ├── stop.py │ │ └── stop_transmission.py ├── mime_types.py ├── parser │ ├── __init__.py │ ├── html.py │ ├── markdown.py │ ├── parser.py │ └── utils.py ├── py.typed ├── raw │ ├── __init__.py │ └── core │ │ ├── __init__.py │ │ ├── future_salt.py │ │ ├── future_salts.py │ │ ├── gzip_packed.py │ │ ├── list.py │ │ ├── message.py │ │ ├── msg_container.py │ │ ├── primitives │ │ ├── __init__.py │ │ ├── bool.py │ │ ├── bytes.py │ │ ├── double.py │ │ ├── int.py │ │ ├── string.py │ │ └── vector.py │ │ └── tl_object.py ├── session │ ├── __init__.py │ ├── auth.py │ ├── internals │ │ ├── __init__.py │ │ ├── data_center.py │ │ ├── msg_factory.py │ │ ├── msg_id.py │ │ └── seq_no.py │ └── session.py ├── storage │ ├── __init__.py │ ├── file_storage.py │ ├── memory_storage.py │ ├── sqlite_storage.py │ └── storage.py ├── sync.py ├── types │ ├── __init__.py │ ├── authorization │ │ ├── __init__.py │ │ ├── sent_code.py │ │ └── terms_of_service.py │ ├── bots_and_keyboards │ │ ├── __init__.py │ │ ├── bot_command.py │ │ ├── bot_command_scope.py │ │ ├── bot_command_scope_all_chat_administrators.py │ │ ├── bot_command_scope_all_group_chats.py │ │ ├── bot_command_scope_all_private_chats.py │ │ ├── bot_command_scope_chat.py │ │ ├── bot_command_scope_chat_administrators.py │ │ ├── bot_command_scope_chat_member.py │ │ ├── bot_command_scope_default.py │ │ ├── callback_game.py │ │ ├── callback_query.py │ │ ├── force_reply.py │ │ ├── game_high_score.py │ │ ├── inline_keyboard_button.py │ │ ├── inline_keyboard_markup.py │ │ ├── keyboard_button.py │ │ ├── login_url.py │ │ ├── menu_button.py │ │ ├── menu_button_commands.py │ │ ├── menu_button_default.py │ │ ├── menu_button_web_app.py │ │ ├── reply_keyboard_markup.py │ │ ├── reply_keyboard_remove.py │ │ ├── sent_web_app_message.py │ │ └── web_app_info.py │ ├── inline_mode │ │ ├── __init__.py │ │ ├── chosen_inline_result.py │ │ ├── inline_query.py │ │ ├── inline_query_result.py │ │ ├── inline_query_result_animation.py │ │ ├── inline_query_result_article.py │ │ ├── inline_query_result_audio.py │ │ ├── inline_query_result_cached_animation.py │ │ ├── inline_query_result_cached_audio.py │ │ ├── inline_query_result_cached_document.py │ │ ├── inline_query_result_cached_photo.py │ │ ├── inline_query_result_cached_sticker.py │ │ ├── inline_query_result_cached_video.py │ │ ├── inline_query_result_cached_voice.py │ │ ├── inline_query_result_contact.py │ │ ├── inline_query_result_document.py │ │ ├── inline_query_result_location.py │ │ ├── inline_query_result_photo.py │ │ ├── inline_query_result_venue.py │ │ ├── inline_query_result_video.py │ │ └── inline_query_result_voice.py │ ├── input_media │ │ ├── __init__.py │ │ ├── input_media.py │ │ ├── input_media_animation.py │ │ ├── input_media_audio.py │ │ ├── input_media_document.py │ │ ├── input_media_photo.py │ │ ├── input_media_video.py │ │ └── input_phone_contact.py │ ├── input_message_content │ │ ├── __init__.py │ │ ├── input_message_content.py │ │ └── input_text_message_content.py │ ├── list.py │ ├── messages_and_media │ │ ├── __init__.py │ │ ├── animation.py │ │ ├── audio.py │ │ ├── contact.py │ │ ├── dice.py │ │ ├── document.py │ │ ├── game.py │ │ ├── giveaway.py │ │ ├── location.py │ │ ├── message.py │ │ ├── message_entity.py │ │ ├── message_reactions.py │ │ ├── photo.py │ │ ├── poll.py │ │ ├── poll_option.py │ │ ├── reaction.py │ │ ├── sticker.py │ │ ├── story.py │ │ ├── stripped_thumbnail.py │ │ ├── thumbnail.py │ │ ├── venue.py │ │ ├── video.py │ │ ├── video_note.py │ │ ├── voice.py │ │ ├── web_app_data.py │ │ └── web_page.py │ ├── object.py │ ├── update.py │ └── user_and_chats │ │ ├── __init__.py │ │ ├── chat.py │ │ ├── chat_admin_with_invite_links.py │ │ ├── chat_event.py │ │ ├── chat_event_filter.py │ │ ├── chat_invite_link.py │ │ ├── chat_join_request.py │ │ ├── chat_joiner.py │ │ ├── chat_member.py │ │ ├── chat_member_updated.py │ │ ├── chat_permissions.py │ │ ├── chat_photo.py │ │ ├── chat_preview.py │ │ ├── chat_privileges.py │ │ ├── chat_reactions.py │ │ ├── dialog.py │ │ ├── emoji_status.py │ │ ├── invite_link_importer.py │ │ ├── restriction.py │ │ ├── user.py │ │ ├── username.py │ │ ├── video_chat_ended.py │ │ ├── video_chat_members_invited.py │ │ ├── video_chat_scheduled.py │ │ └── video_chat_started.py └── utils.py ├── requirements.txt ├── setup.py ├── tests ├── __init__.py ├── filters │ ├── __init__.py │ └── test_command.py ├── parser │ ├── __init__.py │ └── test_html.py └── test_file_id.py └── tox.ini /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: delivrance 2 | liberapay: delivrance 3 | open_collective: pyrogram 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: Report issues affecting the framework or the documentation 3 | body: 4 | - type: checkboxes 5 | attributes: 6 | label: Checklist 7 | description: Invalid, incomplete or inadequate issue reports may not be taken into consideration 8 | options: 9 | - label: I am sure the error is coming from Pyrogram's code and not elsewhere 10 | required: true 11 | - label: I have searched in the issue tracker for similar bug reports, including closed ones 12 | required: true 13 | - label: I ran `pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip` and reproduced the issue using the latest development version 14 | required: true 15 | 16 | - type: textarea 17 | attributes: 18 | label: Description 19 | description: Provide a clear and concise description of the issue 20 | placeholder: Description... 21 | validations: 22 | required: true 23 | 24 | - type: textarea 25 | attributes: 26 | label: Steps to reproduce 27 | description: Explain precisely how to reproduce the issue 28 | placeholder: | 29 | 1. 30 | 2. 31 | 3. 32 | validations: 33 | required: true 34 | 35 | - type: textarea 36 | attributes: 37 | label: Code example 38 | description: Provide a [minimal, complete, consistently reproducible](https://stackoverflow.com/help/minimal-reproducible-example) and properly formatted example involving normal usages (if applicable) 39 | placeholder: | 40 | from pyrogram import Client 41 | ... 42 | render: python 43 | 44 | - type: textarea 45 | attributes: 46 | label: Logs 47 | description: Provide the complete traceback (if applicable) 48 | placeholder: | 49 | Traceback (most recent call last): 50 | File "main.py", line 1, in 51 | ... 52 | render: shell -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Ask Pyrogram related questions 4 | url: https://stackoverflow.com/questions/tagged/pyrogram 5 | about: This place is only for reporting issues about Pyrogram. You can ask questions at StackOverflow. 6 | - name: Join the Telegram channel 7 | url: https://t.me/pyrogram 8 | about: Join the official channel and stay tuned for news, updates and announcements. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Suggest ideas, new features or enhancements 3 | labels: [enhancement] 4 | body: 5 | - type: checkboxes 6 | attributes: 7 | label: Checklist 8 | options: 9 | - label: I believe the idea is awesome and would benefit the framework 10 | required: true 11 | - label: I have searched in the issue tracker for similar requests, including closed ones 12 | required: true 13 | 14 | - type: textarea 15 | attributes: 16 | label: Description 17 | description: Provide a detailed description of the request 18 | placeholder: Description... 19 | validations: 20 | required: true -------------------------------------------------------------------------------- /.github/workflows/python.yml: -------------------------------------------------------------------------------- 1 | name: Pyrogram - Mod 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest, macos-latest] 12 | python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Set up Python ${{ matrix.python-version }} 18 | uses: actions/setup-python@v2 19 | with: 20 | python-version: ${{ matrix.python-version }} 21 | 22 | - name: Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | pip install tox 26 | 27 | - name: Generate API 28 | run: | 29 | make venv 30 | make api 31 | 32 | - name: Run tests 33 | run: | 34 | tox 35 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | ## Include 2 | include README.md COPYING COPYING.lesser NOTICE requirements.txt 3 | recursive-include compiler *.py *.tl *.tsv *.txt 4 | recursive-include tests *.py 5 | 6 | ## Exclude 7 | prune pyrogram/errors/exceptions 8 | prune pyrogram/raw/functions 9 | prune pyrogram/raw/types 10 | prune pyrogram/raw/base 11 | exclude pyrogram/raw/all.py 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VENV := venv 2 | PYTHON := $(VENV)/bin/python 3 | HOST = $(shell ifconfig | grep "inet " | tail -1 | cut -d\ -f2) 4 | TAG = v$(shell grep -E '__version__ = ".*"' pyrogram/__init__.py | cut -d\" -f2) 5 | 6 | RM := rm -rf 7 | 8 | .PHONY: venv clean-build clean-api clean api build 9 | 10 | venv: 11 | $(RM) $(VENV) 12 | python3 -m venv $(VENV) 13 | $(PYTHON) -m pip install -U pip wheel setuptools 14 | $(PYTHON) -m pip install -U -r requirements.txt -r dev-requirements.txt 15 | @echo "Created venv with $$($(PYTHON) --version)" 16 | 17 | clean-build: 18 | $(RM) *.egg-info build dist 19 | 20 | clean-api: 21 | $(RM) pyrogram/errors/exceptions pyrogram/raw/all.py pyrogram/raw/base pyrogram/raw/functions pyrogram/raw/types 22 | 23 | clean: 24 | make clean-build 25 | make clean-api 26 | 27 | api: 28 | cd compiler/api && ../../$(PYTHON) compiler.py 29 | cd compiler/errors && ../../$(PYTHON) compiler.py 30 | 31 | build: 32 | make clean 33 | $(PYTHON) setup.py sdist 34 | $(PYTHON) setup.py bdist_wheel 35 | 36 | tag: 37 | git tag $(TAG) 38 | git push origin $(TAG) 39 | 40 | dtag: 41 | git tag -d $(TAG) 42 | git push origin -d $(TAG) -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Pyrogram - Telegram MTProto API Client Library for Python 2 | Copyright (C) 2017-present Dan 3 | 4 | This file is part of Pyrogram. 5 | 6 | Pyrogram is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published 8 | by the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | Pyrogram is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with Pyrogram. If not, see . -------------------------------------------------------------------------------- /compiler/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | -------------------------------------------------------------------------------- /compiler/api/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | -------------------------------------------------------------------------------- /compiler/api/template/combinator.txt: -------------------------------------------------------------------------------- 1 | {notice} 2 | 3 | from io import BytesIO 4 | 5 | from pyrogram.raw.core.primitives import Int, Long, Int128, Int256, Bool, Bytes, String, Double, Vector 6 | from pyrogram.raw.core import TLObject 7 | from pyrogram import raw 8 | from typing import List, Optional, Any 9 | 10 | {warning} 11 | 12 | 13 | class {name}(TLObject): # type: ignore 14 | """{docstring} 15 | """ 16 | 17 | __slots__: List[str] = [{slots}] 18 | 19 | ID = {id} 20 | QUALNAME = "{qualname}" 21 | 22 | def __init__(self{arguments}) -> None: 23 | {fields} 24 | 25 | @staticmethod 26 | def read(b: BytesIO, *args: Any) -> "{name}": 27 | {read_types} 28 | return {name}({return_arguments}) 29 | 30 | def write(self, *args) -> bytes: 31 | b = BytesIO() 32 | b.write(Int(self.ID, False)) 33 | 34 | {write_types} 35 | return b.getvalue() 36 | -------------------------------------------------------------------------------- /compiler/api/template/type.txt: -------------------------------------------------------------------------------- 1 | {notice} 2 | 3 | {warning} 4 | 5 | from typing import Union 6 | from pyrogram import raw 7 | from pyrogram.raw.core import TLObject 8 | 9 | {name} = Union[{types}] 10 | 11 | 12 | # noinspection PyRedeclaration 13 | class {name}: # type: ignore 14 | """{docstring} 15 | """ 16 | 17 | QUALNAME = "pyrogram.raw.base.{qualname}" 18 | 19 | def __init__(self): 20 | raise TypeError("Base types can only be used for type checking purposes: " 21 | "you tried to use a base type instance as argument, " 22 | "but you need to instantiate one of its constructors instead. " 23 | "More info: https://docs.pyrogram.org/telegram/base/{doc_name}") 24 | -------------------------------------------------------------------------------- /compiler/errors/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | -------------------------------------------------------------------------------- /compiler/errors/sort.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import csv 20 | from pathlib import Path 21 | 22 | for p in Path("source").glob("*.tsv"): 23 | with open(p) as f: 24 | reader = csv.reader(f, delimiter="\t") 25 | dct = {k: v for k, v in reader if k != "id"} 26 | keys = sorted(dct) 27 | 28 | with open(p, "w") as f: 29 | f.write("id\tmessage\n") 30 | 31 | for i, item in enumerate(keys, start=1): 32 | f.write(f"{item}\t{dct[item]}") 33 | 34 | if i != len(keys): 35 | f.write("\n") 36 | -------------------------------------------------------------------------------- /compiler/errors/source/303_SEE_OTHER.tsv: -------------------------------------------------------------------------------- 1 | id message 2 | FILE_MIGRATE_X The file to be accessed is currently stored in DC{value} 3 | NETWORK_MIGRATE_X The source IP address is associated with DC{value} (for registration) 4 | PHONE_MIGRATE_X The phone number a user is trying to use for authorization is associated with DC{value} 5 | STATS_MIGRATE_X The statistics of the group/channel are stored in DC{value} 6 | USER_MIGRATE_X The user whose identity is being used to execute queries is associated with DC{value} (for registration) -------------------------------------------------------------------------------- /compiler/errors/source/401_UNAUTHORIZED.tsv: -------------------------------------------------------------------------------- 1 | id message 2 | ACTIVE_USER_REQUIRED The method is only available to already activated users 3 | AUTH_KEY_INVALID The key is invalid 4 | AUTH_KEY_PERM_EMPTY The method is unavailable for temporary authorization key, not bound to permanent 5 | AUTH_KEY_UNREGISTERED The key is not registered in the system. Delete your session file and login again 6 | SESSION_EXPIRED The authorization has expired 7 | SESSION_PASSWORD_NEEDED The two-step verification is enabled and a password is required 8 | SESSION_REVOKED The authorization has been invalidated, because of the user terminating all sessions 9 | USER_DEACTIVATED The user has been deleted/deactivated 10 | USER_DEACTIVATED_BAN The user has been deleted/deactivated -------------------------------------------------------------------------------- /compiler/errors/source/406_NOT_ACCEPTABLE.tsv: -------------------------------------------------------------------------------- 1 | id message 2 | AUTH_KEY_DUPLICATED The same authorization key (session file) was used in more than one place simultaneously. You must delete your session file and log in again with your phone number or bot token 3 | CHANNEL_PRIVATE The channel/supergroup is not accessible 4 | FILEREF_UPGRADE_NEEDED The file reference has expired and you must use a refreshed one by obtaining the original media message 5 | FRESH_CHANGE_ADMINS_FORBIDDEN You were just elected admin, you can't add or modify other admins yet 6 | FRESH_CHANGE_PHONE_FORBIDDEN You can't change your phone number because your session was logged-in recently 7 | FRESH_RESET_AUTHORISATION_FORBIDDEN You can't terminate other authorized sessions because the current was logged-in recently 8 | PHONE_NUMBER_INVALID The phone number is invalid 9 | PHONE_PASSWORD_FLOOD You have tried to log-in too many times 10 | STICKERSET_INVALID The sticker set is invalid 11 | STICKERSET_OWNER_ANONYMOUS This sticker set can't be used as the group's sticker set because it was created by one of its anonymous admins 12 | USERPIC_UPLOAD_REQUIRED You must have a profile picture to publish your geolocation 13 | USER_RESTRICTED You are limited/restricted. You can't perform this action -------------------------------------------------------------------------------- /compiler/errors/source/420_FLOOD.tsv: -------------------------------------------------------------------------------- 1 | id message 2 | 2FA_CONFIRM_WAIT_X A wait of {value} seconds is required because this account is active and protected by a 2FA password 3 | FLOOD_TEST_PHONE_WAIT_X A wait of {value} seconds is required in the test servers 4 | FLOOD_WAIT_X A wait of {value} seconds is required 5 | SLOWMODE_WAIT_X A wait of {value} seconds is required to send messages in this chat. 6 | TAKEOUT_INIT_DELAY_X You have to confirm the data export request using one of your mobile devices or wait {value} seconds -------------------------------------------------------------------------------- /compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv: -------------------------------------------------------------------------------- 1 | id message 2 | ApiCallError Telegram is having internal problems. Please try again later. 3 | Timeout Telegram is having internal problems. Please try again later. 4 | Timedout Telegram is having internal problems. Please try again later. 5 | -------------------------------------------------------------------------------- /compiler/errors/template/class.txt: -------------------------------------------------------------------------------- 1 | {notice} 2 | 3 | from ..rpc_error import RPCError 4 | 5 | 6 | class {super_class}(RPCError): 7 | {docstring} 8 | CODE = {code} 9 | """``int``: RPC Error Code""" 10 | NAME = __doc__ 11 | 12 | 13 | {sub_classes} -------------------------------------------------------------------------------- /compiler/errors/template/sub_class.txt: -------------------------------------------------------------------------------- 1 | class {sub_class}({super_class}): 2 | {docstring} 3 | ID = {id} 4 | """``str``: RPC Error ID""" 5 | MESSAGE = __doc__ 6 | 7 | 8 | -------------------------------------------------------------------------------- /dev-requirements.txt: -------------------------------------------------------------------------------- 1 | -r requirements.txt 2 | 3 | pytest 4 | pytest-asyncio 5 | pytest-cov 6 | twine -------------------------------------------------------------------------------- /pyrogram/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | __version__ = "3.0.2" 20 | __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" 21 | __copyright__ = "Copyright (C) 2017-present Dan " 22 | 23 | from concurrent.futures.thread import ThreadPoolExecutor 24 | 25 | 26 | class StopTransmission(Exception): 27 | pass 28 | 29 | 30 | class StopPropagation(StopAsyncIteration): 31 | pass 32 | 33 | 34 | class ContinuePropagation(StopAsyncIteration): 35 | pass 36 | 37 | 38 | from . import raw, types, filters, handlers, emoji, enums 39 | from .client import Client 40 | from .sync import idle, compose 41 | 42 | crypto_executor = ThreadPoolExecutor(1, thread_name_prefix="CryptoWorker") 43 | -------------------------------------------------------------------------------- /pyrogram/connection/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .connection import Connection 20 | -------------------------------------------------------------------------------- /pyrogram/connection/transport/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .tcp import * 20 | -------------------------------------------------------------------------------- /pyrogram/connection/transport/tcp/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .tcp import TCP 20 | from .tcp_abridged import TCPAbridged 21 | from .tcp_abridged_o import TCPAbridgedO 22 | from .tcp_full import TCPFull 23 | from .tcp_intermediate import TCPIntermediate 24 | from .tcp_intermediate_o import TCPIntermediateO 25 | -------------------------------------------------------------------------------- /pyrogram/connection/transport/tcp/tcp_abridged.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import logging 20 | from typing import Optional 21 | 22 | from .tcp import TCP 23 | 24 | log = logging.getLogger(__name__) 25 | 26 | 27 | class TCPAbridged(TCP): 28 | def __init__(self, ipv6: bool, proxy: dict): 29 | super().__init__(ipv6, proxy) 30 | 31 | async def connect(self, address: tuple): 32 | await super().connect(address) 33 | await super().send(b"\xef") 34 | 35 | async def send(self, data: bytes, *args): 36 | length = len(data) // 4 37 | 38 | await super().send( 39 | (bytes([length]) 40 | if length <= 126 41 | else b"\x7f" + length.to_bytes(3, "little")) 42 | + data 43 | ) 44 | 45 | async def recv(self, length: int = 0) -> Optional[bytes]: 46 | length = await super().recv(1) 47 | 48 | if length is None: 49 | return None 50 | 51 | if length == b"\x7f": 52 | length = await super().recv(3) 53 | 54 | if length is None: 55 | return None 56 | 57 | return await super().recv(int.from_bytes(length, "little") * 4) 58 | -------------------------------------------------------------------------------- /pyrogram/connection/transport/tcp/tcp_intermediate.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import logging 20 | from struct import pack, unpack 21 | from typing import Optional 22 | 23 | from .tcp import TCP 24 | 25 | log = logging.getLogger(__name__) 26 | 27 | 28 | class TCPIntermediate(TCP): 29 | def __init__(self, ipv6: bool, proxy: dict): 30 | super().__init__(ipv6, proxy) 31 | 32 | async def connect(self, address: tuple): 33 | await super().connect(address) 34 | await super().send(b"\xee" * 4) 35 | 36 | async def send(self, data: bytes, *args): 37 | await super().send(pack(" Optional[bytes]: 40 | length = await super().recv(4) 41 | 42 | if length is None: 43 | return None 44 | 45 | return await super().recv(unpack(" 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | -------------------------------------------------------------------------------- /pyrogram/enums/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .chat_action import ChatAction 20 | from .chat_event_action import ChatEventAction 21 | from .chat_member_status import ChatMemberStatus 22 | from .chat_members_filter import ChatMembersFilter 23 | from .chat_type import ChatType 24 | from .message_entity_type import MessageEntityType 25 | from .message_media_type import MessageMediaType 26 | from .message_service_type import MessageServiceType 27 | from .messages_filter import MessagesFilter 28 | from .next_code_type import NextCodeType 29 | from .parse_mode import ParseMode 30 | from .poll_type import PollType 31 | from .sent_code_type import SentCodeType 32 | from .user_status import UserStatus 33 | 34 | __all__ = [ 35 | 'ChatAction', 36 | 'ChatEventAction', 37 | 'ChatMemberStatus', 38 | 'ChatMembersFilter', 39 | 'ChatType', 40 | 'MessageEntityType', 41 | 'MessageMediaType', 42 | 'MessageServiceType', 43 | 'MessagesFilter', 44 | 'NextCodeType', 45 | 'ParseMode', 46 | 'PollType', 47 | 'SentCodeType', 48 | 'UserStatus' 49 | ] 50 | -------------------------------------------------------------------------------- /pyrogram/enums/auto_name.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from enum import Enum 20 | 21 | 22 | class AutoName(Enum): 23 | def _generate_next_value_(self, *args): 24 | return self.lower() 25 | 26 | def __repr__(self): 27 | return f"pyrogram.enums.{self}" 28 | -------------------------------------------------------------------------------- /pyrogram/enums/chat_member_status.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from enum import auto 20 | 21 | from .auto_name import AutoName 22 | 23 | 24 | class ChatMemberStatus(AutoName): 25 | """Chat member status enumeration used in :obj:`~pyrogram.types.ChatMember`.""" 26 | 27 | OWNER = auto() 28 | "Chat owner" 29 | 30 | ADMINISTRATOR = auto() 31 | "Chat administrator" 32 | 33 | MEMBER = auto() 34 | "Chat member" 35 | 36 | RESTRICTED = auto() 37 | "Restricted chat member" 38 | 39 | LEFT = auto() 40 | "Left chat member" 41 | 42 | BANNED = auto() 43 | "Banned chat member" 44 | -------------------------------------------------------------------------------- /pyrogram/enums/chat_members_filter.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | from .auto_name import AutoName 21 | 22 | 23 | class ChatMembersFilter(AutoName): 24 | """Chat members filter enumeration used in :meth:`~pyrogram.Client.get_chat_members`""" 25 | 26 | SEARCH = raw.types.ChannelParticipantsSearch 27 | "Search for members" 28 | 29 | BANNED = raw.types.ChannelParticipantsKicked 30 | "Banned members" 31 | 32 | RESTRICTED = raw.types.ChannelParticipantsBanned 33 | "Restricted members" 34 | 35 | BOTS = raw.types.ChannelParticipantsBots 36 | "Bots" 37 | 38 | RECENT = raw.types.ChannelParticipantsRecent 39 | "Recently active members" 40 | 41 | ADMINISTRATORS = raw.types.ChannelParticipantsAdmins 42 | "Administrators" 43 | 44 | DELETED = raw.types.ChannelParticipantsBanned 45 | "Deleted accounts" 46 | -------------------------------------------------------------------------------- /pyrogram/enums/chat_type.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from enum import auto 20 | 21 | from .auto_name import AutoName 22 | 23 | 24 | class ChatType(AutoName): 25 | """Chat type enumeration used in :obj:`~pyrogram.types.Chat`.""" 26 | 27 | PRIVATE = auto() 28 | "Chat is a private chat with a user" 29 | 30 | BOT = auto() 31 | "Chat is a private chat with a bot" 32 | 33 | GROUP = auto() 34 | "Chat is a basic group" 35 | 36 | SUPERGROUP = auto() 37 | "Chat is a supergroup" 38 | 39 | CHANNEL = auto() 40 | "Chat is a channel" 41 | -------------------------------------------------------------------------------- /pyrogram/enums/message_media_type.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from enum import auto 20 | 21 | from .auto_name import AutoName 22 | 23 | 24 | class MessageMediaType(AutoName): 25 | """Message media type enumeration used in :obj:`~pyrogram.types.Message`.""" 26 | 27 | AUDIO = auto() 28 | "Audio media" 29 | 30 | DOCUMENT = auto() 31 | "Document media" 32 | 33 | PHOTO = auto() 34 | "Photo media" 35 | 36 | STICKER = auto() 37 | "Sticker media" 38 | 39 | VIDEO = auto() 40 | "Video media" 41 | 42 | ANIMATION = auto() 43 | "Animation media" 44 | 45 | VOICE = auto() 46 | "Voice media" 47 | 48 | VIDEO_NOTE = auto() 49 | "Video note media" 50 | 51 | CONTACT = auto() 52 | "Contact media" 53 | 54 | LOCATION = auto() 55 | "Location media" 56 | 57 | VENUE = auto() 58 | "Venue media" 59 | 60 | POLL = auto() 61 | "Poll media" 62 | 63 | WEB_PAGE = auto() 64 | "Web page media" 65 | 66 | DICE = auto() 67 | "Dice media" 68 | 69 | GAME = auto() 70 | "Game media" 71 | -------------------------------------------------------------------------------- /pyrogram/enums/next_code_type.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | from .auto_name import AutoName 21 | 22 | 23 | class NextCodeType(AutoName): 24 | """Next code type enumeration used in :obj:`~pyrogram.types.SentCode`.""" 25 | 26 | CALL = raw.types.auth.CodeTypeCall 27 | "The code will be sent via a phone call. A synthesized voice will tell the user which verification code to input." 28 | 29 | FLASH_CALL = raw.types.auth.CodeTypeFlashCall 30 | "The code will be sent via a flash phone call, that will be closed immediately." 31 | 32 | MISSED_CALL = raw.types.auth.CodeTypeMissedCall 33 | "Missed call." 34 | 35 | SMS = raw.types.auth.CodeTypeSms 36 | "The code was sent via SMS." 37 | 38 | FRAGMENT_SMS = raw.types.auth.CodeTypeFragmentSms 39 | "The code was sent via Fragment SMS." 40 | -------------------------------------------------------------------------------- /pyrogram/enums/parse_mode.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from enum import auto 20 | 21 | from .auto_name import AutoName 22 | 23 | 24 | class ParseMode(AutoName): 25 | """Parse mode enumeration used in various places to set a specific parse mode""" 26 | 27 | DEFAULT = auto() 28 | "Default mode. Markdown and HTML combined" 29 | 30 | MARKDOWN = auto() 31 | "Markdown only mode" 32 | 33 | HTML = auto() 34 | "HTML only mode" 35 | 36 | DISABLED = auto() 37 | "Disabled mode" 38 | -------------------------------------------------------------------------------- /pyrogram/enums/poll_type.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from enum import auto 20 | 21 | from .auto_name import AutoName 22 | 23 | 24 | class PollType(AutoName): 25 | """Poll type enumeration used in :obj:`~pyrogram.types.Poll`.""" 26 | 27 | QUIZ = auto() 28 | "Quiz poll" 29 | 30 | REGULAR = auto() 31 | "Regular poll" 32 | -------------------------------------------------------------------------------- /pyrogram/enums/sent_code_type.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | from .auto_name import AutoName 21 | 22 | 23 | class SentCodeType(AutoName): 24 | """Sent code type enumeration used in :obj:`~pyrogram.types.SentCode`.""" 25 | 26 | APP = raw.types.auth.SentCodeTypeApp 27 | "The code was sent through the telegram app." 28 | 29 | CALL = raw.types.auth.SentCodeTypeCall 30 | "The code will be sent via a phone call. A synthesized voice will tell the user which verification code to input." 31 | 32 | FLASH_CALL = raw.types.auth.SentCodeTypeFlashCall 33 | "The code will be sent via a flash phone call, that will be closed immediately." 34 | 35 | MISSED_CALL = raw.types.auth.SentCodeTypeMissedCall 36 | "Missed call." 37 | 38 | SMS = raw.types.auth.SentCodeTypeSms 39 | "The code was sent via SMS." 40 | 41 | FRAGMENT_SMS = raw.types.auth.SentCodeTypeFragmentSms 42 | "The code was sent via Fragment SMS." 43 | 44 | EMAIL_CODE = raw.types.auth.SentCodeTypeEmailCode 45 | "The code was sent via email." 46 | -------------------------------------------------------------------------------- /pyrogram/enums/user_status.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from enum import auto 20 | 21 | from .auto_name import AutoName 22 | 23 | 24 | class UserStatus(AutoName): 25 | """User status enumeration used in :obj:`~pyrogram.types.User`.""" 26 | 27 | ONLINE = auto() 28 | """User is online""" 29 | 30 | OFFLINE = auto() 31 | """User is offline""" 32 | 33 | RECENTLY = auto() 34 | """User was seen recently""" 35 | 36 | LAST_WEEK = auto() 37 | """User was seen last week""" 38 | 39 | LAST_MONTH = auto() 40 | """User was seen last month""" 41 | 42 | LONG_AGO = auto() 43 | """User was seen long ago""" 44 | -------------------------------------------------------------------------------- /pyrogram/handlers/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .callback_query_handler import CallbackQueryHandler 20 | from .chat_join_request_handler import ChatJoinRequestHandler 21 | from .chat_member_updated_handler import ChatMemberUpdatedHandler 22 | from .chosen_inline_result_handler import ChosenInlineResultHandler 23 | from .deleted_messages_handler import DeletedMessagesHandler 24 | from .disconnect_handler import DisconnectHandler 25 | from .edited_message_handler import EditedMessageHandler 26 | from .inline_query_handler import InlineQueryHandler 27 | from .message_handler import MessageHandler 28 | from .poll_handler import PollHandler 29 | from .raw_update_handler import RawUpdateHandler 30 | from .user_status_handler import UserStatusHandler 31 | -------------------------------------------------------------------------------- /pyrogram/handlers/disconnect_handler.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Callable 20 | 21 | from .handler import Handler 22 | 23 | 24 | class DisconnectHandler(Handler): 25 | """The Disconnect handler class. Used to handle disconnections. It is intended to be used with 26 | :meth:`~pyrogram.Client.add_handler` 27 | 28 | For a nicer way to register this handler, have a look at the 29 | :meth:`~pyrogram.Client.on_disconnect` decorator. 30 | 31 | Parameters: 32 | callback (``Callable``): 33 | Pass a function that will be called when a disconnection occurs. It takes *(client)* 34 | as positional argument (look at the section below for a detailed description). 35 | 36 | Other parameters: 37 | client (:obj:`~pyrogram.Client`): 38 | The Client itself. Useful, for example, when you want to change the proxy before a new connection 39 | is established. 40 | """ 41 | 42 | def __init__(self, callback: Callable): 43 | super().__init__(callback) 44 | -------------------------------------------------------------------------------- /pyrogram/handlers/handler.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import inspect 20 | from typing import Callable 21 | 22 | import pyrogram 23 | from pyrogram.filters import Filter 24 | from pyrogram.types import Update 25 | 26 | 27 | class Handler: 28 | def __init__(self, callback: Callable, filters: Filter = None): 29 | self.callback = callback 30 | self.filters = filters 31 | 32 | async def check(self, client: "pyrogram.Client", update: Update): 33 | if callable(self.filters): 34 | if inspect.iscoroutinefunction(self.filters.__call__): 35 | return await self.filters(client, update) 36 | else: 37 | return await client.loop.run_in_executor( 38 | client.executor, 39 | self.filters, 40 | client, update 41 | ) 42 | 43 | return True 44 | -------------------------------------------------------------------------------- /pyrogram/handlers/message_handler.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Callable 20 | 21 | from .handler import Handler 22 | 23 | 24 | class MessageHandler(Handler): 25 | """The Message handler class. Used to handle new messages. 26 | It is intended to be used with :meth:`~pyrogram.Client.add_handler` 27 | 28 | For a nicer way to register this handler, have a look at the 29 | :meth:`~pyrogram.Client.on_message` decorator. 30 | 31 | Parameters: 32 | callback (``Callable``): 33 | Pass a function that will be called when a new Message arrives. It takes *(client, message)* 34 | as positional arguments (look at the section below for a detailed description). 35 | 36 | filters (:obj:`Filters`): 37 | Pass one or more filters to allow only a subset of messages to be passed 38 | in your callback function. 39 | 40 | Other parameters: 41 | client (:obj:`~pyrogram.Client`): 42 | The Client itself, useful when you want to call other API methods inside the message handler. 43 | 44 | message (:obj:`~pyrogram.types.Message`): 45 | The received message. 46 | """ 47 | 48 | def __init__(self, callback: Callable, filters=None): 49 | super().__init__(callback, filters) 50 | -------------------------------------------------------------------------------- /pyrogram/handlers/poll_handler.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Callable 20 | 21 | from .handler import Handler 22 | 23 | 24 | class PollHandler(Handler): 25 | """The Poll handler class. Used to handle polls updates. 26 | 27 | It is intended to be used with :meth:`~pyrogram.Client.add_handler` 28 | 29 | For a nicer way to register this handler, have a look at the 30 | :meth:`~pyrogram.Client.on_poll` decorator. 31 | 32 | Parameters: 33 | callback (``Callable``): 34 | Pass a function that will be called when a new poll update arrives. It takes *(client, poll)* 35 | as positional arguments (look at the section below for a detailed description). 36 | 37 | filters (:obj:`Filters`): 38 | Pass one or more filters to allow only a subset of polls to be passed 39 | in your callback function. 40 | 41 | Other parameters: 42 | client (:obj:`~pyrogram.Client`): 43 | The Client itself, useful when you want to call other API methods inside the poll handler. 44 | 45 | poll (:obj:`~pyrogram.types.Poll`): 46 | The received poll. 47 | """ 48 | 49 | def __init__(self, callback: Callable, filters=None): 50 | super().__init__(callback, filters) 51 | -------------------------------------------------------------------------------- /pyrogram/methods/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .advanced import Advanced 20 | from .auth import Auth 21 | from .bots import Bots 22 | from .chats import Chats 23 | from .contacts import Contacts 24 | from .decorators import Decorators 25 | from .invite_links import InviteLinks 26 | from .messages import Messages 27 | from .password import Password 28 | from .users import Users 29 | from .utilities import Utilities 30 | 31 | 32 | class Methods( 33 | Advanced, 34 | Auth, 35 | Bots, 36 | Contacts, 37 | Password, 38 | Chats, 39 | Users, 40 | Messages, 41 | Decorators, 42 | Utilities, 43 | InviteLinks, 44 | ): 45 | pass 46 | -------------------------------------------------------------------------------- /pyrogram/methods/advanced/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .invoke import Invoke 20 | from .resolve_peer import ResolvePeer 21 | from .save_file import SaveFile 22 | 23 | 24 | class Advanced( 25 | Invoke, 26 | ResolvePeer, 27 | SaveFile 28 | ): 29 | pass 30 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .accept_terms_of_service import AcceptTermsOfService 20 | from .check_password import CheckPassword 21 | from .connect import Connect 22 | from .disconnect import Disconnect 23 | from .get_password_hint import GetPasswordHint 24 | from .initialize import Initialize 25 | from .log_out import LogOut 26 | from .recover_password import RecoverPassword 27 | from .resend_code import ResendCode 28 | from .send_code import SendCode 29 | from .send_recovery_code import SendRecoveryCode 30 | from .sign_in import SignIn 31 | from .sign_in_bot import SignInBot 32 | from .sign_up import SignUp 33 | from .terminate import Terminate 34 | 35 | 36 | class Auth( 37 | AcceptTermsOfService, 38 | CheckPassword, 39 | Connect, 40 | Disconnect, 41 | GetPasswordHint, 42 | Initialize, 43 | LogOut, 44 | RecoverPassword, 45 | ResendCode, 46 | SendCode, 47 | SendRecoveryCode, 48 | SignIn, 49 | SignInBot, 50 | SignUp, 51 | Terminate 52 | ): 53 | pass 54 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/accept_terms_of_service.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | 22 | 23 | class AcceptTermsOfService: 24 | async def accept_terms_of_service( 25 | self: "pyrogram.Client", 26 | terms_of_service_id: str 27 | ) -> bool: 28 | """Accept the given terms of service. 29 | 30 | .. include:: /_includes/usable-by/users.rst 31 | 32 | Parameters: 33 | terms_of_service_id (``str``): 34 | The terms of service identifier. 35 | """ 36 | r = await self.invoke( 37 | raw.functions.help.AcceptTermsOfService( 38 | id=raw.types.DataJSON( 39 | data=terms_of_service_id 40 | ) 41 | ) 42 | ) 43 | 44 | return bool(r) 45 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/connect.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram.session import Session 21 | 22 | 23 | class Connect: 24 | async def connect( 25 | self: "pyrogram.Client", 26 | ) -> bool: 27 | """ 28 | Connect the client to Telegram servers. 29 | 30 | Returns: 31 | ``bool``: On success, in case the passed-in session is authorized, True is returned. Otherwise, in case 32 | the session needs to be authorized, False is returned. 33 | 34 | Raises: 35 | ConnectionError: In case you try to connect an already connected client. 36 | """ 37 | if self.is_connected: 38 | raise ConnectionError("Client is already connected") 39 | 40 | await self.load_session() 41 | 42 | self.session = Session( 43 | self, await self.storage.dc_id(), 44 | await self.storage.auth_key(), await self.storage.test_mode() 45 | ) 46 | 47 | await self.session.start() 48 | 49 | self.is_connected = True 50 | 51 | return bool(await self.storage.user_id()) 52 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/disconnect.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | 21 | 22 | class Disconnect: 23 | async def disconnect( 24 | self: "pyrogram.Client", 25 | ): 26 | """Disconnect the client from Telegram servers. 27 | 28 | Raises: 29 | ConnectionError: In case you try to disconnect an already disconnected client or in case you try to 30 | disconnect a client that needs to be terminated first. 31 | """ 32 | if not self.is_connected: 33 | raise ConnectionError("Client is already disconnected") 34 | 35 | if self.is_initialized: 36 | raise ConnectionError("Can't disconnect an initialized client") 37 | 38 | await self.session.stop() 39 | await self.storage.close() 40 | self.is_connected = False 41 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/get_password_hint.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import logging 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | log = logging.getLogger(__name__) 25 | 26 | 27 | class GetPasswordHint: 28 | async def get_password_hint( 29 | self: "pyrogram.Client", 30 | ) -> str: 31 | """Get your Two-Step Verification password hint. 32 | 33 | .. include:: /_includes/usable-by/users.rst 34 | 35 | Returns: 36 | ``str``: On success, the password hint as string is returned. 37 | """ 38 | return (await self.invoke(raw.functions.account.GetPassword())).hint 39 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/initialize.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import asyncio 20 | import logging 21 | 22 | import pyrogram 23 | 24 | log = logging.getLogger(__name__) 25 | 26 | 27 | class Initialize: 28 | async def initialize( 29 | self: "pyrogram.Client", 30 | ): 31 | """Initialize the client by starting up workers. 32 | 33 | This method will start updates and download workers. 34 | It will also load plugins and start the internal dispatcher. 35 | 36 | Raises: 37 | ConnectionError: In case you try to initialize a disconnected client or in case you try to initialize an 38 | already initialized client. 39 | """ 40 | if not self.is_connected: 41 | raise ConnectionError("Can't initialize a disconnected client") 42 | 43 | if self.is_initialized: 44 | raise ConnectionError("Client is already initialized") 45 | 46 | self.load_plugins() 47 | 48 | await self.dispatcher.start() 49 | 50 | self.updates_watchdog_task = asyncio.create_task(self.updates_watchdog()) 51 | 52 | self.is_initialized = True 53 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/log_out.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import logging 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | log = logging.getLogger(__name__) 25 | 26 | 27 | class LogOut: 28 | async def log_out( 29 | self: "pyrogram.Client", 30 | ): 31 | """Log out from Telegram and delete the *\\*.session* file. 32 | 33 | When you log out, the current client is stopped and the storage session deleted. 34 | No more API calls can be made until you start the client and re-authorize again. 35 | 36 | .. include:: /_includes/usable-by/users-bots.rst 37 | 38 | Returns: 39 | ``bool``: On success, True is returned. 40 | 41 | Example: 42 | .. code-block:: python 43 | 44 | # Log out. 45 | app.log_out() 46 | """ 47 | await self.invoke(raw.functions.auth.LogOut()) 48 | await self.stop() 49 | await self.storage.delete() 50 | 51 | return True 52 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/recover_password.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import logging 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | from pyrogram import types 24 | 25 | log = logging.getLogger(__name__) 26 | 27 | 28 | class RecoverPassword: 29 | async def recover_password( 30 | self: "pyrogram.Client", 31 | recovery_code: str 32 | ) -> "types.User": 33 | """Recover your password with a recovery code and log in. 34 | 35 | .. include:: /_includes/usable-by/users.rst 36 | 37 | Parameters: 38 | recovery_code (``str``): 39 | The recovery code sent via email. 40 | 41 | Returns: 42 | :obj:`~pyrogram.types.User`: On success, the authorized user is returned and the Two-Step Verification 43 | password reset. 44 | 45 | Raises: 46 | BadRequest: In case the recovery code is invalid. 47 | """ 48 | r = await self.invoke( 49 | raw.functions.auth.RecoverPassword( 50 | code=recovery_code 51 | ) 52 | ) 53 | 54 | await self.storage.user_id(r.user.id) 55 | await self.storage.is_bot(False) 56 | 57 | return types.User._parse(self, r.user) 58 | -------------------------------------------------------------------------------- /pyrogram/methods/auth/send_recovery_code.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import logging 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | log = logging.getLogger(__name__) 25 | 26 | 27 | class SendRecoveryCode: 28 | async def send_recovery_code( 29 | self: "pyrogram.Client", 30 | ) -> str: 31 | """Send a code to your email to recover your password. 32 | 33 | .. include:: /_includes/usable-by/users.rst 34 | 35 | Returns: 36 | ``str``: On success, the hidden email pattern is returned and a recovery code is sent to that email. 37 | 38 | Raises: 39 | BadRequest: In case no recovery email was set up. 40 | """ 41 | return (await self.invoke( 42 | raw.functions.auth.RequestPasswordRecovery() 43 | )).email_pattern 44 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/create_channel.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | import pyrogram 19 | from pyrogram import raw 20 | from pyrogram import types 21 | 22 | 23 | class CreateChannel: 24 | async def create_channel( 25 | self: "pyrogram.Client", 26 | title: str, 27 | description: str = "" 28 | ) -> "types.Chat": 29 | """Create a new broadcast channel. 30 | 31 | .. include:: /_includes/usable-by/users.rst 32 | 33 | Parameters: 34 | title (``str``): 35 | The channel title. 36 | 37 | description (``str``, *optional*): 38 | The channel description. 39 | 40 | Returns: 41 | :obj:`~pyrogram.types.Chat`: On success, a chat object is returned. 42 | 43 | Example: 44 | .. code-block:: python 45 | 46 | await app.create_channel("Channel Title", "Channel Description") 47 | """ 48 | r = await self.invoke( 49 | raw.functions.channels.CreateChannel( 50 | title=title, 51 | about=description, 52 | broadcast=True 53 | ) 54 | ) 55 | 56 | return types.Chat._parse_chat(self, r.chats[0]) 57 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/create_group_call.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import random 20 | from typing import Optional 21 | from typing import Union 22 | 23 | import pyrogram 24 | from pyrogram import raw 25 | 26 | 27 | class CreateGroupCall: 28 | async def create_group_call( 29 | self: "pyrogram.Client", 30 | chat_id: Union[int, str], 31 | rtmp_stream: Optional[bool] = False, 32 | title: Optional[Union[str, int]] = None, 33 | schedule_date: Optional[int] = None 34 | ): 35 | return await self.invoke( 36 | raw.functions.phone.CreateGroupCall( 37 | peer=await self.resolve_peer(chat_id), 38 | random_id=random.randint(0, 2147483647), 39 | rtmp_stream=rtmp_stream, 40 | title=title, 41 | schedule_date=schedule_date, 42 | ) 43 | ) 44 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/delete_channel.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class DeleteChannel: 26 | async def delete_channel( 27 | self: "pyrogram.Client", 28 | chat_id: Union[int, str] 29 | ) -> bool: 30 | """Delete a channel. 31 | 32 | .. include:: /_includes/usable-by/users.rst 33 | 34 | Parameters: 35 | chat_id (``int`` | ``str``): 36 | The id of the channel to be deleted. 37 | 38 | Returns: 39 | ``bool``: On success, True is returned. 40 | 41 | Example: 42 | .. code-block:: python 43 | 44 | await app.delete_channel(channel_id) 45 | """ 46 | await self.invoke( 47 | raw.functions.channels.DeleteChannel( 48 | channel=await self.resolve_peer(chat_id) 49 | ) 50 | ) 51 | 52 | return True 53 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/delete_supergroup.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class DeleteSupergroup: 26 | async def delete_supergroup( 27 | self: "pyrogram.Client", 28 | chat_id: Union[int, str] 29 | ) -> bool: 30 | """Delete a supergroup. 31 | 32 | .. include:: /_includes/usable-by/users.rst 33 | 34 | Parameters: 35 | chat_id (``int`` | ``str``): 36 | The id of the supergroup to be deleted. 37 | 38 | Returns: 39 | ``bool``: On success, True is returned. 40 | 41 | Example: 42 | .. code-block:: python 43 | 44 | await app.delete_supergroup(supergroup_id) 45 | """ 46 | await self.invoke( 47 | raw.functions.channels.DeleteChannel( 48 | channel=await self.resolve_peer(chat_id) 49 | ) 50 | ) 51 | 52 | return True 53 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/get_chat_online_count.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class GetChatOnlineCount: 26 | async def get_chat_online_count( 27 | self: "pyrogram.Client", 28 | chat_id: Union[int, str] 29 | ) -> int: 30 | """Get the number of members that are currently online in a chat. 31 | 32 | .. include:: /_includes/usable-by/users.rst 33 | 34 | Parameters: 35 | chat_id (``int`` | ``str``): 36 | Unique identifier (int) or username (str) of the target chat. 37 | 38 | Returns: 39 | ``int``: On success, the chat members online count is returned. 40 | 41 | Example: 42 | .. code-block:: python 43 | 44 | online = await app.get_chat_online_count(chat_id) 45 | print(online) 46 | """ 47 | return (await self.invoke( 48 | raw.functions.messages.GetOnlines( 49 | peer=await self.resolve_peer(chat_id) 50 | ) 51 | )).onlines 52 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/get_group_call_stream_channels.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class GetGroupCallStreamChannels: 26 | async def get_group_call_stream_channels( 27 | self: "pyrogram.Client", 28 | call: Union[int, str], 29 | chat_id: Union[int, str] 30 | ): 31 | call = await self.invoke(raw.functions.channels.GetFullChannel(channel=await self.resolve_peer(chat_id))) 32 | try: 33 | result = await self.invoke( 34 | raw.functions.phone.GetGroupCallStreamChannels( 35 | call=call.full_chat.call 36 | ) 37 | ) 38 | return result 39 | except Exception as e: 40 | return Exception(e) 41 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/get_group_call_stream_rtmp_url.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union, Optional 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class GetGroupCallStreamRtmpUrl: 26 | async def get_group_call_stream_rtmp_url( 27 | self: "pyrogram.Client", 28 | peer: Union[int, str], 29 | revoke: Optional[bool] 30 | ): 31 | return await self.invoke( 32 | raw.functions.phone.GetGroupCallStreamRtmpUrl( 33 | peer=await self.resolve_peer(peer), 34 | revoke=revoke 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/mark_chat_unread.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class MarkChatUnread: 26 | async def mark_chat_unread( 27 | self: "pyrogram.Client", 28 | chat_id: Union[int, str], 29 | ) -> bool: 30 | """Mark a chat as unread. 31 | 32 | .. include:: /_includes/usable-by/users.rst 33 | 34 | Parameters: 35 | chat_id (``int`` | ``str``): 36 | Unique identifier (int) or username (str) of the target chat. 37 | 38 | Returns: 39 | ``bool``: On success, True is returned. 40 | """ 41 | 42 | return await self.invoke( 43 | raw.functions.messages.MarkDialogUnread( 44 | peer=await self.resolve_peer(chat_id), 45 | unread=True 46 | ) 47 | ) 48 | -------------------------------------------------------------------------------- /pyrogram/methods/chats/set_chat_protected_content.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class SetChatProtectedContent: 26 | async def set_chat_protected_content( 27 | self: "pyrogram.Client", 28 | chat_id: Union[int, str], 29 | enabled: bool 30 | ) -> bool: 31 | """Set the chat protected content setting. 32 | 33 | .. include:: /_includes/usable-by/users-bots.rst 34 | 35 | Parameters: 36 | chat_id (``int`` | ``str``): 37 | Unique identifier (int) or username (str) of the target chat. 38 | 39 | enabled (``bool``): 40 | Pass True to enable the protected content setting, False to disable. 41 | 42 | Returns: 43 | ``bool``: On success, True is returned. 44 | """ 45 | 46 | await self.invoke( 47 | raw.functions.messages.ToggleNoForwards( 48 | peer=await self.resolve_peer(chat_id), 49 | enabled=enabled 50 | ) 51 | ) 52 | 53 | return True 54 | -------------------------------------------------------------------------------- /pyrogram/methods/contacts/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .add_contact import AddContact 20 | from .delete_contacts import DeleteContacts 21 | from .get_contacts import GetContacts 22 | from .get_contacts_count import GetContactsCount 23 | from .import_contacts import ImportContacts 24 | 25 | 26 | class Contacts( 27 | GetContacts, 28 | DeleteContacts, 29 | ImportContacts, 30 | GetContactsCount, 31 | AddContact 32 | ): 33 | pass 34 | -------------------------------------------------------------------------------- /pyrogram/methods/contacts/get_contacts.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import logging 20 | from typing import List 21 | 22 | import pyrogram 23 | from pyrogram import raw 24 | from pyrogram import types 25 | 26 | log = logging.getLogger(__name__) 27 | 28 | 29 | class GetContacts: 30 | async def get_contacts( 31 | self: "pyrogram.Client" 32 | ) -> List["types.User"]: 33 | """Get contacts from your Telegram address book. 34 | 35 | .. include:: /_includes/usable-by/users.rst 36 | 37 | Returns: 38 | List of :obj:`~pyrogram.types.User`: On success, a list of users is returned. 39 | 40 | Example: 41 | .. code-block:: python 42 | 43 | contacts = await app.get_contacts() 44 | print(contacts) 45 | """ 46 | contacts = await self.invoke(raw.functions.contacts.GetContacts(hash=0)) 47 | return types.List(types.User._parse(self, user) for user in contacts.users) 48 | -------------------------------------------------------------------------------- /pyrogram/methods/contacts/get_contacts_count.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | 22 | 23 | class GetContactsCount: 24 | async def get_contacts_count( 25 | self: "pyrogram.Client" 26 | ) -> int: 27 | """Get the total count of contacts from your Telegram address book. 28 | 29 | .. include:: /_includes/usable-by/users.rst 30 | 31 | Returns: 32 | ``int``: On success, the contacts count is returned. 33 | 34 | Example: 35 | .. code-block:: python 36 | 37 | count = await app.get_contacts_count() 38 | print(count) 39 | """ 40 | 41 | return len((await self.invoke(raw.functions.contacts.GetContacts(hash=0))).contacts) 42 | -------------------------------------------------------------------------------- /pyrogram/methods/decorators/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .on_callback_query import OnCallbackQuery 20 | from .on_chat_join_request import OnChatJoinRequest 21 | from .on_chat_member_updated import OnChatMemberUpdated 22 | from .on_chosen_inline_result import OnChosenInlineResult 23 | from .on_deleted_messages import OnDeletedMessages 24 | from .on_disconnect import OnDisconnect 25 | from .on_edited_message import OnEditedMessage 26 | from .on_inline_query import OnInlineQuery 27 | from .on_message import OnMessage 28 | from .on_poll import OnPoll 29 | from .on_raw_update import OnRawUpdate 30 | from .on_user_status import OnUserStatus 31 | 32 | 33 | class Decorators( 34 | OnMessage, 35 | OnEditedMessage, 36 | OnDeletedMessages, 37 | OnCallbackQuery, 38 | OnRawUpdate, 39 | OnDisconnect, 40 | OnUserStatus, 41 | OnInlineQuery, 42 | OnPoll, 43 | OnChosenInlineResult, 44 | OnChatMemberUpdated, 45 | OnChatJoinRequest 46 | ): 47 | pass 48 | -------------------------------------------------------------------------------- /pyrogram/methods/decorators/on_disconnect.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Callable 20 | 21 | import pyrogram 22 | 23 | 24 | class OnDisconnect: 25 | def on_disconnect(self=None) -> Callable: 26 | """Decorator for handling disconnections. 27 | 28 | This does the same thing as :meth:`~pyrogram.Client.add_handler` using the 29 | :obj:`~pyrogram.handlers.DisconnectHandler`. 30 | """ 31 | 32 | def decorator(func: Callable) -> Callable: 33 | if isinstance(self, pyrogram.Client): 34 | self.add_handler(pyrogram.handlers.DisconnectHandler(func)) 35 | else: 36 | if not hasattr(func, "handlers"): 37 | func.handlers = [] 38 | 39 | func.handlers.append((pyrogram.handlers.DisconnectHandler(func), 0)) 40 | 41 | return func 42 | 43 | return decorator 44 | -------------------------------------------------------------------------------- /pyrogram/methods/decorators/on_raw_update.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Callable 20 | 21 | import pyrogram 22 | 23 | 24 | class OnRawUpdate: 25 | def on_raw_update( 26 | self=None, 27 | group: int = 0 28 | ) -> Callable: 29 | """Decorator for handling raw updates. 30 | 31 | This does the same thing as :meth:`~pyrogram.Client.add_handler` using the 32 | :obj:`~pyrogram.handlers.RawUpdateHandler`. 33 | 34 | Parameters: 35 | group (``int``, *optional*): 36 | The group identifier, defaults to 0. 37 | """ 38 | 39 | def decorator(func: Callable) -> Callable: 40 | if isinstance(self, pyrogram.Client): 41 | self.add_handler(pyrogram.handlers.RawUpdateHandler(func), group) 42 | else: 43 | if not hasattr(func, "handlers"): 44 | func.handlers = [] 45 | 46 | func.handlers.append( 47 | ( 48 | pyrogram.handlers.RawUpdateHandler(func), 49 | group 50 | ) 51 | ) 52 | 53 | return func 54 | 55 | return decorator 56 | -------------------------------------------------------------------------------- /pyrogram/methods/invite_links/delete_chat_invite_link.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class DeleteChatInviteLink: 26 | async def delete_chat_invite_link( 27 | self: "pyrogram.Client", 28 | chat_id: Union[int, str], 29 | invite_link: str, 30 | ) -> bool: 31 | """Delete an already revoked invite link. 32 | 33 | .. include:: /_includes/usable-by/users.rst 34 | 35 | Parameters: 36 | chat_id (``int`` | ``str``): 37 | Unique identifier for the target chat or username of the target channel/supergroup 38 | (in the format @username). 39 | 40 | invite_link (``str``): 41 | The revoked invite link to delete. 42 | 43 | Returns: 44 | ``bool``: On success ``True`` is returned. 45 | """ 46 | 47 | return await self.invoke( 48 | raw.functions.messages.DeleteExportedChatInvite( 49 | peer=await self.resolve_peer(chat_id), 50 | link=invite_link, 51 | ) 52 | ) 53 | -------------------------------------------------------------------------------- /pyrogram/methods/password/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .change_cloud_password import ChangeCloudPassword 20 | from .enable_cloud_password import EnableCloudPassword 21 | from .remove_cloud_password import RemoveCloudPassword 22 | 23 | 24 | class Password( 25 | RemoveCloudPassword, 26 | ChangeCloudPassword, 27 | EnableCloudPassword 28 | ): 29 | pass 30 | -------------------------------------------------------------------------------- /pyrogram/methods/users/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .block_user import BlockUser 20 | from .delete_profile_photos import DeleteProfilePhotos 21 | from .get_chat_photos import GetChatPhotos 22 | from .get_chat_photos_count import GetChatPhotosCount 23 | from .get_common_chats import GetCommonChats 24 | from .get_default_emoji_statuses import GetDefaultEmojiStatuses 25 | from .get_me import GetMe 26 | from .get_users import GetUsers 27 | from .set_emoji_status import SetEmojiStatus 28 | from .set_profile_photo import SetProfilePhoto 29 | from .set_username import SetUsername 30 | from .unblock_user import UnblockUser 31 | from .update_profile import UpdateProfile 32 | 33 | 34 | class Users( 35 | BlockUser, 36 | GetCommonChats, 37 | GetChatPhotos, 38 | SetProfilePhoto, 39 | DeleteProfilePhotos, 40 | GetUsers, 41 | GetMe, 42 | SetUsername, 43 | GetChatPhotosCount, 44 | UnblockUser, 45 | UpdateProfile, 46 | GetDefaultEmojiStatuses, 47 | SetEmojiStatus 48 | ): 49 | pass 50 | -------------------------------------------------------------------------------- /pyrogram/methods/users/block_user.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class BlockUser: 26 | async def block_user( 27 | self: "pyrogram.Client", 28 | user_id: Union[int, str], 29 | my_stories_from: Union[bool, None] = None 30 | ) -> bool: 31 | """Block a user. 32 | 33 | .. include:: /_includes/usable-by/users.rst 34 | 35 | Parameters: 36 | user_id (``int`` | ``str``):: 37 | Unique identifier (int) or username (str) of the target user. 38 | For you yourself you can simply use "me" or "self". 39 | For a contact that exists in your Telegram address book you can use his phone number (str). 40 | 41 | Returns: 42 | ``bool``: True on success 43 | 44 | Example: 45 | .. code-block:: python 46 | 47 | await app.block_user(user_id) 48 | """ 49 | return bool( 50 | await self.invoke( 51 | raw.functions.contacts.Block( 52 | id=await self.resolve_peer(user_id), 53 | my_stories_from=my_stories_from 54 | ) 55 | ) 56 | ) 57 | -------------------------------------------------------------------------------- /pyrogram/methods/users/get_default_emoji_statuses.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import List 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | from pyrogram import types 24 | 25 | 26 | class GetDefaultEmojiStatuses: 27 | async def get_default_emoji_statuses( 28 | self: "pyrogram.Client", 29 | ) -> List["types.EmojiStatus"]: 30 | """Get the default emoji statuses. 31 | 32 | .. include:: /_includes/usable-by/users-bots.rst 33 | 34 | Returns: 35 | List of :obj:`~pyrogram.types.EmojiStatus`: On success, a list of emoji statuses is returned. 36 | 37 | Example: 38 | .. code-block:: python 39 | 40 | default_emoji_statuses = await app.get_default_emoji_statuses() 41 | print(default_emoji_statuses) 42 | """ 43 | r = await self.invoke( 44 | raw.functions.account.GetDefaultEmojiStatuses(hash=0) 45 | ) 46 | 47 | return types.List([types.EmojiStatus._parse(self, i) for i in r.statuses]) 48 | -------------------------------------------------------------------------------- /pyrogram/methods/users/get_me.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from pyrogram import types 22 | 23 | 24 | class GetMe: 25 | async def get_me( 26 | self: "pyrogram.Client" 27 | ) -> "types.User": 28 | """Get your own user identity. 29 | 30 | .. include:: /_includes/usable-by/users-bots.rst 31 | 32 | Returns: 33 | :obj:`~pyrogram.types.User`: Information about the own logged in user/bot. 34 | 35 | Example: 36 | .. code-block:: python 37 | 38 | me = await app.get_me() 39 | print(me) 40 | """ 41 | r = await self.invoke( 42 | raw.functions.users.GetFullUser( 43 | id=raw.types.InputUserSelf() 44 | ) 45 | ) 46 | 47 | users = {u.id: u for u in r.users} 48 | 49 | return types.User._parse(self, users[r.full_user.id]) 50 | -------------------------------------------------------------------------------- /pyrogram/methods/users/set_username.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Optional 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class SetUsername: 26 | async def set_username( 27 | self: "pyrogram.Client", 28 | username: Optional[str] 29 | ) -> bool: 30 | """Set your own username. 31 | 32 | This method only works for users, not bots. Bot usernames must be changed via Bot Support or by recreating 33 | them from scratch using BotFather. To set a channel or supergroup username you can use 34 | :meth:`~pyrogram.Client.set_chat_username`. 35 | 36 | .. include:: /_includes/usable-by/users.rst 37 | 38 | Parameters: 39 | username (``str`` | ``None``): 40 | Username to set. "" (empty string) or None to remove it. 41 | 42 | Returns: 43 | ``bool``: True on success. 44 | 45 | Example: 46 | .. code-block:: python 47 | 48 | await app.set_username("new_username") 49 | """ 50 | 51 | return bool( 52 | await self.invoke( 53 | raw.functions.account.UpdateUsername( 54 | username=username or "" 55 | ) 56 | ) 57 | ) 58 | -------------------------------------------------------------------------------- /pyrogram/methods/users/unblock_user.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | 24 | 25 | class UnblockUser: 26 | async def unblock_user( 27 | self: "pyrogram.Client", 28 | user_id: Union[int, str], 29 | my_stories_from: Union[bool, None] = None 30 | ) -> bool: 31 | """Unblock a user. 32 | 33 | .. include:: /_includes/usable-by/users.rst 34 | 35 | Parameters: 36 | user_id (``int`` | ``str``):: 37 | Unique identifier (int) or username (str) of the target user. 38 | For you yourself you can simply use "me" or "self". 39 | For a contact that exists in your Telegram address book you can use his phone number (str). 40 | 41 | Returns: 42 | ``bool``: True on success 43 | 44 | Example: 45 | .. code-block:: python 46 | 47 | await app.unblock_user(user_id) 48 | """ 49 | return bool( 50 | await self.invoke( 51 | raw.functions.contacts.Unblock( 52 | id=await self.resolve_peer(user_id), 53 | my_stories_from=my_stories_from 54 | ) 55 | ) 56 | ) 57 | -------------------------------------------------------------------------------- /pyrogram/methods/utilities/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .add_handler import AddHandler 20 | from .export_session_string import ExportSessionString 21 | from .remove_handler import RemoveHandler 22 | from .restart import Restart 23 | from .run import Run 24 | from .start import Start 25 | from .stop import Stop 26 | from .stop_transmission import StopTransmission 27 | 28 | 29 | class Utilities( 30 | AddHandler, 31 | ExportSessionString, 32 | RemoveHandler, 33 | Restart, 34 | Run, 35 | Start, 36 | Stop, 37 | StopTransmission 38 | ): 39 | pass 40 | -------------------------------------------------------------------------------- /pyrogram/methods/utilities/export_session_string.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | 21 | 22 | class ExportSessionString: 23 | async def export_session_string( 24 | self: "pyrogram.Client" 25 | ): 26 | """Export the current authorized session as a serialized string. 27 | 28 | Session strings are useful for storing in-memory authorized sessions in a portable, serialized string. 29 | More detailed information about session strings can be found at the dedicated page of 30 | :doc:`Storage Engines <../../topics/storage-engines>`. 31 | 32 | Returns: 33 | ``str``: The session serialized into a printable, url-safe string. 34 | 35 | Example: 36 | .. code-block:: python 37 | 38 | s = await app.export_session_string() 39 | """ 40 | return await self.storage.export_session_string() 41 | -------------------------------------------------------------------------------- /pyrogram/methods/utilities/stop_transmission.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | 21 | 22 | class StopTransmission: 23 | def stop_transmission(self): 24 | """Stop downloading or uploading a file. 25 | 26 | This method must be called inside a progress callback function in order to stop the transmission at the 27 | desired time. The progress callback is called every time a file chunk is uploaded/downloaded. 28 | 29 | Example: 30 | .. code-block:: python 31 | 32 | # Stop transmission once the upload progress reaches 50% 33 | async def progress(current, total, client): 34 | if (current * 100 / total) > 50: 35 | client.stop_transmission() 36 | 37 | async with app: 38 | await app.send_document( 39 | "me", "file.zip", 40 | progress=progress, 41 | progress_args=(app,)) 42 | """ 43 | raise pyrogram.StopTransmission 44 | -------------------------------------------------------------------------------- /pyrogram/parser/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .parser import Parser 20 | -------------------------------------------------------------------------------- /pyrogram/parser/utils.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import re 20 | from struct import unpack 21 | 22 | # SMP = Supplementary Multilingual Plane: https://en.wikipedia.org/wiki/Plane_(Unicode)#Overview 23 | SMP_RE = re.compile(r"[\U00010000-\U0010FFFF]") 24 | 25 | 26 | def add_surrogates(text): 27 | # Replace each SMP code point with a surrogate pair 28 | return SMP_RE.sub( 29 | lambda match: # Split SMP in two surrogates 30 | "".join(chr(i) for i in unpack(" 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from importlib import import_module 20 | 21 | from . import types, functions, base, core 22 | from .all import objects 23 | 24 | for k, v in objects.items(): 25 | path, name = v.rsplit(".", 1) 26 | objects[k] = getattr(import_module(path), name) 27 | -------------------------------------------------------------------------------- /pyrogram/raw/core/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .future_salt import FutureSalt 20 | from .future_salts import FutureSalts 21 | from .gzip_packed import GzipPacked 22 | from .list import List 23 | from .message import Message 24 | from .msg_container import MsgContainer 25 | from .primitives.bool import Bool, BoolFalse, BoolTrue 26 | from .primitives.bytes import Bytes 27 | from .primitives.double import Double 28 | from .primitives.int import Int, Long, Int128, Int256 29 | from .primitives.string import String 30 | from .primitives.vector import Vector 31 | from .tl_object import TLObject 32 | -------------------------------------------------------------------------------- /pyrogram/raw/core/future_salt.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from io import BytesIO 20 | from typing import Any 21 | 22 | from .primitives.int import Int, Long 23 | from .tl_object import TLObject 24 | 25 | 26 | class FutureSalt(TLObject): 27 | ID = 0x0949D9DC 28 | 29 | __slots__ = ["valid_since", "valid_until", "salt"] 30 | 31 | QUALNAME = "FutureSalt" 32 | 33 | def __init__(self, valid_since: int, valid_until: int, salt: int): 34 | self.valid_since = valid_since 35 | self.valid_until = valid_until 36 | self.salt = salt 37 | 38 | @staticmethod 39 | def read(data: BytesIO, *args: Any) -> "FutureSalt": 40 | valid_since = Int.read(data) 41 | valid_until = Int.read(data) 42 | salt = Long.read(data) 43 | 44 | return FutureSalt(valid_since, valid_until, salt) 45 | 46 | def write(self, *args: Any) -> bytes: 47 | b = BytesIO() 48 | 49 | b.write(Int(self.valid_since)) 50 | b.write(Int(self.valid_until)) 51 | b.write(Long(self.salt)) 52 | 53 | return b.getvalue() 54 | -------------------------------------------------------------------------------- /pyrogram/raw/core/gzip_packed.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from gzip import compress, decompress 20 | from io import BytesIO 21 | from typing import cast, Any 22 | 23 | from .primitives.bytes import Bytes 24 | from .primitives.int import Int 25 | from .tl_object import TLObject 26 | 27 | 28 | class GzipPacked(TLObject): 29 | ID = 0x3072CFA1 30 | 31 | __slots__ = ["packed_data"] 32 | 33 | QUALNAME = "GzipPacked" 34 | 35 | def __init__(self, packed_data: TLObject): 36 | self.packed_data = packed_data 37 | 38 | @staticmethod 39 | def read(data: BytesIO, *args: Any) -> "GzipPacked": 40 | # Return the Object itself instead of a GzipPacked wrapping it 41 | return cast(GzipPacked, TLObject.read( 42 | BytesIO( 43 | decompress( 44 | Bytes.read(data) 45 | ) 46 | ) 47 | )) 48 | 49 | def write(self, *args: Any) -> bytes: 50 | b = BytesIO() 51 | 52 | b.write(Int(self.ID, False)) 53 | 54 | b.write( 55 | Bytes( 56 | compress( 57 | self.packed_data.write() 58 | ) 59 | ) 60 | ) 61 | 62 | return b.getvalue() 63 | -------------------------------------------------------------------------------- /pyrogram/raw/core/list.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import List as TList, Any 20 | 21 | from .tl_object import TLObject 22 | 23 | 24 | class List(TList[Any], TLObject): 25 | def __repr__(self) -> str: 26 | return f"pyrogram.raw.core.List([{','.join(TLObject.__repr__(i) for i in self)}])" 27 | -------------------------------------------------------------------------------- /pyrogram/raw/core/message.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from io import BytesIO 20 | from typing import Any 21 | 22 | from .primitives.int import Int, Long 23 | from .tl_object import TLObject 24 | 25 | 26 | class Message(TLObject): 27 | ID = 0x5BB8E511 # hex(crc32(b"message msg_id:long seqno:int bytes:int body:Object = Message")) 28 | 29 | __slots__ = ["msg_id", "seq_no", "length", "body"] 30 | 31 | QUALNAME = "Message" 32 | 33 | def __init__(self, body: TLObject, msg_id: int, seq_no: int, length: int): 34 | self.msg_id = msg_id 35 | self.seq_no = seq_no 36 | self.length = length 37 | self.body = body 38 | 39 | @staticmethod 40 | def read(data: BytesIO, *args: Any) -> "Message": 41 | msg_id = Long.read(data) 42 | seq_no = Int.read(data) 43 | length = Int.read(data) 44 | body = data.read(length) 45 | 46 | return Message(TLObject.read(BytesIO(body)), msg_id, seq_no, length) 47 | 48 | def write(self, *args: Any) -> bytes: 49 | b = BytesIO() 50 | 51 | b.write(Long(self.msg_id)) 52 | b.write(Int(self.seq_no)) 53 | b.write(Int(self.length)) 54 | b.write(self.body.write()) 55 | 56 | return b.getvalue() 57 | -------------------------------------------------------------------------------- /pyrogram/raw/core/msg_container.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from io import BytesIO 20 | from typing import List, Any 21 | 22 | from .message import Message 23 | from .primitives.int import Int 24 | from .tl_object import TLObject 25 | 26 | 27 | class MsgContainer(TLObject): 28 | ID = 0x73F1F8DC 29 | 30 | __slots__ = ["messages"] 31 | 32 | QUALNAME = "MsgContainer" 33 | 34 | def __init__(self, messages: List[Message]): 35 | self.messages = messages 36 | 37 | @staticmethod 38 | def read(data: BytesIO, *args: Any) -> "MsgContainer": 39 | count = Int.read(data) 40 | return MsgContainer([Message.read(data) for _ in range(count)]) 41 | 42 | def write(self, *args: Any) -> bytes: 43 | b = BytesIO() 44 | 45 | b.write(Int(self.ID, False)) 46 | 47 | count = len(self.messages) 48 | b.write(Int(count)) 49 | 50 | for message in self.messages: 51 | b.write(message.write()) 52 | 53 | return b.getvalue() 54 | -------------------------------------------------------------------------------- /pyrogram/raw/core/primitives/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .bool import Bool, BoolFalse, BoolTrue 20 | from .bytes import Bytes 21 | from .double import Double 22 | from .int import Int, Long, Int128, Int256 23 | from .string import String 24 | from .vector import Vector 25 | -------------------------------------------------------------------------------- /pyrogram/raw/core/primitives/bool.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from io import BytesIO 20 | from typing import Any 21 | 22 | from ..tl_object import TLObject 23 | 24 | 25 | class BoolFalse(bytes, TLObject): 26 | ID = 0xBC799737 27 | value = False 28 | 29 | @classmethod 30 | def read(cls, *args: Any) -> bool: 31 | return cls.value 32 | 33 | def __new__(cls) -> bytes: # type: ignore 34 | return cls.ID.to_bytes(4, "little") 35 | 36 | 37 | class BoolTrue(BoolFalse): 38 | ID = 0x997275B5 39 | value = True 40 | 41 | 42 | class Bool(bytes, TLObject): 43 | @classmethod 44 | def read(cls, data: BytesIO, *args: Any) -> bool: 45 | return int.from_bytes(data.read(4), "little") == BoolTrue.ID 46 | 47 | def __new__(cls, value: bool) -> bytes: # type: ignore 48 | return BoolTrue() if value else BoolFalse() 49 | -------------------------------------------------------------------------------- /pyrogram/raw/core/primitives/bytes.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from io import BytesIO 20 | from typing import Any 21 | 22 | from ..tl_object import TLObject 23 | 24 | 25 | class Bytes(bytes, TLObject): 26 | @classmethod 27 | def read(cls, data: BytesIO, *args: Any) -> bytes: 28 | length = int.from_bytes(data.read(1), "little") 29 | 30 | if length <= 253: 31 | x = data.read(length) 32 | data.read(-(length + 1) % 4) 33 | else: 34 | length = int.from_bytes(data.read(3), "little") 35 | x = data.read(length) 36 | data.read(-length % 4) 37 | 38 | return x 39 | 40 | def __new__(cls, value: bytes) -> bytes: # type: ignore 41 | length = len(value) 42 | 43 | if length <= 253: 44 | return ( 45 | bytes([length]) 46 | + value 47 | + bytes(-(length + 1) % 4) 48 | ) 49 | else: 50 | return ( 51 | bytes([254]) 52 | + length.to_bytes(3, "little") 53 | + value 54 | + bytes(-length % 4) 55 | ) 56 | -------------------------------------------------------------------------------- /pyrogram/raw/core/primitives/double.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from io import BytesIO 20 | from struct import unpack, pack 21 | from typing import cast, Any 22 | 23 | from ..tl_object import TLObject 24 | 25 | 26 | class Double(bytes, TLObject): 27 | @classmethod 28 | def read(cls, data: BytesIO, *args: Any) -> float: 29 | return cast(float, unpack("d", data.read(8))[0]) 30 | 31 | def __new__(cls, value: float) -> bytes: # type: ignore 32 | return pack("d", value) 33 | -------------------------------------------------------------------------------- /pyrogram/raw/core/primitives/int.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from io import BytesIO 20 | from typing import Any 21 | 22 | from ..tl_object import TLObject 23 | 24 | 25 | class Int(bytes, TLObject): 26 | SIZE = 4 27 | 28 | @classmethod 29 | def read(cls, data: BytesIO, signed: bool = True, *args: Any) -> int: 30 | return int.from_bytes(data.read(cls.SIZE), "little", signed=signed) 31 | 32 | def __new__(cls, value: int, signed: bool = True) -> bytes: # type: ignore 33 | return value.to_bytes(cls.SIZE, "little", signed=signed) 34 | 35 | 36 | class Long(Int): 37 | SIZE = 8 38 | 39 | 40 | class Int128(Int): 41 | SIZE = 16 42 | 43 | 44 | class Int256(Int): 45 | SIZE = 32 46 | -------------------------------------------------------------------------------- /pyrogram/raw/core/primitives/string.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from io import BytesIO 20 | from typing import cast 21 | 22 | from .bytes import Bytes 23 | 24 | 25 | class String(Bytes): 26 | @classmethod 27 | def read(cls, data: BytesIO, *args) -> str: # type: ignore 28 | return cast(bytes, super(String, String).read(data)).decode(errors="replace") 29 | 30 | def __new__(cls, value: str) -> bytes: # type: ignore 31 | return super().__new__(cls, value.encode()) 32 | -------------------------------------------------------------------------------- /pyrogram/session/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .auth import Auth 20 | from .session import Session 21 | -------------------------------------------------------------------------------- /pyrogram/session/internals/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .data_center import DataCenter 20 | from .msg_factory import MsgFactory 21 | from .msg_id import MsgId 22 | -------------------------------------------------------------------------------- /pyrogram/session/internals/msg_factory.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram.raw.core import Message, MsgContainer, TLObject 20 | from pyrogram.raw.functions import Ping 21 | from pyrogram.raw.types import MsgsAck, HttpWait 22 | from .msg_id import MsgId 23 | from .seq_no import SeqNo 24 | 25 | not_content_related = (Ping, HttpWait, MsgsAck, MsgContainer) 26 | 27 | 28 | class MsgFactory: 29 | def __init__(self): 30 | self.seq_no = SeqNo() 31 | 32 | def __call__(self, body: TLObject) -> Message: 33 | return Message( 34 | body, 35 | MsgId(), 36 | self.seq_no(not isinstance(body, not_content_related)), 37 | len(body) 38 | ) 39 | -------------------------------------------------------------------------------- /pyrogram/session/internals/msg_id.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import logging 20 | import time 21 | 22 | log = logging.getLogger(__name__) 23 | 24 | 25 | class MsgId: 26 | last_time = 0 27 | offset = 0 28 | 29 | def __new__(cls) -> int: 30 | now = int(time.time()) 31 | cls.offset = (cls.offset + 4) if now == cls.last_time else 0 32 | msg_id = (now * 2 ** 32) + cls.offset 33 | cls.last_time = now 34 | 35 | return msg_id 36 | -------------------------------------------------------------------------------- /pyrogram/session/internals/seq_no.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | 20 | class SeqNo: 21 | def __init__(self): 22 | self.content_related_messages_sent = 0 23 | 24 | def __call__(self, is_content_related: bool) -> int: 25 | seq_no = (self.content_related_messages_sent * 2) + (1 if is_content_related else 0) 26 | 27 | if is_content_related: 28 | self.content_related_messages_sent += 1 29 | 30 | return seq_no 31 | -------------------------------------------------------------------------------- /pyrogram/storage/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .file_storage import FileStorage 20 | from .memory_storage import MemoryStorage 21 | from .storage import Storage 22 | -------------------------------------------------------------------------------- /pyrogram/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .authorization import * 20 | from .bots_and_keyboards import * 21 | from .inline_mode import * 22 | from .input_media import * 23 | from .input_message_content import * 24 | from .list import List 25 | from .messages_and_media import * 26 | from .object import Object 27 | from .update import * 28 | from .user_and_chats import * 29 | -------------------------------------------------------------------------------- /pyrogram/types/authorization/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .sent_code import SentCode 20 | from .terms_of_service import TermsOfService 21 | 22 | __all__ = ["TermsOfService", "SentCode"] 23 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/bot_command.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | 21 | from ..object import Object 22 | 23 | 24 | class BotCommand(Object): 25 | """A bot command with the standard slash "/" prefix. 26 | 27 | Parameters: 28 | command (``str``): 29 | Text of the command; 1-32 characters. 30 | Can contain only lowercase English letters, digits and underscores. 31 | 32 | description (``str``): 33 | Description of the command; 1-256 characters. 34 | """ 35 | 36 | def __init__(self, command: str, description: str): 37 | super().__init__() 38 | 39 | self.command = command 40 | self.description = description 41 | 42 | def write(self) -> "raw.types.BotCommand": 43 | return raw.types.BotCommand( 44 | command=self.command, 45 | description=self.description, 46 | ) 47 | 48 | @staticmethod 49 | def read(c: "raw.types.BotCommand") -> "BotCommand": 50 | return BotCommand( 51 | command=c.command, 52 | description=c.description 53 | ) 54 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/bot_command_scope_all_chat_administrators.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from .bot_command_scope import BotCommandScope 22 | 23 | 24 | class BotCommandScopeAllChatAdministrators(BotCommandScope): 25 | """Represents the scope of bot commands, covering all group and supergroup chat administrators. 26 | """ 27 | 28 | def __init__(self): 29 | super().__init__("all_chat_administrators") 30 | 31 | async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope": 32 | return raw.types.BotCommandScopeChatAdmins() 33 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/bot_command_scope_all_group_chats.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from .bot_command_scope import BotCommandScope 22 | 23 | 24 | class BotCommandScopeAllGroupChats(BotCommandScope): 25 | """Represents the scope of bot commands, covering all group and supergroup chats. 26 | """ 27 | 28 | def __init__(self): 29 | super().__init__("all_group_chats") 30 | 31 | async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope": 32 | return raw.types.BotCommandScopeChats() 33 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/bot_command_scope_all_private_chats.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from .bot_command_scope import BotCommandScope 22 | 23 | 24 | class BotCommandScopeAllPrivateChats(BotCommandScope): 25 | """Represents the scope of bot commands, covering all private chats. 26 | """ 27 | 28 | def __init__(self): 29 | super().__init__("all_private_chats") 30 | 31 | async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope": 32 | return raw.types.BotCommandScopeUsers() 33 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/bot_command_scope_chat.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | from .bot_command_scope import BotCommandScope 24 | 25 | 26 | class BotCommandScopeChat(BotCommandScope): 27 | """Represents the scope of bot commands, covering a specific chat. 28 | 29 | Parameters: 30 | chat_id (``int`` | ``str``): 31 | Unique identifier for the target chat or username of the target supergroup (in the format 32 | @supergroupusername). 33 | """ 34 | 35 | def __init__(self, chat_id: Union[int, str]): 36 | super().__init__("chat") 37 | 38 | self.chat_id = chat_id 39 | 40 | async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope": 41 | return raw.types.BotCommandScopePeer( 42 | peer=await client.resolve_peer(self.chat_id) 43 | ) 44 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/bot_command_scope_chat_administrators.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | from .bot_command_scope import BotCommandScope 24 | 25 | 26 | class BotCommandScopeChatAdministrators(BotCommandScope): 27 | """Represents the scope of bot commands, covering all administrators of a specific group or supergroup chat. 28 | 29 | Parameters: 30 | chat_id (``int`` | ``str``): 31 | Unique identifier for the target chat or username of the target supergroup (in the format 32 | @supergroupusername). 33 | """ 34 | 35 | def __init__(self, chat_id: Union[int, str]): 36 | super().__init__("chat_administrators") 37 | 38 | self.chat_id = chat_id 39 | 40 | async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope": 41 | return raw.types.BotCommandScopePeerAdmins( 42 | peer=await client.resolve_peer(self.chat_id) 43 | ) 44 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/bot_command_scope_chat_member.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Union 20 | 21 | import pyrogram 22 | from pyrogram import raw 23 | from .bot_command_scope import BotCommandScope 24 | 25 | 26 | class BotCommandScopeChatMember(BotCommandScope): 27 | """Represents the scope of bot commands, covering a specific member of a group or supergroup chat. 28 | 29 | Parameters: 30 | chat_id (``int`` | ``str``): 31 | Unique identifier for the target chat or username of the target supergroup (in the format 32 | @supergroupusername). 33 | 34 | user_id (``int`` | ``str``): 35 | Unique identifier of the target user. 36 | """ 37 | 38 | def __init__(self, chat_id: Union[int, str], user_id: Union[int, str]): 39 | super().__init__("chat_member") 40 | 41 | self.chat_id = chat_id 42 | self.user_id = user_id 43 | 44 | async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope": 45 | return raw.types.BotCommandScopePeerUser( 46 | peer=await client.resolve_peer(self.chat_id), 47 | user_id=await client.resolve_peer(self.user_id) 48 | ) 49 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/bot_command_scope_default.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from .bot_command_scope import BotCommandScope 22 | 23 | 24 | class BotCommandScopeDefault(BotCommandScope): 25 | """Represents the default scope of bot commands. 26 | Default commands are used if no commands with a narrower scope are specified for the user. 27 | """ 28 | 29 | def __init__(self): 30 | super().__init__("default") 31 | 32 | async def write(self, client: "pyrogram.Client") -> "raw.base.BotCommandScope": 33 | return raw.types.BotCommandScopeDefault() 34 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/callback_game.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from ..object import Object 20 | 21 | 22 | class CallbackGame(Object): 23 | """Placeholder, currently holds no information. 24 | 25 | Use BotFather to set up your game. 26 | """ 27 | 28 | def __init__(self): 29 | super().__init__() 30 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/menu_button.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from ..object import Object 22 | 23 | 24 | class MenuButton(Object): 25 | """Describes the bot's menu button in a private chat. 26 | 27 | It should be one of: 28 | 29 | - :obj:`~pyrogram.types.MenuButtonCommands` 30 | - :obj:`~pyrogram.types.MenuButtonWebApp` 31 | - :obj:`~pyrogram.types.MenuButtonDefault` 32 | 33 | If a menu button other than :obj:`~pyrogram.types.MenuButtonDefault` is set for a private chat, then it is applied 34 | in the chat. Otherwise the default menu button is applied. By default, the menu button opens the list of bot 35 | commands. 36 | """ 37 | 38 | def __init__(self, type: str): 39 | super().__init__() 40 | 41 | self.type = type 42 | 43 | async def write(self, client: "pyrogram.Client") -> "raw.base.BotMenuButton": 44 | raise NotImplementedError 45 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/menu_button_commands.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from .menu_button import MenuButton 22 | 23 | 24 | class MenuButtonCommands(MenuButton): 25 | """A menu button, which opens the bot's list of commands. 26 | """ 27 | 28 | def __init__(self): 29 | super().__init__("commands") 30 | 31 | async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButtonCommands": 32 | return raw.types.BotMenuButtonCommands() 33 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/menu_button_default.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from .menu_button import MenuButton 22 | 23 | 24 | class MenuButtonDefault(MenuButton): 25 | """Describes that no specific value for the menu button was set. 26 | """ 27 | 28 | def __init__(self): 29 | super().__init__("default") 30 | 31 | async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButtonDefault": 32 | return raw.types.BotMenuButtonDefault() 33 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/menu_button_web_app.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw, types 21 | from .menu_button import MenuButton 22 | 23 | 24 | class MenuButtonWebApp(MenuButton): 25 | """A menu button, which launches a `Web App `_. 26 | 27 | Parameters: 28 | text (``str``): 29 | Text on the button 30 | 31 | web_app (:obj:`~pyrogram.types.WebAppInfo`): 32 | Description of the Web App that will be launched when the user presses the button. 33 | The Web App will be able to send an arbitrary message on behalf of the user using the method 34 | :meth:`~pyrogram.Client.answer_web_app_query`. 35 | """ 36 | 37 | def __init__( 38 | self, 39 | text: str, 40 | web_app: "types.WebAppInfo" 41 | ): 42 | super().__init__("web_app") 43 | 44 | self.text = text 45 | self.web_app = web_app 46 | 47 | async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButton": 48 | return raw.types.BotMenuButton( 49 | text=self.text, 50 | url=self.web_app.url 51 | ) 52 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/sent_web_app_message.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw, utils 20 | from ..object import Object 21 | 22 | 23 | class SentWebAppMessage(Object): 24 | """Contains information about an inline message sent by a `Web App `_ on behalf of a user. 25 | 26 | Parameters: 27 | inline_message_id (``str``): 28 | Identifier of the sent inline message. 29 | Available only if there is an inline keyboard attached to the message. 30 | """ 31 | 32 | def __init__( 33 | self, *, 34 | inline_message_id: str, 35 | ): 36 | super().__init__() 37 | 38 | self.inline_message_id = inline_message_id 39 | 40 | @staticmethod 41 | def _parse(obj: "raw.types.WebViewMessageSent"): 42 | return SentWebAppMessage(inline_message_id=utils.pack_inline_message_id(obj.msg_id)) 43 | -------------------------------------------------------------------------------- /pyrogram/types/bots_and_keyboards/web_app_info.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from ..object import Object 20 | 21 | 22 | class WebAppInfo(Object): 23 | """Contains information about a `Web App `_. 24 | 25 | Parameters: 26 | url (``str``): 27 | An HTTPS URL of a Web App to be opened with additional data as specified in 28 | `Initializing Web Apps `_. 29 | """ 30 | 31 | def __init__( 32 | self, *, 33 | url: str, 34 | ): 35 | super().__init__() 36 | 37 | self.url = url 38 | -------------------------------------------------------------------------------- /pyrogram/types/input_media/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .input_media import InputMedia 20 | from .input_media_animation import InputMediaAnimation 21 | from .input_media_audio import InputMediaAudio 22 | from .input_media_document import InputMediaDocument 23 | from .input_media_photo import InputMediaPhoto 24 | from .input_media_video import InputMediaVideo 25 | from .input_phone_contact import InputPhoneContact 26 | 27 | __all__ = [ 28 | "InputMedia", "InputMediaAnimation", "InputMediaAudio", "InputMediaDocument", "InputMediaPhoto", "InputMediaVideo", 29 | "InputPhoneContact" 30 | ] 31 | -------------------------------------------------------------------------------- /pyrogram/types/input_media/input_media.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import List, Union, BinaryIO 20 | 21 | from ..messages_and_media import MessageEntity 22 | from ..object import Object 23 | 24 | 25 | class InputMedia(Object): 26 | """Content of a media message to be sent. 27 | 28 | It should be one of: 29 | 30 | - :obj:`~pyrogram.types.InputMediaAnimation` 31 | - :obj:`~pyrogram.types.InputMediaDocument` 32 | - :obj:`~pyrogram.types.InputMediaAudio` 33 | - :obj:`~pyrogram.types.InputMediaPhoto` 34 | - :obj:`~pyrogram.types.InputMediaVideo` 35 | """ 36 | 37 | def __init__( 38 | self, 39 | media: Union[str, BinaryIO], 40 | caption: str = "", 41 | parse_mode: str = None, 42 | caption_entities: List[MessageEntity] = None 43 | ): 44 | super().__init__() 45 | 46 | self.media = media 47 | self.caption = caption 48 | self.parse_mode = parse_mode 49 | self.caption_entities = caption_entities 50 | -------------------------------------------------------------------------------- /pyrogram/types/input_media/input_phone_contact.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | from pyrogram.session.internals import MsgId 21 | from ..object import Object 22 | 23 | 24 | class InputPhoneContact(Object): 25 | """A Phone Contact to be added in your Telegram address book. 26 | It is intended to be used with :meth:`~pyrogram.Client.add_contacts()` 27 | 28 | Parameters: 29 | phone (``str``): 30 | Contact's phone number 31 | 32 | first_name (``str``): 33 | Contact's first name 34 | 35 | last_name (``str``, *optional*): 36 | Contact's last name 37 | """ 38 | 39 | def __init__(self, phone: str, first_name: str, last_name: str = ""): 40 | super().__init__(None) 41 | 42 | def __new__(cls, 43 | phone: str, 44 | first_name: str, 45 | last_name: str = ""): 46 | return raw.types.InputPhoneContact( 47 | client_id=MsgId(), 48 | phone="+" + phone.strip("+"), 49 | first_name=first_name, 50 | last_name=last_name 51 | ) 52 | -------------------------------------------------------------------------------- /pyrogram/types/input_message_content/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .input_message_content import InputMessageContent 20 | from .input_text_message_content import InputTextMessageContent 21 | 22 | __all__ = [ 23 | "InputMessageContent", "InputTextMessageContent" 24 | ] 25 | -------------------------------------------------------------------------------- /pyrogram/types/input_message_content/input_message_content.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | 21 | from ..object import Object 22 | 23 | """- :obj:`~pyrogram.types.InputLocationMessageContent` 24 | - :obj:`~pyrogram.types.InputVenueMessageContent` 25 | - :obj:`~pyrogram.types.InputContactMessageContent`""" 26 | 27 | 28 | class InputMessageContent(Object): 29 | """Content of a message to be sent as a result of an inline query. 30 | 31 | Pyrogram currently supports the following types: 32 | 33 | - :obj:`~pyrogram.types.InputTextMessageContent` 34 | """ 35 | 36 | def __init__(self): 37 | super().__init__() 38 | 39 | async def write(self, client: "pyrogram.Client", reply_markup): 40 | raise NotImplementedError 41 | -------------------------------------------------------------------------------- /pyrogram/types/list.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .object import Object 20 | 21 | 22 | class List(list): 23 | __slots__ = [] 24 | 25 | def __str__(self): 26 | # noinspection PyCallByClass 27 | return Object.__str__(self) 28 | 29 | def __repr__(self): 30 | return f"pyrogram.types.List([{','.join(Object.__repr__(i) for i in self)}])" 31 | -------------------------------------------------------------------------------- /pyrogram/types/messages_and_media/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from .animation import Animation 20 | from .audio import Audio 21 | from .contact import Contact 22 | from .dice import Dice 23 | from .document import Document 24 | from .game import Game 25 | from .location import Location 26 | from .message import Message 27 | from .message_entity import MessageEntity 28 | from .photo import Photo 29 | from .poll import Poll 30 | from .poll_option import PollOption 31 | from .reaction import Reaction 32 | from .sticker import Sticker 33 | from .stripped_thumbnail import StrippedThumbnail 34 | from .thumbnail import Thumbnail 35 | from .venue import Venue 36 | from .video import Video 37 | from .video_note import VideoNote 38 | from .voice import Voice 39 | from .web_app_data import WebAppData 40 | from .web_page import WebPage 41 | from .message_reactions import MessageReactions 42 | 43 | __all__ = [ 44 | "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", 45 | "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", 46 | "Reaction", "WebAppData", "MessageReactions" 47 | ] 48 | -------------------------------------------------------------------------------- /pyrogram/types/messages_and_media/dice.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from ..object import Object 22 | 23 | 24 | class Dice(Object): 25 | """A dice with a random value from 1 to 6 for currently supported base emoji. 26 | 27 | Parameters: 28 | emoji (``string``): 29 | Emoji on which the dice throw animation is based. 30 | 31 | value (``int``): 32 | Value of the dice, 1-6 for currently supported base emoji. 33 | """ 34 | 35 | def __init__(self, *, client: "pyrogram.Client" = None, emoji: str, value: int): 36 | super().__init__(client) 37 | 38 | self.emoji = emoji 39 | self.value = value 40 | 41 | @staticmethod 42 | def _parse(client, dice: "raw.types.MessageMediaDice") -> "Dice": 43 | return Dice( 44 | emoji=dice.emoticon, 45 | value=dice.value, 46 | client=client 47 | ) 48 | -------------------------------------------------------------------------------- /pyrogram/types/messages_and_media/location.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | 21 | from pyrogram import raw 22 | from ..object import Object 23 | 24 | 25 | class Location(Object): 26 | """A point on the map. 27 | 28 | Parameters: 29 | longitude (``float``): 30 | Longitude as defined by sender. 31 | 32 | latitude (``float``): 33 | Latitude as defined by sender. 34 | """ 35 | 36 | def __init__( 37 | self, 38 | *, 39 | client: "pyrogram.Client" = None, 40 | longitude: float, 41 | latitude: float 42 | ): 43 | super().__init__(client) 44 | 45 | self.longitude = longitude 46 | self.latitude = latitude 47 | 48 | @staticmethod 49 | def _parse(client, geo_point: "raw.types.GeoPoint") -> "Location": 50 | if isinstance(geo_point, raw.types.GeoPoint): 51 | return Location( 52 | longitude=geo_point.long, 53 | latitude=geo_point.lat, 54 | client=client 55 | ) 56 | -------------------------------------------------------------------------------- /pyrogram/types/messages_and_media/message_reactions.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import Optional, List 20 | 21 | import pyrogram 22 | from pyrogram import raw, types 23 | from ..object import Object 24 | 25 | 26 | class MessageReactions(Object): 27 | """Contains information about a message reactions. 28 | 29 | Parameters: 30 | reactions (List of :obj:`~pyrogram.types.Reaction`): 31 | Reactions list. 32 | """ 33 | 34 | def __init__( 35 | self, 36 | *, 37 | client: "pyrogram.Client" = None, 38 | reactions: Optional[List["types.Reaction"]] = None, 39 | ): 40 | super().__init__(client) 41 | 42 | self.reactions = reactions 43 | 44 | @staticmethod 45 | def _parse( 46 | client: "pyrogram.Client", 47 | message_reactions: Optional["raw.base.MessageReactions"] = None 48 | ) -> Optional["MessageReactions"]: 49 | if not message_reactions: 50 | return None 51 | 52 | return MessageReactions( 53 | client=client, 54 | reactions=[types.Reaction._parse_count(client, reaction) 55 | for reaction in message_reactions.results] 56 | ) 57 | -------------------------------------------------------------------------------- /pyrogram/types/messages_and_media/poll_option.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from ..object import Object 21 | 22 | 23 | class PollOption(Object): 24 | """Contains information about one answer option in a poll. 25 | 26 | Parameters: 27 | text (``str``): 28 | Option text, 1-100 characters. 29 | 30 | voter_count (``int``): 31 | Number of users that voted for this option. 32 | Equals to 0 until you vote. 33 | 34 | data (``bytes``): 35 | The data this poll option is holding. 36 | """ 37 | 38 | def __init__( 39 | self, 40 | *, 41 | client: "pyrogram.Client" = None, 42 | text: str, 43 | voter_count: int, 44 | data: bytes 45 | ): 46 | super().__init__(client) 47 | 48 | self.text = text 49 | self.voter_count = voter_count 50 | self.data = data 51 | -------------------------------------------------------------------------------- /pyrogram/types/messages_and_media/story.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from ..object import Object 22 | 23 | 24 | class Story(Object): 25 | """A Story. 26 | 27 | Parameters: 28 | peer: The peer of the story. 29 | chat_id: The chat ID of the story. 30 | via_mention: Whether the story is via mention. 31 | 32 | """ 33 | 34 | def __init__( 35 | self, 36 | *, 37 | client: "pyrogram.Client" = None, 38 | peer, 39 | chat_id, 40 | via_mention, 41 | ): 42 | super().__init__(client) 43 | 44 | self.peer = peer 45 | self.chat_id = chat_id 46 | self.via_mention = via_mention 47 | 48 | @staticmethod 49 | def _parse(client, story: "raw.types.MessageMediaStory"): 50 | return Story( 51 | client=client, 52 | peer=story.peer, 53 | chat_id=story.id, 54 | via_mention=story.via_mention 55 | ) 56 | -------------------------------------------------------------------------------- /pyrogram/types/messages_and_media/stripped_thumbnail.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | from pyrogram import raw 21 | from ..object import Object 22 | 23 | 24 | class StrippedThumbnail(Object): 25 | """A stripped thumbnail 26 | 27 | Parameters: 28 | data (``bytes``): 29 | Thumbnail data 30 | """ 31 | 32 | def __init__( 33 | self, 34 | *, 35 | client: "pyrogram.Client" = None, 36 | data: bytes 37 | ): 38 | super().__init__(client) 39 | 40 | self.data = data 41 | 42 | @staticmethod 43 | def _parse(client, stripped_thumbnail: "raw.types.PhotoStrippedSize") -> "StrippedThumbnail": 44 | return StrippedThumbnail( 45 | data=stripped_thumbnail.bytes, 46 | client=client 47 | ) 48 | -------------------------------------------------------------------------------- /pyrogram/types/messages_and_media/web_app_data.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | from ..object import Object 21 | 22 | 23 | class WebAppData(Object): 24 | """Contains data sent from a `Web App `_ to the bot. 25 | 26 | Parameters: 27 | data (``str``): 28 | The data. 29 | 30 | button_text (``str``): 31 | Text of the *web_app* keyboard button, from which the Web App was opened. 32 | 33 | """ 34 | 35 | def __init__( 36 | self, 37 | *, 38 | data: str, 39 | button_text: str, 40 | ): 41 | super().__init__() 42 | 43 | self.data = data 44 | self.button_text = button_text 45 | 46 | @staticmethod 47 | def _parse(action: "raw.types.MessageActionWebViewDataSentMe"): 48 | return WebAppData( 49 | data=action.data, 50 | button_text=action.text 51 | ) 52 | -------------------------------------------------------------------------------- /pyrogram/types/update.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | import pyrogram 20 | 21 | 22 | class Update: 23 | def stop_propagation(self): 24 | raise pyrogram.StopPropagation 25 | 26 | def continue_propagation(self): 27 | raise pyrogram.ContinuePropagation 28 | -------------------------------------------------------------------------------- /pyrogram/types/user_and_chats/restriction.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | from ..object import Object 21 | 22 | 23 | class Restriction(Object): 24 | """A restriction applied to bots or chats. 25 | 26 | Parameters: 27 | platform (``str``): 28 | The platform the restriction is applied to, e.g. "ios", "android" 29 | 30 | reason (``str``): 31 | The restriction reason, e.g. "porn", "copyright". 32 | 33 | text (``str``): 34 | The restriction text. 35 | """ 36 | 37 | def __init__(self, *, platform: str, reason: str, text: str): 38 | super().__init__(None) 39 | 40 | self.platform = platform 41 | self.reason = reason 42 | self.text = text 43 | 44 | @staticmethod 45 | def _parse(restriction: "raw.types.RestrictionReason") -> "Restriction": 46 | return Restriction( 47 | platform=restriction.platform, 48 | reason=restriction.reason, 49 | text=restriction.text 50 | ) 51 | -------------------------------------------------------------------------------- /pyrogram/types/user_and_chats/username.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | from ..object import Object 21 | 22 | 23 | class Username(Object): 24 | """A user's or chat's username. 25 | 26 | Parameters: 27 | username (``str``): 28 | User's or chat's username. 29 | 30 | editable (``bool``, *optional*): 31 | True, if it's a basic username; False, if it's a collectible username. 32 | 33 | active (``bool``, *optional*): 34 | True, if the collectible username is active. 35 | 36 | """ 37 | 38 | def __init__(self, *, username: str, editable: bool = None, active: bool = None): 39 | super().__init__(None) 40 | 41 | self.username = username 42 | self.editable = editable 43 | self.active = active 44 | 45 | @staticmethod 46 | def _parse(username: "raw.types.Username") -> "Username": 47 | return Username( 48 | username=username.username, 49 | editable=username.editable, 50 | active=username.active 51 | ) 52 | -------------------------------------------------------------------------------- /pyrogram/types/user_and_chats/video_chat_ended.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from pyrogram import raw 20 | from ..object import Object 21 | 22 | 23 | class VideoChatEnded(Object): 24 | """A service message about a voice chat ended in the chat. 25 | 26 | Parameters: 27 | duration (``int``): 28 | Voice chat duration; in seconds. 29 | """ 30 | 31 | def __init__( 32 | self, *, 33 | duration: int 34 | ): 35 | super().__init__() 36 | 37 | self.duration = duration 38 | 39 | @staticmethod 40 | def _parse(action: "raw.types.MessageActionGroupCall") -> "VideoChatEnded": 41 | return VideoChatEnded(duration=action.duration) 42 | -------------------------------------------------------------------------------- /pyrogram/types/user_and_chats/video_chat_members_invited.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from typing import List, Dict 20 | 21 | from pyrogram import raw, types 22 | from ..object import Object 23 | 24 | 25 | class VideoChatMembersInvited(Object): 26 | """A service message about new members invited to a voice chat. 27 | 28 | 29 | Parameters: 30 | users (List of :obj:`~pyrogram.types.User`): 31 | New members that were invited to the voice chat. 32 | """ 33 | 34 | def __init__( 35 | self, *, 36 | users: List["types.User"] 37 | ): 38 | super().__init__() 39 | 40 | self.users = users 41 | 42 | @staticmethod 43 | def _parse( 44 | client, 45 | action: "raw.types.MessageActionInviteToGroupCall", 46 | users: Dict[int, "raw.types.User"] 47 | ) -> "VideoChatMembersInvited": 48 | users = [types.User._parse(client, users[i]) for i in action.users] 49 | 50 | return VideoChatMembersInvited(users=users) 51 | -------------------------------------------------------------------------------- /pyrogram/types/user_and_chats/video_chat_scheduled.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from datetime import datetime 20 | 21 | from pyrogram import raw, utils 22 | from ..object import Object 23 | 24 | 25 | class VideoChatScheduled(Object): 26 | """A service message about a voice chat scheduled in the chat. 27 | 28 | Parameters: 29 | start_date (:py:obj:`~datetime.datetime`): 30 | Point in time when the voice chat is supposed to be started by a chat administrator. 31 | """ 32 | 33 | def __init__( 34 | self, *, 35 | start_date: datetime 36 | ): 37 | super().__init__() 38 | 39 | self.start_date = start_date 40 | 41 | @staticmethod 42 | def _parse(action: "raw.types.MessageActionGroupCallScheduled") -> "VideoChatScheduled": 43 | return VideoChatScheduled(start_date=utils.timestamp_to_datetime(action.schedule_date)) 44 | -------------------------------------------------------------------------------- /pyrogram/types/user_and_chats/video_chat_started.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | from ..object import Object 20 | 21 | 22 | class VideoChatStarted(Object): 23 | """A service message about a voice chat started in the chat. 24 | 25 | Currently holds no information. 26 | """ 27 | 28 | def __init__(self): 29 | super().__init__() 30 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyaes==1.6.1 2 | pysocks==1.7.1 3 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | -------------------------------------------------------------------------------- /tests/filters/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | 19 | class Client: 20 | def __init__(self): 21 | self.me = User("username") 22 | 23 | async def get_me(self): 24 | return self.me 25 | 26 | 27 | class User: 28 | def __init__(self, username: str = None): 29 | self.username = username 30 | 31 | 32 | class Message: 33 | def __init__(self, text: str = None, caption: str = None): 34 | self.text = text 35 | self.caption = caption 36 | self.command = None 37 | -------------------------------------------------------------------------------- /tests/parser/__init__.py: -------------------------------------------------------------------------------- 1 | # Pyrogram - Telegram MTProto API Client Library for Python 2 | # Copyright (C) 2017-present Dan 3 | # 4 | # This file is part of Pyrogram. 5 | # 6 | # Pyrogram is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as published 8 | # by the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Pyrogram is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public License 17 | # along with Pyrogram. If not, see . 18 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [testenv] 2 | deps = -rdev-requirements.txt 3 | commands = coverage run -m pytest {posargs} 4 | skip_install = true --------------------------------------------------------------------------------