mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
add aliases for edit/delete reply markup to Message (#662)
* add aliases for edit/delete reply markup to Message * add towncrier patch note * add missed towncrier patch note description
This commit is contained in:
parent
04bbc8211c
commit
c1f605c6f5
3 changed files with 78 additions and 0 deletions
1
CHANGES/662.feature
Normal file
1
CHANGES/662.feature
Normal file
|
|
@ -0,0 +1 @@
|
|||
add aliases for edit/delete reply markup to Message
|
||||
|
|
@ -14,6 +14,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|||
CopyMessage,
|
||||
DeleteMessage,
|
||||
EditMessageCaption,
|
||||
EditMessageReplyMarkup,
|
||||
EditMessageText,
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
|
|
@ -1788,6 +1789,21 @@ class Message(TelegramObject):
|
|||
reply_markup=reply_markup,
|
||||
)
|
||||
|
||||
def edit_reply_markup(
|
||||
self,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
) -> EditMessageReplyMarkup:
|
||||
from ..methods import EditMessageReplyMarkup
|
||||
|
||||
return EditMessageReplyMarkup(
|
||||
chat_id=self.chat.id,
|
||||
message_id=self.message_id,
|
||||
reply_markup=reply_markup,
|
||||
)
|
||||
|
||||
def delete_reply_markup(self) -> EditMessageReplyMarkup:
|
||||
return self.edit_reply_markup(reply_markup=None)
|
||||
|
||||
def edit_caption(
|
||||
self,
|
||||
caption: str,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from aiogram.methods import (
|
|||
CopyMessage,
|
||||
DeleteMessage,
|
||||
EditMessageCaption,
|
||||
EditMessageReplyMarkup,
|
||||
EditMessageText,
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
|
|
@ -36,6 +37,8 @@ from aiogram.types import (
|
|||
Document,
|
||||
EncryptedCredentials,
|
||||
Game,
|
||||
InlineKeyboardButton,
|
||||
InlineKeyboardMarkup,
|
||||
Invoice,
|
||||
Location,
|
||||
MessageAutoDeleteTimerChanged,
|
||||
|
|
@ -561,6 +564,64 @@ class TestMessage:
|
|||
assert isinstance(method, EditMessageText)
|
||||
assert method.chat_id == message.chat.id
|
||||
|
||||
def test_edit_reply_markup(self):
|
||||
reply_markup = InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="test",
|
||||
callback_data="test",
|
||||
),
|
||||
],
|
||||
]
|
||||
)
|
||||
reply_markup_new = InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="test2",
|
||||
callback_data="test2",
|
||||
),
|
||||
],
|
||||
]
|
||||
)
|
||||
|
||||
message = Message(
|
||||
message_id=42,
|
||||
chat=Chat(id=42, type="private"),
|
||||
date=datetime.datetime.now(),
|
||||
reply_markup=reply_markup,
|
||||
)
|
||||
method = message.edit_reply_markup(
|
||||
reply_markup=reply_markup_new,
|
||||
)
|
||||
assert isinstance(method, EditMessageReplyMarkup)
|
||||
assert method.reply_markup == reply_markup_new
|
||||
assert method.chat_id == message.chat.id
|
||||
|
||||
def test_delete_reply_markup(self):
|
||||
reply_markup = InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="test",
|
||||
callback_data="test",
|
||||
),
|
||||
],
|
||||
]
|
||||
)
|
||||
|
||||
message = Message(
|
||||
message_id=42,
|
||||
chat=Chat(id=42, type="private"),
|
||||
date=datetime.datetime.now(),
|
||||
reply_markup=reply_markup,
|
||||
)
|
||||
method = message.delete_reply_markup()
|
||||
assert isinstance(method, EditMessageReplyMarkup)
|
||||
assert method.reply_markup is None
|
||||
assert method.chat_id == message.chat.id
|
||||
|
||||
def test_edit_caption(self):
|
||||
message = Message(
|
||||
message_id=42, chat=Chat(id=42, type="private"), date=datetime.datetime.now()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue