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

Add edit, edit_caption, edit_media and edit_reply_markup bound methods to the CallbackQuery type

This commit is contained in:
Dan 2019-06-14 02:46:27 +02:00
parent 22199b0fe5
commit da4ff268a4
3 changed files with 187 additions and 1 deletions

View File

@ -81,9 +81,13 @@ CallbackQuery
^^^^^^^^^^^^^ ^^^^^^^^^^^^^
.. hlist:: .. hlist::
:columns: 2 :columns: 5
- :meth:`~CallbackQuery.answer` - :meth:`~CallbackQuery.answer`
- :meth:`~CallbackQuery.edit`
- :meth:`~CallbackQuery.edit_caption`
- :meth:`~CallbackQuery.edit_media`
- :meth:`~CallbackQuery.edit_reply_markup`
InlineQuery InlineQuery
^^^^^^^^^^^ ^^^^^^^^^^^
@ -137,6 +141,10 @@ Details
.. CallbackQuery .. CallbackQuery
.. automethod:: CallbackQuery.answer() .. automethod:: CallbackQuery.answer()
.. automethod:: CallbackQuery.edit()
.. automethod:: CallbackQuery.edit_caption()
.. automethod:: CallbackQuery.edit_media()
.. automethod:: CallbackQuery.edit_reply_markup()
.. InlineQuery .. InlineQuery
.. automethod:: InlineQuery.answer() .. automethod:: InlineQuery.answer()

View File

@ -159,3 +159,9 @@ class BaseClient:
def edit_message_text(self, *args, **kwargs): def edit_message_text(self, *args, **kwargs):
pass pass
def edit_message_media(self, *args, **kwargs):
pass
def edit_message_reply_markup(self, *args, **kwargs):
pass

View File

@ -172,3 +172,175 @@ class CallbackQuery(Object, Update):
url=url, url=url,
cache_time=cache_time cache_time=cache_time
) )
def edit(
self,
text: str,
parse_mode: str = "",
disable_web_page_preview: bool = None,
reply_markup: "pyrogram.InlineKeyboardMarkup" = None
) -> Union["pyrogram.Message", bool]:
"""Bound method *edit* of :obj:`CallbackQuery`.
Parameters:
text (``str``):
New text of the message.
parse_mode (``str``, *optional*):
Pass "markdown" or "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:
:obj:`Message` | ``bool``: On success, if the edited message was sent by the bot, the edited message is
returned, otherwise True is returned (message sent via the bot, as inline query result).
Raises:
RPCError: In case of a Telegram RPC error.
"""
chat_id = None
message_id = None
inline_message_id = None
if self.message is not None:
chat_id = self.message.chat.id
message_id = self.message.message_id
if self.inline_message_id is not None:
inline_message_id = self.inline_message_id
return self._client.edit_message_text(
text=text,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
parse_mode=parse_mode,
disable_web_page_preview=disable_web_page_preview,
reply_markup=reply_markup
)
def edit_caption(
self,
caption: str,
parse_mode: str = "",
reply_markup: "pyrogram.InlineKeyboardMarkup" = None
) -> Union["pyrogram.Message", bool]:
"""Bound method *edit_caption* of :obj:`Message`.
Parameters:
caption (``str``):
New caption of the message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.
Returns:
:obj:`Message` | ``bool``: On success, if the edited message was sent by the bot, the edited message is
returned, otherwise True is returned (message sent via the bot, as inline query result).
Raises:
RPCError: In case of a Telegram RPC error.
"""
chat_id = None
message_id = None
inline_message_id = None
if self.message is not None:
chat_id = self.message.chat.id
message_id = self.message.message_id
if self.inline_message_id is not None:
inline_message_id = self.inline_message_id
return self._client.edit_message_text(
text=caption,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
parse_mode=parse_mode,
reply_markup=reply_markup
)
def edit_media(
self,
media: "pyrogram.InputMedia",
reply_markup: "pyrogram.InlineKeyboardMarkup" = None
) -> Union["pyrogram.Message", bool]:
"""Bound method *edit_media* of :obj:`Message`.
Parameters:
media (:obj:`InputMedia`):
One of the InputMedia objects describing an animation, audio, document, photo or video.
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.
Returns:
:obj:`Message` | ``bool``: On success, if the edited message was sent by the bot, the edited message is
returned, otherwise True is returned (message sent via the bot, as inline query result).
Raises:
RPCError: In case of a Telegram RPC error.
"""
chat_id = None
message_id = None
inline_message_id = None
if self.message is not None:
chat_id = self.message.chat.id
message_id = self.message.message_id
if self.inline_message_id is not None:
inline_message_id = self.inline_message_id
return self._client.edit_message_media(
media=media,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id,
reply_markup=reply_markup
)
def edit_reply_markup(
self,
reply_markup: "pyrogram.InlineKeyboardMarkup" = None
) -> Union["pyrogram.Message", bool]:
"""Bound method *edit_reply_markup* of :obj:`Message`.
Parameters:
reply_markup (:obj:`InlineKeyboardMarkup`):
An InlineKeyboardMarkup object.
Returns:
:obj:`Message` | ``bool``: On success, if the edited message was sent by the bot, the edited message is
returned, otherwise True is returned (message sent via the bot, as inline query result).
Raises:
RPCError: In case of a Telegram RPC error.
"""
chat_id = None
message_id = None
inline_message_id = None
if self.message is not None:
chat_id = self.message.chat.id
message_id = self.message.message_id
if self.inline_message_id is not None:
inline_message_id = self.inline_message_id
return self._client.edit_message_reply_markup(
reply_markup=reply_markup,
chat_id=chat_id,
message_id=message_id,
inline_message_id=inline_message_id
)