2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Merge develop -> asyncio

This commit is contained in:
Dan 2019-07-11 04:17:46 +02:00
commit d441f16879
51 changed files with 890 additions and 930 deletions

View File

@ -101,7 +101,7 @@ userStatusLastMonth#77ebc742 = UserStatus;
chatEmpty#9ba2d800 id:int = Chat;
chat#3bda1bde flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true deactivated:flags.5?true id:int title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel admin_rights:flags.14?ChatAdminRights default_banned_rights:flags.18?ChatBannedRights = Chat;
chatForbidden#7328bdb id:int title:string = Chat;
channel#4df30834 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat;
channel#4df30834 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat;
channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat;
chatFull#1b7c9db3 flags:# can_set_username:flags.7?true id:int about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:flags.3?Vector<BotInfo> pinned_msg_id:flags.6?int folder_id:flags.11?int = ChatFull;
@ -1065,7 +1065,7 @@ auth.resendCode#3ef1a9bf phone_number:string phone_code_hash:string = auth.SentC
auth.cancelCode#1f040578 phone_number:string phone_code_hash:string = Bool;
auth.dropTempAuthKeys#8e48a188 except_auth_keys:Vector<long> = Bool;
account.registerDevice#5cbea590 token_type:int token:string app_sandbox:Bool secret:bytes other_uids:Vector<int> = Bool;
account.registerDevice#68976c6f flags:# no_muted:flags.0?true token_type:int token:string app_sandbox:Bool secret:bytes other_uids:Vector<int> = Bool;
account.unregisterDevice#3076c4bf token_type:int token:string other_uids:Vector<int> = Bool;
account.updateNotifySettings#84be5b93 peer:InputNotifyPeer settings:InputPeerNotifySettings = Bool;
account.getNotifySettings#12b3ad31 peer:InputNotifyPeer = PeerNotifySettings;
@ -1364,7 +1364,7 @@ langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLangua
folders.editPeerFolders#6847d0ab folder_peers:Vector<InputFolderPeer> = Updates;
folders.deleteFolder#1c295881 folder_id:int = Updates;
// LAYER 103
// Ports
channels.exportInvite#c7560885 channel:InputChannel = ExportedChatInvite;
// LAYER 102

View File

@ -23,6 +23,7 @@ import shutil
HOME = "compiler/docs"
DESTINATION = "docs/source/telegram"
PYROGRAM_API_DEST = "docs/source/api"
FUNCTIONS_PATH = "pyrogram/api/functions"
TYPES_PATH = "pyrogram/api/types"
@ -117,6 +118,350 @@ def generate(source_path, base):
f.write("\n")
def pyrogram_api():
def get_title_list(s: str) -> list:
return [i.strip() for i in [j.strip() for j in s.split("\n") if j] if i]
# Methods
categories = dict(
utilities="""
Utilities
start
stop
restart
idle
run
add_handler
remove_handler
stop_transmission
export_session_string
""",
messages="""
Messages
send_message
forward_messages
send_photo
send_audio
send_document
send_sticker
send_animated_sticker
send_video
send_animation
send_voice
send_video_note
send_media_group
send_location
send_venue
send_contact
send_cached_media
edit_message_text
edit_message_caption
edit_message_media
edit_message_reply_markup
edit_inline_text
edit_inline_caption
edit_inline_media
edit_inline_reply_markup
send_chat_action
delete_messages
get_messages
get_history
get_history_count
read_history
iter_history
send_poll
vote_poll
stop_poll
retract_vote
download_media
""",
chats="""
Chats
join_chat
leave_chat
kick_chat_member
unban_chat_member
restrict_chat_member
promote_chat_member
export_chat_invite_link
set_chat_photo
delete_chat_photo
set_chat_title
set_chat_description
pin_chat_message
unpin_chat_message
get_chat
get_chat_member
get_chat_members
get_chat_members_count
iter_chat_members
get_dialogs
iter_dialogs
get_dialogs_count
restrict_chat
update_chat_username
archive_chats
unarchive_chats
""",
users="""
Users
get_me
get_users
get_profile_photos
get_profile_photos_count
iter_profile_photos
set_profile_photo
delete_profile_photos
update_username
block_user
unblock_user
""",
contacts="""
Contacts
add_contacts
get_contacts
get_contacts_count
delete_contacts
""",
password="""
Pssword
enable_cloud_password
change_cloud_password
remove_cloud_password
""",
bots="""
Bots
get_inline_bot_results
send_inline_bot_result
answer_callback_query
answer_inline_query
request_callback_answer
send_game
set_game_score
get_game_high_scores
""",
advanced="""
Advanced
send
resolve_peer
save_file
"""
)
root = PYROGRAM_API_DEST + "/methods"
shutil.rmtree(root, ignore_errors=True)
os.mkdir(root)
with open(HOME + "/template/methods.rst") as f:
template = f.read()
with open(root + "/index.rst", "w") as f:
fmt_keys = {}
for k, v in categories.items():
name, *methods = get_title_list(v)
fmt_keys.update({k: "\n ".join("{0} <{0}>".format(m) for m in methods)})
for method in methods:
with open(root + "/{}.rst".format(method), "w") as f2:
title = "{}()".format(method)
f2.write(title + "\n" + "=" * len(title) + "\n\n")
f2.write(".. automethod:: pyrogram.Client.{}()".format(method))
f.write(template.format(**fmt_keys))
# Types
categories = dict(
users_chats="""
Users & Chats
User
Chat
ChatPreview
ChatPhoto
ChatMember
ChatPermissions
Dialog
""",
messages_media="""
Messages & Media
Message
MessageEntity
Photo
Thumbnail
Audio
Document
Animation
Video
Voice
VideoNote
Contact
Location
Venue
Sticker
Game
WebPage
Poll
PollOption
""",
bots_keyboard="""
Bots & Keyboards
ReplyKeyboardMarkup
KeyboardButton
ReplyKeyboardRemove
InlineKeyboardMarkup
InlineKeyboardButton
ForceReply
CallbackQuery
GameHighScore
CallbackGame
""",
input_media="""
Input Media
InputMedia
InputMediaPhoto
InputMediaVideo
InputMediaAudio
InputMediaAnimation
InputMediaDocument
InputPhoneContact
""",
inline_mode="""
Inline Mode
InlineQuery
InlineQueryResult
InlineQueryResultArticle
""",
input_message_content="""
InputMessageContent
InputMessageContent
InputTextMessageContent
"""
)
root = PYROGRAM_API_DEST + "/types"
shutil.rmtree(root, ignore_errors=True)
os.mkdir(root)
with open(HOME + "/template/types.rst") as f:
template = f.read()
with open(root + "/index.rst", "w") as f:
fmt_keys = {}
for k, v in categories.items():
name, *types = get_title_list(v)
fmt_keys.update({k: "\n ".join(types)})
# noinspection PyShadowingBuiltins
for type in types:
with open(root + "/{}.rst".format(type), "w") as f2:
title = "{}".format(type)
f2.write(title + "\n" + "=" * len(title) + "\n\n")
f2.write(".. autoclass:: pyrogram.{}()".format(type))
f.write(template.format(**fmt_keys))
# Bound Methods
categories = dict(
message="""
Message
Message.click
Message.delete
Message.download
Message.forward
Message.pin
Message.edit_text
Message.edit_caption
Message.edit_media
Message.edit_reply_markup
Message.reply_text
Message.reply_animation
Message.reply_audio
Message.reply_cached_media
Message.reply_chat_action
Message.reply_contact
Message.reply_document
Message.reply_game
Message.reply_inline_bot_result
Message.reply_location
Message.reply_media_group
Message.reply_photo
Message.reply_poll
Message.reply_sticker
Message.reply_venue
Message.reply_video
Message.reply_video_note
Message.reply_voice
""",
chat="""
Chat
Chat.archive
Chat.unarchive
Chat.set_title
Chat.set_description
Chat.set_photo
Chat.kick_member
Chat.unban_member
Chat.restrict_member
Chat.promote_member
""",
user="""
User
User.archive
User.unarchive
""",
callback_query="""
Callback Query
CallbackQuery.answer
CallbackQuery.edit_message_text
CallbackQuery.edit_message_caption
CallbackQuery.edit_message_media
CallbackQuery.edit_message_reply_markup
""",
inline_query="""
InlineQuery
InlineQuery.answer
"""
)
root = PYROGRAM_API_DEST + "/bound-methods"
shutil.rmtree(root, ignore_errors=True)
os.mkdir(root)
with open(HOME + "/template/bound-methods.rst") as f:
template = f.read()
with open(root + "/index.rst", "w") as f:
fmt_keys = {}
for k, v in categories.items():
name, *bound_methods = get_title_list(v)
fmt_keys.update({"{}_hlist".format(k): "\n ".join("- :meth:`~{}`".format(bm) for bm in bound_methods)})
fmt_keys.update(
{"{}_toctree".format(k): "\n ".join("{} <{}>".format(bm.split(".")[1], bm) for bm in bound_methods)})
# noinspection PyShadowingBuiltins
for bm in bound_methods:
with open(root + "/{}.rst".format(bm), "w") as f2:
title = "{}()".format(bm)
f2.write(title + "\n" + "=" * len(title) + "\n\n")
f2.write(".. automethod:: pyrogram.{}()".format(bm))
f.write(template.format(**fmt_keys))
def start():
global page_template
global toctree
@ -131,6 +476,7 @@ def start():
generate(TYPES_PATH, TYPES_BASE)
generate(FUNCTIONS_PATH, FUNCTIONS_BASE)
pyrogram_api()
if "__main__" == __name__:
@ -138,5 +484,6 @@ if "__main__" == __name__:
TYPES_PATH = "../../pyrogram/api/types"
HOME = "."
DESTINATION = "../../docs/source/telegram"
PYROGRAM_API_DEST = "../../docs/source/api"
start()

View File

@ -0,0 +1,88 @@
Bound Methods
=============
Some Pyrogram types define what are called bound methods. Bound methods are functions attached to a class which are
accessed via an instance of that class. They make it even easier to call specific methods by automatically inferring
some of the required arguments.
.. code-block:: python
:emphasize-lines: 8
from pyrogram import Client
app = Client("my_account")
@app.on_message()
def hello(client, message)
message.reply("hi")
app.run()
.. currentmodule:: pyrogram
Message
-------
.. hlist::
:columns: 3
{message_hlist}
.. toctree::
:hidden:
{message_toctree}
Chat
----
.. hlist::
:columns: 4
{chat_hlist}
.. toctree::
:hidden:
{chat_toctree}
User
----
.. hlist::
:columns: 2
{user_hlist}
.. toctree::
:hidden:
{user_toctree}
CallbackQuery
-------------
.. hlist::
:columns: 3
{callback_query_hlist}
.. toctree::
:hidden:
{callback_query_toctree}
InlineQuery
-----------
.. hlist::
:columns: 2
{inline_query_hlist}
.. toctree::
:hidden:
{inline_query_toctree}

122
compiler/docs/template/methods.rst vendored Normal file
View File

@ -0,0 +1,122 @@
Available Methods
=================
This page is about Pyrogram methods. All the methods listed here are bound to a :class:`~pyrogram.Client` instance.
.. code-block:: python
:emphasize-lines: 6
from pyrogram import Client
app = Client("my_account")
with app:
app.send_message("haskell", "hi")
.. currentmodule:: pyrogram.Client
Utilities
---------
.. autosummary::
:nosignatures:
{utilities}
.. toctree::
:hidden:
{utilities}
Messages
--------
.. autosummary::
:nosignatures:
{messages}
.. toctree::
:hidden:
{messages}
Chats
-----
.. autosummary::
:nosignatures:
{chats}
.. toctree::
:hidden:
{chats}
Users
-----
.. autosummary::
:nosignatures:
{users}
.. toctree::
:hidden:
{users}
Contacts
--------
.. autosummary::
:nosignatures:
{contacts}
.. toctree::
:hidden:
{contacts}
Password
--------
.. autosummary::
:nosignatures:
{password}
.. toctree::
:hidden:
{password}
Bots
----
.. autosummary::
:nosignatures:
{bots}
.. toctree::
:hidden:
{bots}
Advanced
--------
Learn more about these methods at :doc:`Advanced Usage <../../topics/advanced-usage>`.
.. autosummary::
:nosignatures:
{advanced}
.. toctree::
:hidden:
{advanced}

95
compiler/docs/template/types.rst vendored Normal file
View File

@ -0,0 +1,95 @@
Available Types
===============
This page is about Pyrogram types. All types listed here are accessible through the main package directly.
.. code-block:: python
:emphasize-lines: 1
from pyrogram import User, Message, ...
.. note::
**Optional** fields may not exist when irrelevant -- i.e.: they will contain the value of ``None`` and aren't shown
when, for example, using ``print()``.
.. currentmodule:: pyrogram
Users & Chats
-------------
.. autosummary::
:nosignatures:
{users_chats}
.. toctree::
:hidden:
{users_chats}
Messages & Media
----------------
.. autosummary::
:nosignatures:
{messages_media}
.. toctree::
:hidden:
{messages_media}
Bots & Keyboards
----------------
.. autosummary::
:nosignatures:
{bots_keyboard}
.. toctree::
:hidden:
{bots_keyboard}
Input Media
-----------
.. autosummary::
:nosignatures:
{input_media}
.. toctree::
:hidden:
{input_media}
Inline Mode
-----------
.. autosummary::
:nosignatures:
{inline_mode}
.. toctree::
:hidden:
{inline_mode}
InputMessageContent
-------------------
.. autosummary::
:nosignatures:
{input_message_content}
.. toctree::
:hidden:
{input_message_content}

View File

@ -1,3 +1,4 @@
id message
AUTH_KEY_DUPLICATED Authorization error - you must delete your session file and log in again with your phone number
FILEREF_UPGRADE_NEEDED The file reference has expired - you must obtain the original media message
STICKERSET_INVALID The sticker set is invalid
1 id message
2 AUTH_KEY_DUPLICATED Authorization error - you must delete your session file and log in again with your phone number
3 FILEREF_UPGRADE_NEEDED The file reference has expired - you must obtain the original media message
4 STICKERSET_INVALID The sticker set is invalid

View File

@ -1,164 +0,0 @@
Bound Methods
=============
Some Pyrogram types define what are called bound methods. Bound methods are functions attached to a class which are
accessed via an instance of that class. They make it even easier to call specific methods by automatically inferring
some of the required arguments.
.. code-block:: python
:emphasize-lines: 8
from pyrogram import Client
app = Client("my_account")
@app.on_message()
def hello(client, message)
message.reply("hi")
app.run()
.. currentmodule:: pyrogram
Index
-----
Message
^^^^^^^
.. hlist::
:columns: 3
- :meth:`~Message.click`
- :meth:`~Message.delete`
- :meth:`~Message.download`
- :meth:`~Message.forward`
- :meth:`~Message.pin`
- :meth:`~Message.edit_text`
- :meth:`~Message.edit_caption`
- :meth:`~Message.edit_media`
- :meth:`~Message.edit_reply_markup`
- :meth:`~Message.reply_text`
- :meth:`~Message.reply_animation`
- :meth:`~Message.reply_audio`
- :meth:`~Message.reply_cached_media`
- :meth:`~Message.reply_chat_action`
- :meth:`~Message.reply_contact`
- :meth:`~Message.reply_document`
- :meth:`~Message.reply_game`
- :meth:`~Message.reply_inline_bot_result`
- :meth:`~Message.reply_location`
- :meth:`~Message.reply_media_group`
- :meth:`~Message.reply_photo`
- :meth:`~Message.reply_poll`
- :meth:`~Message.reply_sticker`
- :meth:`~Message.reply_venue`
- :meth:`~Message.reply_video`
- :meth:`~Message.reply_video_note`
- :meth:`~Message.reply_voice`
Chat
^^^^
.. hlist::
:columns: 2
- :meth:`~Chat.archive`
- :meth:`~Chat.unarchive`
- :meth:`~Chat.set_title`
- :meth:`~Chat.set_description`
- :meth:`~Chat.set_photo`
- :meth:`~Chat.kick_member`
- :meth:`~Chat.unban_member`
- :meth:`~Chat.restrict_member`
- :meth:`~Chat.promote_member`
User
^^^^
.. hlist::
:columns: 2
- :meth:`~User.archive`
- :meth:`~User.unarchive`
CallbackQuery
^^^^^^^^^^^^^
.. hlist::
:columns: 3
- :meth:`~CallbackQuery.answer`
- :meth:`~CallbackQuery.edit_message_text`
- :meth:`~CallbackQuery.edit_message_caption`
- :meth:`~CallbackQuery.edit_message_media`
- :meth:`~CallbackQuery.edit_message_reply_markup`
InlineQuery
^^^^^^^^^^^
.. hlist::
:columns: 2
- :meth:`~InlineQuery.answer`
-----
Details
-------
.. Message
.. automethod:: Message.click()
.. automethod:: Message.delete()
.. automethod:: Message.download()
.. automethod:: Message.forward()
.. automethod:: Message.pin()
.. automethod:: Message.edit_text()
.. automethod:: Message.edit_caption()
.. automethod:: Message.edit_media()
.. automethod:: Message.edit_reply_markup()
.. automethod:: Message.reply_text()
.. automethod:: Message.reply_animation()
.. automethod:: Message.reply_audio()
.. automethod:: Message.reply_cached_media()
.. automethod:: Message.reply_chat_action()
.. automethod:: Message.reply_contact()
.. automethod:: Message.reply_document()
.. automethod:: Message.reply_game()
.. automethod:: Message.reply_inline_bot_result()
.. automethod:: Message.reply_location()
.. automethod:: Message.reply_media_group()
.. automethod:: Message.reply_photo()
.. automethod:: Message.reply_poll()
.. automethod:: Message.reply_sticker()
.. automethod:: Message.reply_venue()
.. automethod:: Message.reply_video()
.. automethod:: Message.reply_video_note()
.. automethod:: Message.reply_voice()
.. Chat
.. automethod:: Chat.archive()
.. automethod:: Chat.unarchive()
.. automethod:: Chat.set_title()
.. automethod:: Chat.set_description()
.. automethod:: Chat.set_photo()
.. automethod:: Chat.kick_member()
.. automethod:: Chat.unban_member()
.. automethod:: Chat.restrict_member()
.. automethod:: Chat.promote_member()
.. User
.. automethod:: User.archive()
.. automethod:: User.unarchive()
.. CallbackQuery
.. automethod:: CallbackQuery.answer()
.. automethod:: CallbackQuery.edit_message_text()
.. automethod:: CallbackQuery.edit_message_caption()
.. automethod:: CallbackQuery.edit_message_media()
.. automethod:: CallbackQuery.edit_message_reply_markup()
.. InlineQuery
.. automethod:: InlineQuery.answer()

View File

@ -1,296 +0,0 @@
Available Methods
=================
This page is about Pyrogram methods. All the methods listed here are bound to a :class:`~pyrogram.Client` instance.
.. code-block:: python
:emphasize-lines: 6
from pyrogram import Client
app = Client("my_account")
with app:
app.send_message("haskell", "hi")
.. currentmodule:: pyrogram
Index
-----
Utilities
^^^^^^^^^
.. hlist::
:columns: 4
- :meth:`~Client.start`
- :meth:`~Client.stop`
- :meth:`~Client.restart`
- :meth:`~Client.idle`
- :meth:`~Client.run`
- :meth:`~Client.add_handler`
- :meth:`~Client.remove_handler`
- :meth:`~Client.stop_transmission`
- :meth:`~Client.export_session_string`
Messages
^^^^^^^^
.. hlist::
:columns: 3
- :meth:`~Client.send_message`
- :meth:`~Client.forward_messages`
- :meth:`~Client.send_photo`
- :meth:`~Client.send_audio`
- :meth:`~Client.send_document`
- :meth:`~Client.send_sticker`
- :meth:`~Client.send_animated_sticker`
- :meth:`~Client.send_video`
- :meth:`~Client.send_animation`
- :meth:`~Client.send_voice`
- :meth:`~Client.send_video_note`
- :meth:`~Client.send_media_group`
- :meth:`~Client.send_location`
- :meth:`~Client.send_venue`
- :meth:`~Client.send_contact`
- :meth:`~Client.send_cached_media`
- :meth:`~Client.edit_message_text`
- :meth:`~Client.edit_message_caption`
- :meth:`~Client.edit_message_media`
- :meth:`~Client.edit_message_reply_markup`
- :meth:`~Client.edit_inline_text`
- :meth:`~Client.edit_inline_caption`
- :meth:`~Client.edit_inline_media`
- :meth:`~Client.edit_inline_reply_markup`
- :meth:`~Client.send_chat_action`
- :meth:`~Client.delete_messages`
- :meth:`~Client.get_messages`
- :meth:`~Client.get_history`
- :meth:`~Client.get_history_count`
- :meth:`~Client.read_history`
- :meth:`~Client.iter_history`
- :meth:`~Client.send_poll`
- :meth:`~Client.vote_poll`
- :meth:`~Client.stop_poll`
- :meth:`~Client.retract_vote`
- :meth:`~Client.download_media`
Chats
^^^^^
.. hlist::
:columns: 3
- :meth:`~Client.join_chat`
- :meth:`~Client.leave_chat`
- :meth:`~Client.kick_chat_member`
- :meth:`~Client.unban_chat_member`
- :meth:`~Client.restrict_chat_member`
- :meth:`~Client.promote_chat_member`
- :meth:`~Client.export_chat_invite_link`
- :meth:`~Client.set_chat_photo`
- :meth:`~Client.delete_chat_photo`
- :meth:`~Client.set_chat_title`
- :meth:`~Client.set_chat_description`
- :meth:`~Client.pin_chat_message`
- :meth:`~Client.unpin_chat_message`
- :meth:`~Client.get_chat`
- :meth:`~Client.get_chat_member`
- :meth:`~Client.get_chat_members`
- :meth:`~Client.get_chat_members_count`
- :meth:`~Client.iter_chat_members`
- :meth:`~Client.get_dialogs`
- :meth:`~Client.iter_dialogs`
- :meth:`~Client.get_dialogs_count`
- :meth:`~Client.restrict_chat`
- :meth:`~Client.update_chat_username`
- :meth:`~Client.archive_chats`
- :meth:`~Client.unarchive_chats`
Users
^^^^^
.. hlist::
:columns: 3
- :meth:`~Client.get_me`
- :meth:`~Client.get_users`
- :meth:`~Client.get_profile_photos`
- :meth:`~Client.get_profile_photos_count`
- :meth:`~Client.iter_profile_photos`
- :meth:`~Client.set_profile_photo`
- :meth:`~Client.delete_profile_photos`
- :meth:`~Client.update_username`
- :meth:`~Client.get_user_dc`
- :meth:`~Client.block_user`
- :meth:`~Client.unblock_user`
Contacts
^^^^^^^^
.. hlist::
:columns: 3
- :meth:`~Client.add_contacts`
- :meth:`~Client.get_contacts`
- :meth:`~Client.get_contacts_count`
- :meth:`~Client.delete_contacts`
Password
^^^^^^^^
.. hlist::
:columns: 3
- :meth:`~Client.enable_cloud_password`
- :meth:`~Client.change_cloud_password`
- :meth:`~Client.remove_cloud_password`
Bots
^^^^
.. hlist::
:columns: 3
- :meth:`~Client.get_inline_bot_results`
- :meth:`~Client.send_inline_bot_result`
- :meth:`~Client.answer_callback_query`
- :meth:`~Client.answer_inline_query`
- :meth:`~Client.request_callback_answer`
- :meth:`~Client.send_game`
- :meth:`~Client.set_game_score`
- :meth:`~Client.get_game_high_scores`
Advanced Usage (Raw API)
^^^^^^^^^^^^^^^^^^^^^^^^
Learn more about these methods at :doc:`Advanced Usage <../topics/advanced-usage>`.
.. hlist::
:columns: 4
- :meth:`~Client.send`
- :meth:`~Client.resolve_peer`
- :meth:`~Client.save_file`
-----
Details
-------
.. Utilities
.. automethod:: Client.start()
.. automethod:: Client.stop()
.. automethod:: Client.restart()
.. automethod:: Client.idle()
.. automethod:: Client.run()
.. automethod:: Client.add_handler()
.. automethod:: Client.remove_handler()
.. automethod:: Client.stop_transmission()
.. automethod:: Client.export_session_string()
.. Messages
.. automethod:: Client.send_message()
.. automethod:: Client.forward_messages()
.. automethod:: Client.send_photo()
.. automethod:: Client.send_audio()
.. automethod:: Client.send_document()
.. automethod:: Client.send_sticker()
.. automethod:: Client.send_animated_sticker()
.. automethod:: Client.send_video()
.. automethod:: Client.send_animation()
.. automethod:: Client.send_voice()
.. automethod:: Client.send_video_note()
.. automethod:: Client.send_media_group()
.. automethod:: Client.send_location()
.. automethod:: Client.send_venue()
.. automethod:: Client.send_contact()
.. automethod:: Client.send_cached_media()
.. automethod:: Client.send_chat_action()
.. automethod:: Client.edit_message_text()
.. automethod:: Client.edit_message_caption()
.. automethod:: Client.edit_message_media()
.. automethod:: Client.edit_message_reply_markup()
.. automethod:: Client.edit_inline_text()
.. automethod:: Client.edit_inline_caption()
.. automethod:: Client.edit_inline_media()
.. automethod:: Client.edit_inline_reply_markup()
.. automethod:: Client.delete_messages()
.. automethod:: Client.get_messages()
.. automethod:: Client.get_history()
.. automethod:: Client.get_history_count()
.. automethod:: Client.read_history()
.. automethod:: Client.iter_history()
.. automethod:: Client.send_poll()
.. automethod:: Client.vote_poll()
.. automethod:: Client.stop_poll()
.. automethod:: Client.retract_vote()
.. automethod:: Client.download_media()
.. Chats
.. automethod:: Client.join_chat()
.. automethod:: Client.leave_chat()
.. automethod:: Client.kick_chat_member()
.. automethod:: Client.unban_chat_member()
.. automethod:: Client.restrict_chat_member()
.. automethod:: Client.promote_chat_member()
.. automethod:: Client.export_chat_invite_link()
.. automethod:: Client.set_chat_photo()
.. automethod:: Client.delete_chat_photo()
.. automethod:: Client.set_chat_title()
.. automethod:: Client.set_chat_description()
.. automethod:: Client.pin_chat_message()
.. automethod:: Client.unpin_chat_message()
.. automethod:: Client.get_chat()
.. automethod:: Client.get_chat_member()
.. automethod:: Client.get_chat_members()
.. automethod:: Client.get_chat_members_count()
.. automethod:: Client.iter_chat_members()
.. automethod:: Client.get_dialogs()
.. automethod:: Client.iter_dialogs()
.. automethod:: Client.get_dialogs_count()
.. automethod:: Client.restrict_chat()
.. automethod:: Client.update_chat_username()
.. automethod:: Client.archive_chats()
.. automethod:: Client.unarchive_chats()
.. Users
.. automethod:: Client.get_me()
.. automethod:: Client.get_users()
.. automethod:: Client.get_profile_photos()
.. automethod:: Client.get_profile_photos_count()
.. automethod:: Client.iter_profile_photos()
.. automethod:: Client.set_profile_photo()
.. automethod:: Client.delete_profile_photos()
.. automethod:: Client.update_username()
.. automethod:: Client.get_user_dc()
.. automethod:: Client.block_user()
.. automethod:: Client.unblock_user()
.. Contacts
.. automethod:: Client.add_contacts()
.. automethod:: Client.get_contacts()
.. automethod:: Client.get_contacts_count()
.. automethod:: Client.delete_contacts()
.. Password
.. automethod:: Client.enable_cloud_password()
.. automethod:: Client.change_cloud_password()
.. automethod:: Client.remove_cloud_password()
.. Bots
.. automethod:: Client.get_inline_bot_results()
.. automethod:: Client.send_inline_bot_result()
.. automethod:: Client.answer_callback_query()
.. automethod:: Client.answer_inline_query()
.. automethod:: Client.request_callback_answer()
.. automethod:: Client.send_game()
.. automethod:: Client.set_game_score()
.. automethod:: Client.get_game_high_scores()
.. Advanced Usage
.. automethod:: Client.send()
.. automethod:: Client.resolve_peer()
.. automethod:: Client.save_file()

View File

@ -1,172 +0,0 @@
Available Types
===============
This page is about Pyrogram types. All types listed here are accessible through the main package directly.
.. code-block:: python
:emphasize-lines: 1
from pyrogram import User, Message, ...
.. note::
**Optional** fields may not exist when irrelevant -- i.e.: they will contain the value of ``None`` and aren't shown
when, for example, using ``print()``.
.. currentmodule:: pyrogram
Index
-----
Users & Chats
^^^^^^^^^^^^^
.. hlist::
:columns: 5
- :class:`User`
- :class:`UserStatus`
- :class:`Chat`
- :class:`ChatPreview`
- :class:`ChatPhoto`
- :class:`ChatMember`
- :class:`ChatPermissions`
- :class:`Dialog`
Messages & Media
^^^^^^^^^^^^^^^^
.. hlist::
:columns: 5
- :class:`Message`
- :class:`MessageEntity`
- :class:`Photo`
- :class:`Thumbnail`
- :class:`Audio`
- :class:`Document`
- :class:`Animation`
- :class:`Video`
- :class:`Voice`
- :class:`VideoNote`
- :class:`Contact`
- :class:`Location`
- :class:`Venue`
- :class:`Sticker`
- :class:`Game`
- :class:`WebPage`
- :class:`Poll`
- :class:`PollOption`
Bots & Keyboards
^^^^^^^^^^^^^^^^
.. hlist::
:columns: 4
- :class:`ReplyKeyboardMarkup`
- :class:`KeyboardButton`
- :class:`ReplyKeyboardRemove`
- :class:`InlineKeyboardMarkup`
- :class:`InlineKeyboardButton`
- :class:`ForceReply`
- :class:`CallbackQuery`
- :class:`GameHighScore`
- :class:`CallbackGame`
Input Media
^^^^^^^^^^^
.. hlist::
:columns: 4
- :class:`InputMedia`
- :class:`InputMediaPhoto`
- :class:`InputMediaVideo`
- :class:`InputMediaAudio`
- :class:`InputMediaAnimation`
- :class:`InputMediaDocument`
- :class:`InputPhoneContact`
Inline Mode
^^^^^^^^^^^
.. hlist::
:columns: 3
- :class:`InlineQuery`
- :class:`InlineQueryResult`
- :class:`InlineQueryResultArticle`
InputMessageContent
^^^^^^^^^^^^^^^^^^^
.. hlist::
:columns: 3
- :class:`InputMessageContent`
- :class:`InputTextMessageContent`
-----
Details
-------
.. User & Chats
.. autoclass:: User()
.. autoclass:: UserStatus()
.. autoclass:: Chat()
.. autoclass:: ChatPreview()
.. autoclass:: ChatPhoto()
.. autoclass:: ChatMember()
.. autoclass:: ChatPermissions()
.. autoclass:: Dialog()
.. Messages & Media
.. autoclass:: Message()
.. autoclass:: MessageEntity()
.. autoclass:: Photo()
.. autoclass:: Thumbnail()
.. autoclass:: Audio()
.. autoclass:: Document()
.. autoclass:: Animation()
.. autoclass:: Video()
.. autoclass:: Voice()
.. autoclass:: VideoNote()
.. autoclass:: Contact()
.. autoclass:: Location()
.. autoclass:: Venue()
.. autoclass:: Sticker()
.. autoclass:: Game()
.. autoclass:: WebPage()
.. autoclass:: Poll()
.. autoclass:: PollOption()
.. Bots & Keyboards
.. autoclass:: ReplyKeyboardMarkup()
.. autoclass:: KeyboardButton()
.. autoclass:: ReplyKeyboardRemove()
.. autoclass:: InlineKeyboardMarkup()
.. autoclass:: InlineKeyboardButton()
.. autoclass:: ForceReply()
.. autoclass:: CallbackQuery()
.. autoclass:: GameHighScore()
.. autoclass:: CallbackGame()
.. Input Media
.. autoclass:: InputMedia()
.. autoclass:: InputMediaPhoto()
.. autoclass:: InputMediaVideo()
.. autoclass:: InputMediaAudio()
.. autoclass:: InputMediaAnimation()
.. autoclass:: InputMediaDocument()
.. autoclass:: InputPhoneContact()
.. Inline Mode
.. autoclass:: InlineQuery()
.. autoclass:: InlineQueryResult()
.. autoclass:: InlineQueryResultArticle()
.. InputMessageContent
.. autoclass:: InputMessageContent()
.. autoclass:: InputTextMessageContent()

View File

@ -170,11 +170,11 @@ IP addresses are now kept as aliases.
:widths: auto
:align: center
DC1, "MIA, Miami FL, USA", ``149.154.175.50``, ``2001:b28:f23d:f001::a``
DC1, "MIA, Miami FL, USA", ``149.154.175.53``, ``2001:b28:f23d:f001::a``
DC2, "AMS, Amsterdam, NL", ``149.154.167.51``, ``2001:67c:4e8:f002::a``
DC3*, "MIA, Miami FL, USA", ``149.154.175.100``, ``2001:b28:f23d:f003::a``
DC4, "AMS, Amsterdam, NL", ``149.154.167.91``, ``2001:67c:4e8:f004::a``
DC5, "SIN, Singapore, SG", ``91.108.56.149``, ``2001:b28:f23f:f005::a``
DC5, "SIN, Singapore, SG", ``91.108.56.130``, ``2001:b28:f23f:f005::a``
.. csv-table:: Test Environment
:header: ID, Location, IPv4, IPv6

View File

@ -23,9 +23,9 @@ Welcome to Pyrogram
:caption: API Reference
api/client
api/methods
api/types
api/bound-methods
api/methods/index
api/types/index
api/bound-methods/index
api/handlers
api/decorators
api/errors
@ -142,9 +142,9 @@ API Reference
:columns: 2
- :doc:`Pyrogram Client <api/client>`: Reference details about the Client class.
- :doc:`Available Methods <api/methods>`: List of available high-level methods.
- :doc:`Available Types <api/types>`: List of available high-level types.
- :doc:`Bound Methods <api/bound-methods>`: List of convenient bound methods.
- :doc:`Available Methods <api/methods/index>`: List of available high-level methods.
- :doc:`Available Types <api/types/index>`: List of available high-level types.
- :doc:`Bound Methods <api/bound-methods/index>`: List of convenient bound methods.
Meta
^^^^

View File

@ -1,9 +1,9 @@
Advanced Usage
==============
Pyrogram's API, which consists of well documented convenience :doc:`methods <../api/methods>` and facade
:doc:`types <../api/types>`, exists to provide a much easier interface to the undocumented and often confusing Telegram
API.
Pyrogram's API, which consists of well documented convenience :doc:`methods <../api/methods/index>` and facade
:doc:`types <../api/types/index>`, exists to provide a much easier interface to the undocumented and often confusing
Telegram API.
In this section, you'll be shown the alternative way of communicating with Telegram using Pyrogram: the main "raw"
Telegram API with its functions and types.
@ -23,21 +23,21 @@ some pitfalls to take into consideration when working with the raw API.
Every available high-level methods in Pyrogram is built on top of these raw functions.
Nothing stops you from using the raw functions only, but they are rather complex and
:doc:`plenty of them <../api/methods>` are already re-implemented by providing a much simpler and cleaner interface
which is very similar to the Bot API (yet much more powerful).
:doc:`plenty of them <../api/methods/index>` are already re-implemented by providing a much simpler and cleaner
interface which is very similar to the Bot API (yet much more powerful).
If you think a raw function should be wrapped and added as a high-level method, feel free to ask in our Community_!
Invoking Functions
^^^^^^^^^^^^^^^^^^
Unlike the :doc:`methods <../api/methods>` found in Pyrogram's API, which can be called in the usual simple way,
Unlike the :doc:`methods <../api/methods/index>` found in Pyrogram's API, which can be called in the usual simple way,
functions to be invoked from the raw Telegram API have a different way of usage and are more complex.
First of all, both :doc:`raw functions <../telegram/functions/index>` and :doc:`raw types <../telegram/types/index>` live in their
respective packages (and sub-packages): ``pyrogram.api.functions``, ``pyrogram.api.types``. They all exist as Python
classes, meaning you need to create an instance of each every time you need them and fill them in with the correct
values using named arguments.
First of all, both :doc:`raw functions <../telegram/functions/index>` and :doc:`raw types <../telegram/types/index>`
live in their respective packages (and sub-packages): ``pyrogram.api.functions``, ``pyrogram.api.types``. They all exist
as Python classes, meaning you need to create an instance of each every time you need them and fill them in with the
correct values using named arguments.
Next, to actually invoke the raw function you have to use the :meth:`~pyrogram.Client.send` method provided by the
Client class and pass the function object you created.

View File

@ -9,7 +9,7 @@ For Humans - str(obj)
---------------------
If you want a nicely formatted, human readable JSON representation of any object in the API -- namely, any object from
:doc:`Pyrogram types <../api/types>`, :doc:`raw functions <../telegram/functions/index>` and
:doc:`Pyrogram types <../api/types/index>`, :doc:`raw functions <../telegram/functions/index>` and
:doc:`raw types <../telegram/types/index>` -- you can use use ``str(obj)``.
.. code-block:: python

View File

@ -400,8 +400,10 @@ class Client(Methods, BaseClient):
await self.start()
async def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)):
"""Block the main script execution until a signal (e.g.: from CTRL+C) is received.
Once the signal is received, the client will automatically stop and the main script will continue its execution.
"""Block the main script execution until a signal is received.
Once the signal is received (e.g.: from CTRL+C), the client will automatically stop and the main script will
continue its execution.
This is used after starting one or more clients and is useful for event-driven applications only, that are,
applications which react upon incoming Telegram updates through handlers, rather than executing a set of methods

View File

@ -74,7 +74,7 @@ class Dispatcher:
return await pyrogram.CallbackQuery._parse(self.client, update, users), CallbackQueryHandler
async def user_status_parser(update, users, chats):
return pyrogram.UserStatus._parse(self.client, update.status, update.user_id), UserStatusHandler
return pyrogram.User._parse_user_status(self.client, update), UserStatusHandler
async def inline_query_parser(update, users, chats):
return pyrogram.InlineQuery._parse(self.client, update, users), InlineQueryHandler

View File

@ -21,26 +21,24 @@ from .handler import Handler
class UserStatusHandler(Handler):
"""The UserStatus handler class. Used to handle user status updates (user going online or offline).
It is intended to be used with :meth:`~Client.add_handler`
It is intended to be used with :meth:`~Client.add_handler`.
For a nicer way to register this handler, have a look at the
:meth:`~Client.on_user_status` decorator.
For a nicer way to register this handler, have a look at the :meth:`~Client.on_user_status` decorator.
Parameters:
callback (``callable``):
Pass a function that will be called when a new UserStatus update arrives. It takes *(client, user_status)*
Pass a function that will be called when a new user status update arrives. It takes *(client, user)*
as positional arguments (look at the section below for a detailed description).
filters (:obj:`Filters`):
Pass one or more filters to allow only a subset of messages to be passed
in your callback function.
Pass one or more filters to allow only a subset of users to be passed in your callback function.
Other parameters:
client (:obj:`Client`):
The Client itself, useful when you want to call other API methods inside the user status handler.
user_status (:obj:`UserStatus`):
The received UserStatus update.
user (:obj:`User`):
The user containing the updated status.
"""
def __init__(self, callback: callable, filters=None):

View File

@ -52,13 +52,13 @@ class RestrictChat(BaseClient):
can_send_other_messages (``bool``, *optional*):
Pass True, if the user can send animations, games, stickers and use inline bots,
implies can_send_media_messages.
implies can_send_messages.
can_add_web_page_previews (``bool``, *optional*):
Pass True, if the user may add web page previews to their messages, implies can_send_media_messages.
Pass True, if the user may add web page previews to their messages, implies can_send_messages.
can_send_polls (``bool``, *optional*):
Pass True, if the user can send polls, implies can_send_media_messages.
Pass True, if the user can send polls, implies can_send_messages.
can_change_info (``bool``, *optional*):
Pass True, if the user can change the chat title, photo and other settings.
@ -96,7 +96,6 @@ class RestrictChat(BaseClient):
if can_send_other_messages:
send_messages = None
send_media = None
send_stickers = None
send_gifs = None
send_games = None
@ -104,7 +103,6 @@ class RestrictChat(BaseClient):
if can_add_web_page_previews:
send_messages = None
send_media = None
embed_links = None
if can_send_polls:

View File

@ -65,13 +65,13 @@ class RestrictChatMember(BaseClient):
can_send_other_messages (``bool``, *optional*):
Pass True, if the user can send animations, games, stickers and use inline bots,
implies can_send_media_messages.
implies can_send_messages.
can_add_web_page_previews (``bool``, *optional*):
Pass True, if the user may add web page previews to their messages, implies can_send_media_messages.
Pass True, if the user may add web page previews to their messages, implies can_send_messages.
can_send_polls (``bool``, *optional*):
Pass True, if the user can send polls, implies can_send_media_messages.
Pass True, if the user can send polls, implies can_send_messages.
can_change_info (``bool``, *optional*):
Pass True, if the user can change the chat title, photo and other settings.
@ -109,7 +109,6 @@ class RestrictChatMember(BaseClient):
if can_send_other_messages:
send_messages = None
send_media = None
send_stickers = None
send_gifs = None
send_games = None
@ -117,7 +116,6 @@ class RestrictChatMember(BaseClient):
if can_add_web_page_previews:
send_messages = None
send_media = None
embed_links = None
if can_send_polls:

View File

@ -87,7 +87,7 @@ class DownloadMedia(BaseClient):
Raises:
RPCError: In case of a Telegram RPC error.
``ValueError`` if the message doesn't contain any downloadable media
ValueError: if the message doesn't contain any downloadable media
"""
error_message = "This message doesn't contain any downloadable media"
available_media = ("audio", "document", "photo", "sticker", "animation", "video", "voice", "video_note")

View File

@ -40,7 +40,7 @@ class EditInlineCaption(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -44,7 +44,7 @@ class EditInlineText(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -48,7 +48,7 @@ class EditMessageCaption(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -50,7 +50,7 @@ class EditMessageText(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -72,7 +72,7 @@ class SendAnimation(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -68,7 +68,7 @@ class SendAudio(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -61,7 +61,7 @@ class SendCachedMedia(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -69,7 +69,7 @@ class SendDocument(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -53,7 +53,7 @@ class SendMessage(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -64,7 +64,7 @@ class SendPhoto(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -68,7 +68,7 @@ class SendVideo(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -89,6 +89,7 @@ class SendVideo(BaseClient):
supports_streaming (``bool``, *optional*):
Pass True, if the uploaded video is suitable for streaming.
Defaults to True.
disable_notification (``bool``, *optional*):
Sends the message silently.

View File

@ -64,7 +64,7 @@ class SendVoice(BaseClient):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -21,7 +21,6 @@ from .delete_profile_photos import DeleteProfilePhotos
from .get_me import GetMe
from .get_profile_photos import GetProfilePhotos
from .get_profile_photos_count import GetProfilePhotosCount
from .get_user_dc import GetUserDC
from .get_users import GetUsers
from .iter_profile_photos import IterProfilePhotos
from .set_profile_photo import SetProfilePhoto
@ -38,7 +37,6 @@ class Users(
GetMe,
UpdateUsername,
GetProfilePhotosCount,
GetUserDC,
IterProfilePhotos,
UnblockUser
):

View File

@ -38,7 +38,7 @@ class BlockUser(BaseClient):
"""
return bool(
await self.send(
functions.contact.Block(
functions.contacts.Block(
id=await self.resolve_peer(user_id)
)
)

View File

@ -1,58 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class GetUserDC(BaseClient):
async def get_user_dc(self, user_id: Union[int, str]) -> Union[int, None]:
"""Get the assigned DC (data center) of a user.
.. note::
This information is approximate: it is based on where Telegram stores a user profile pictures and does not
by any means tell you the user location (i.e. a user might travel far away, but will still connect to its
assigned DC). More info at `FAQs <../faq#what-are-the-ip-addresses-of-telegram-data-centers>`_.
Parameters:
user_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
Returns:
``int`` | ``None``: The DC identifier as integer, or None in case it wasn't possible to get it (i.e. the
user has no profile picture or has the privacy setting enabled).
Raises:
RPCError: In case of a Telegram RPC error.
"""
r = await self.send(functions.users.GetUsers(id=[await self.resolve_peer(user_id)]))
if r:
r = r[0]
if r.photo:
if isinstance(r.photo, types.UserProfilePhoto):
return r.photo.dc_id
return None

View File

@ -38,7 +38,7 @@ class UnblockUser(BaseClient):
"""
return bool(
await self.send(
functions.contact.Unblock(
functions.contacts.Unblock(
id=await self.resolve_peer(user_id)
)
)

View File

@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import html
import logging
import re
from collections import OrderedDict
from html.parser import HTMLParser
@ -27,6 +28,8 @@ from pyrogram.api import types
from pyrogram.errors import PeerIdInvalid
from . import utils
log = logging.getLogger(__name__)
class Parser(HTMLParser):
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
@ -94,7 +97,7 @@ class Parser(HTMLParser):
line, offset = self.getpos()
offset += 1
raise ValueError("Unmatched closing tag </{}> at line {}:{}".format(tag, line, offset))
log.warning("Unmatched closing tag </{}> at line {}:{}".format(tag, line, offset))
else:
if not self.tag_entities[tag]:
self.tag_entities.pop(tag)
@ -120,7 +123,7 @@ class HTML:
for tag, entities in parser.tag_entities.items():
unclosed_tags.append("<{}> (x{})".format(tag, len(entities)))
raise ValueError("Unclosed tags: {}".format(", ".join(unclosed_tags)))
log.warning("Unclosed tags: {}".format(", ".join(unclosed_tags)))
entities = []

View File

@ -44,7 +44,7 @@ class Parser:
if mode == "":
return self.markdown.parse(text)
if mode in "markdown":
if mode in ["markdown", "md"]:
return self.markdown.parse(text, True)
if mode == "html":

View File

@ -191,7 +191,7 @@ class CallbackQuery(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -243,7 +243,7 @@ class CallbackQuery(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -42,7 +42,7 @@ class InputMediaAnimation(InputMedia):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -44,7 +44,7 @@ class InputMediaAudio(InputMedia):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -42,7 +42,7 @@ class InputMediaDocument(InputMedia):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
"""

View File

@ -38,7 +38,7 @@ class InputMediaPhoto(InputMedia):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
"""

View File

@ -44,7 +44,7 @@ class InputMediaVideo(InputMedia):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -33,7 +33,7 @@ class InputTextMessageContent(InputMessageContent):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -689,7 +689,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -786,7 +786,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -923,7 +923,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -1052,7 +1052,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -1270,7 +1270,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -1660,7 +1660,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -2058,7 +2058,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -2314,7 +2314,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -2412,7 +2412,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
@ -2469,7 +2469,7 @@ class Message(Object, Update):
parse_mode (``str``, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "markdown" or "md" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.

View File

@ -23,8 +23,7 @@ from .chat_photo import ChatPhoto
from .chat_preview import ChatPreview
from .dialog import Dialog
from .user import User
from .user_status import UserStatus
__all__ = [
"Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "User", "UserStatus"
"Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "User"
]

View File

@ -20,62 +20,81 @@ import html
import pyrogram
from pyrogram.api import types
from .chat_photo import ChatPhoto
from .user_status import UserStatus
from ..object import Object
from ..update import Update
class User(Object):
class User(Object, Update):
"""A Telegram user or bot.
Parameters:
id (``int``):
Unique identifier for this user or bot.
is_self(``bool``):
is_self(``bool``, *optional*):
True, if this user is you yourself.
is_contact(``bool``):
is_contact(``bool``, *optional*):
True, if this user is in your contacts.
is_mutual_contact(``bool``):
is_mutual_contact(``bool``, *optional*):
True, if you both have each other's contact.
is_deleted(``bool``):
is_deleted(``bool``, *optional*):
True, if this user is deleted.
is_bot (``bool``):
is_bot (``bool``, *optional*):
True, if this user is a bot.
is_verified (``bool``):
is_verified (``bool``, *optional*):
True, if this user has been verified by Telegram.
is_restricted (``bool``):
is_restricted (``bool``, *optional*):
True, if this user has been restricted. Bots only.
See *restriction_reason* for details.
is_scam (``bool``):
is_scam (``bool``, *optional*):
True, if this user has been flagged for scam.
is_support (``bool``):
is_support (``bool``, *optional*):
True, if this user is part of the Telegram support team.
first_name (``str``):
first_name (``str``, *optional*):
User's or bot's first name.
status (:obj:`UserStatus <pyrogram.UserStatus>`, *optional*):
User's Last Seen status. Empty for bots.
last_name (``str``, *optional*):
User's or bot's last name.
status (``str``, *optional*):
User's Last Seen & Online status.
Can be one of the following:
"*online*", user is online right now.
"*offline*", user is currently offline.
"*recently*", user with hidden last seen time who was online between 1 second and 2-3 days ago.
"*within_week*", user with hidden last seen time who was online between 2-3 and seven days ago.
"*within_month*", user with hidden last seen time who was online between 6-7 days and a month ago.
"*long_time_ago*", blocked user or user with hidden last seen time who was online more than a month ago.
*None*, for bots.
last_online_date (``int``, *optional*):
Last online date of a user. Only available in case status is "*offline*".
next_offline_date (``int``, *optional*):
Date when a user will automatically go offline. Only available in case status is "*online*".
username (``str``, *optional*):
User's or bot's username.
language_code (``str``, *optional*):
IETF language tag of the user's language.
dc_id (``int``, *optional*):
User's or bot's assigned DC (data center). Available only in case the user has set a public profile photo.
Note that this information is approximate; it is based on where Telegram stores a user profile pictures and
does not by any means tell you the user location (i.e. a user might travel far away, but will still connect
to its assigned DC). More info at `FAQs </faq#what-are-the-ip-addresses-of-telegram-data-centers>`_.
phone_number (``str``, *optional*):
User's phone number.
@ -89,8 +108,8 @@ class User(Object):
__slots__ = [
"id", "is_self", "is_contact", "is_mutual_contact", "is_deleted", "is_bot", "is_verified", "is_restricted",
"is_scam", "is_support", "first_name", "last_name", "status", "username", "language_code", "phone_number",
"photo", "restriction_reason"
"is_scam", "is_support", "first_name", "last_name", "status", "last_online_date", "next_offline_date",
"username", "language_code", "dc_id", "phone_number", "photo", "restriction_reason"
]
def __init__(
@ -98,20 +117,23 @@ class User(Object):
*,
client: "pyrogram.BaseClient" = None,
id: int,
is_self: bool,
is_contact: bool,
is_mutual_contact: bool,
is_deleted: bool,
is_bot: bool,
is_verified: bool,
is_restricted: bool,
is_scam: bool,
is_support: bool,
first_name: str,
is_self: bool = None,
is_contact: bool = None,
is_mutual_contact: bool = None,
is_deleted: bool = None,
is_bot: bool = None,
is_verified: bool = None,
is_restricted: bool = None,
is_scam: bool = None,
is_support: bool = None,
first_name: str = None,
last_name: str = None,
status: UserStatus = None,
status: str = None,
last_online_date: int = None,
next_offline_date: int = None,
username: str = None,
language_code: str = None,
dc_id: int = None,
phone_number: str = None,
photo: ChatPhoto = None,
restriction_reason: str = None
@ -131,8 +153,11 @@ class User(Object):
self.first_name = first_name
self.last_name = last_name
self.status = status
self.last_online_date = last_online_date
self.next_offline_date = next_offline_date
self.username = username
self.language_code = language_code
self.dc_id = dc_id
self.phone_number = phone_number
self.photo = photo
self.restriction_reason = restriction_reason
@ -161,15 +186,57 @@ class User(Object):
is_support=user.support,
first_name=user.first_name,
last_name=user.last_name,
status=UserStatus._parse(client, user.status, user.id, user.bot),
**User._parse_status(user.status, user.bot),
username=user.username,
language_code=user.lang_code,
dc_id=getattr(user.photo, "dc_id", None),
phone_number=user.phone,
photo=ChatPhoto._parse(client, user.photo, user.id),
restriction_reason=user.restriction_reason,
client=client
)
@staticmethod
def _parse_status(user_status: types.UpdateUserStatus, is_bot: bool = False):
if isinstance(user_status, types.UserStatusOnline):
status, date = "online", user_status.expires
elif isinstance(user_status, types.UserStatusOffline):
status, date = "offline", user_status.was_online
elif isinstance(user_status, types.UserStatusRecently):
status, date = "recently", None
elif isinstance(user_status, types.UserStatusLastWeek):
status, date = "within_week", None
elif isinstance(user_status, types.UserStatusLastMonth):
status, date = "within_month", None
else:
status, date = "long_time_ago", None
last_online_date = None
next_offline_date = None
if is_bot:
status = None
if status == "online":
next_offline_date = date
if status == "offline":
last_online_date = date
return {
"status": status,
"last_online_date": last_online_date,
"next_offline_date": next_offline_date
}
@staticmethod
def _parse_user_status(client, user_status: types.UpdateUserStatus):
return User(
id=user_status.user_id,
**User._parse_status(user_status.status),
client=client
)
async def archive(self):
"""Bound method *archive* of :obj:`User`.
@ -215,3 +282,49 @@ class User(Object):
"""
return await self._client.unarchive_chats(self.id)
def block(self):
"""Bound method *block* of :obj:`User`.
Use as a shortcut for:
.. code-block:: python
client.block_user(123456789)
Example:
.. code-block:: python
user.block()
Returns:
True on success.
Raises:
RPCError: In case of a Telegram RPC error.
"""
return self._client.block_user(self.id)
def unblock(self):
"""Bound method *unblock* of :obj:`User`.
Use as a shortcut for:
.. code-block:: python
client.unblock_user(123456789)
Example:
.. code-block:: python
user.unblock()
Returns:
True on success.
Raises:
RPCError: In case of a Telegram RPC error.
"""
return self._client.unblock_user(self.id)

View File

@ -1,116 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import pyrogram
from pyrogram.api import types
from ..object import Object
from ..update import Update
class UserStatus(Object, Update):
"""A User status (Last Seen privacy).
.. note::
You won't see exact last seen timestamps for people with whom you don't share your own. Instead, you get
"recently", "within_week", "within_month" or "long_time_ago" fields set.
Parameters:
user_id (``int``):
User's id.
online (``bool``, *optional*):
True if the user is online in this very moment, None otherwise.
If True, the "date" field will be also set containing the online expiration date (i.e.: the date when a
user will automatically go offline in case of no action by his client).
offline (``bool``, *optional*):
True if the user is offline in this moment and has the Last Seen privacy setting public, None otherwise.
If True, the "date" field will be also set containing the last seen date (i.e.: the date when a user
was online the last time).
date (``int``, *optional*):
Exact date in unix time. Available only in case "online" or "offline" equals to True.
recently (``bool``, *optional*):
True for users with hidden Last Seen privacy that have been online between 1 second and 2-3 days ago,
None otherwise.
within_week (``bool``, *optional*):
True for users with hidden Last Seen privacy that have been online between 2-3 and seven days ago,
None otherwise.
within_month (``bool``, *optional*):
True for users with hidden Last Seen privacy that have been online between 6-7 days and a month ago,
None otherwise.
long_time_ago (``bool``, *optional*):
True for users with hidden Last Seen privacy that have been online more than a month ago (this is also
always shown to blocked users), None otherwise.
"""
__slots__ = ["user_id", "online", "offline", "date", "recently", "within_week", "within_month", "long_time_ago"]
def __init__(
self,
*,
client: "pyrogram.BaseClient" = None,
user_id: int,
online: bool = None,
offline: bool = None,
date: int = None,
recently: bool = None,
within_week: bool = None,
within_month: bool = None,
long_time_ago: bool = None
):
super().__init__(client)
self.user_id = user_id
self.online = online
self.offline = offline
self.date = date
self.recently = recently
self.within_week = within_week
self.within_month = within_month
self.long_time_ago = long_time_ago
@staticmethod
def _parse(client, user_status, user_id: int, is_bot: bool = False):
if is_bot:
return None
status = UserStatus(user_id=user_id, client=client)
if isinstance(user_status, types.UserStatusOnline):
status.online = True
status.date = user_status.expires
elif isinstance(user_status, types.UserStatusOffline):
status.offline = True
status.date = user_status.was_online
elif isinstance(user_status, types.UserStatusRecently):
status.recently = True
elif isinstance(user_status, types.UserStatusLastWeek):
status.within_week = True
elif isinstance(user_status, types.UserStatusLastMonth):
status.within_month = True
else:
status.long_time_ago = True
return status

View File

@ -32,12 +32,12 @@ class RPCError(Exception):
NAME = None
MESSAGE = "{x}"
def __init__(self, x: int or RawRPCError, rpc_name: str, is_unknown: bool):
super().__init__("[{} {}]: {} ({})".format(
def __init__(self, x: int or RawRPCError = None, rpc_name: str = None, is_unknown: bool = False):
super().__init__("[{} {}]: {} {}".format(
self.CODE,
self.ID or self.NAME,
self.MESSAGE.format(x=x),
'caused by "{}"'.format(rpc_name)
'(caused by "{}")'.format(rpc_name) if rpc_name else ""
))
try:

View File

@ -26,11 +26,11 @@ class DataCenter:
}
PROD = {
1: "149.154.175.50",
1: "149.154.175.53",
2: "149.154.167.51",
3: "149.154.175.100",
4: "149.154.167.91",
5: "91.108.56.149",
5: "91.108.56.130",
121: "95.213.217.195"
}

View File

@ -39,8 +39,12 @@ with open("README.md", encoding="utf-8") as f:
class Clean(Command):
DIST = ["./build", "./dist", "./Pyrogram.egg-info"]
API = ["pyrogram/api/errors/exceptions", "pyrogram/api/functions", "pyrogram/api/types", "pyrogram/api/all.py"]
DOCS = ["docs/source/telegram", "docs/build"]
API = ["pyrogram/errors/exceptions", "pyrogram/api/functions", "pyrogram/api/types", "pyrogram/api/all.py"]
DOCS = [
"docs/source/telegram", "docs/build", "docs/source/api/methods", "docs/source/api/types",
"docs/source/api/bound-methods"
]
ALL = DIST + API + DOCS
description = "Clean generated files"
@ -122,7 +126,6 @@ class Generate(Command):
if len(argv) > 1 and argv[1] in ["bdist_wheel", "install", "develop"]:
api_compiler.start()
error_compiler.start()
docs_compiler.start()
setup(
name="Pyrogram",