diff --git a/compiler/error/source/403_FORBIDDEN.tsv b/compiler/error/source/403_FORBIDDEN.tsv index a2d06832..34433da7 100644 --- a/compiler/error/source/403_FORBIDDEN.tsv +++ b/compiler/error/source/403_FORBIDDEN.tsv @@ -1,4 +1,5 @@ id message CHAT_WRITE_FORBIDDEN You don't have rights to send messages in this chat RIGHT_FORBIDDEN One or more admin rights can't be applied to this kind of chat (channel/supergroup) -CHAT_ADMIN_INVITE_REQUIRED You don't have rights to invite other users \ No newline at end of file +CHAT_ADMIN_INVITE_REQUIRED You don't have rights to invite other users +MESSAGE_DELETE_FORBIDDEN You don't have rights to delete messages in this chat \ No newline at end of file diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 4f9866e0..8471dd82 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès pyrogram_types.Messages: +def parse_deleted_messages(update) -> pyrogram_types.Messages: + messages = update.messages + channel_id = getattr(update, "channel_id", None) + parsed_messages = [] for message in messages: @@ -864,42 +870,40 @@ def parse_profile_photos(photos): ) -def parse_callback_query(client, callback_query, users): - peer = callback_query.peer +def parse_callback_query(client, update, users): + message = None + inline_message_id = None - if isinstance(peer, types.PeerUser): - peer_id = peer.user_id - elif isinstance(peer, types.PeerChat): - peer_id = -peer.chat_id - else: - peer_id = int("-100" + str(peer.channel_id)) + if isinstance(update, types.UpdateBotCallbackQuery): + peer = update.peer - return pyrogram_types.CallbackQuery( - id=str(callback_query.query_id), - from_user=parse_user(users[callback_query.user_id]), - message=client.get_messages(peer_id, callback_query.msg_id), - chat_instance=str(callback_query.chat_instance), - data=callback_query.data.decode(), - game_short_name=callback_query.game_short_name, - client=client - ) + if isinstance(peer, types.PeerUser): + peer_id = peer.user_id + elif isinstance(peer, types.PeerChat): + peer_id = -peer.chat_id + else: + peer_id = int("-100" + str(peer.channel_id)) - -def parse_inline_callback_query(client, callback_query, users): - return pyrogram_types.CallbackQuery( - id=str(callback_query.query_id), - from_user=parse_user(users[callback_query.user_id]), - chat_instance=str(callback_query.chat_instance), - inline_message_id=b64encode( + message = client.get_messages(peer_id, update.msg_id) + elif isinstance(update, types.UpdateInlineBotCallbackQuery): + inline_message_id = b64encode( pack( " + + Use as a shortcut for: + + .. code-block:: python + + client.edit_message_text( + chat_id=message.chat.id, + message_id=message.message_id, + text="hello", + ) + + Example: + .. code-block:: python + + message.edit("hello") + + Args: + text (``str``): + New text of the message. + + parse_mode (``str``, *optional*): + Use :obj:`MARKDOWN ` or :obj:`HTML ` + if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your message. + Defaults to Markdown. + + disable_web_page_preview (``bool``, *optional*): + Disables link previews for links in this message. + + reply_markup (:obj:`InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + Returns: + On success, the edited :obj:`Message ` is returned. + + Raises: + :class:`Error ` in case of a Telegram RPC error. + """ + return self._client.edit_message_text( + chat_id=self.chat.id, + message_id=self.message_id, + text=text, + parse_mode=parse_mode, + disable_web_page_preview=disable_web_page_preview, + reply_markup=reply_markup + ) + def forward(self, chat_id: int or str, disable_notification: bool = None): @@ -560,7 +634,7 @@ class Message(Object): else: raise ValueError("The message doesn't contain any keyboard") - def download(self, file_name: str = "", block: bool = True): + def download(self, file_name: str = "", block: bool = True, progress: callable = None, progress_args: tuple = None): """Bound method *download* of :obj:`Message `. Use as a shortcut for: @@ -585,6 +659,15 @@ class Message(Object): Blocks the code execution until the file has been downloaded. Defaults to True. + progress (``callable``): + Pass a callback function to view the download progress. + The function must take *(client, current, total, \*args)* as positional arguments (look at the section + below for a detailed description). + + progress_args (``tuple``): + Extra custom arguments for the progress callback function. Useful, for example, if you want to pass + a chat_id and a message_id in order to edit a message with the updated progress. + Returns: On success, the absolute path of the downloaded file as string is returned, None otherwise. @@ -595,5 +678,7 @@ class Message(Object): return self._client.download_media( message=self, file_name=file_name, - block=block + block=block, + progress=progress, + progress_args=progress_args, ) diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 8020bc71..41f64a40 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -37,7 +37,7 @@ class Connection: 4: TCPIntermediateO } - def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, mode: int = 1): + def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, mode: int = 3): self.dc_id = dc_id self.ipv6 = ipv6 self.proxy = proxy