From e5016a0666e45562e57f4e98e808f7e5d6894938 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 28 Aug 2023 22:26:36 +0300 Subject: [PATCH] Fix `Message.send_copy` method for stories Fixed an issue with the `Message.send_copy` method, which was not functioning properly with story-type messages. The `ForwardMessage` logic has been added to the method to enable copying of stories, in addition to other types. Tests and documentation have also been updated to reflect these changes. --- CHANGES/1286.bugfi.rst | 1 + aiogram/types/message.py | 8 ++++++++ docs/dispatcher/dispatcher.rst | 4 ++-- tests/test_api/test_types/test_message.py | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 CHANGES/1286.bugfi.rst diff --git a/CHANGES/1286.bugfi.rst b/CHANGES/1286.bugfi.rst new file mode 100644 index 00000000..a9cfe0d9 --- /dev/null +++ b/CHANGES/1286.bugfi.rst @@ -0,0 +1 @@ +Fixed :code:`Message.send_copy` method, which was not working properly with stories, so not you can copy stories too (forwards messages). diff --git a/aiogram/types/message.py b/aiogram/types/message.py index d1b68235..5ad60d5b 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -2804,6 +2804,7 @@ class Message(TelegramObject): allow_sending_without_reply: Optional[bool] = None, message_thread_id: Optional[int] = None, ) -> Union[ + ForwardMessage, SendAnimation, SendAudio, SendContact, @@ -2839,6 +2840,7 @@ class Message(TelegramObject): :return: """ from ..methods import ( + ForwardMessage, SendAnimation, SendAudio, SendContact, @@ -2957,6 +2959,12 @@ class Message(TelegramObject): return SendDice( **kwargs, ).as_(self._bot) + if self.story: + return ForwardMessage( + from_chat_id=self.chat.id, + message_id=self.message_id, + **kwargs, + ).as_(self._bot) raise TypeError("This type of message can't be copied.") diff --git a/docs/dispatcher/dispatcher.rst b/docs/dispatcher/dispatcher.rst index 502422c0..2bb192de 100644 --- a/docs/dispatcher/dispatcher.rst +++ b/docs/dispatcher/dispatcher.rst @@ -4,14 +4,14 @@ Dispatcher Dispatcher is root :obj:`Router` and in code Dispatcher can be used directly for routing updates or attach another routers into dispatcher. -Here is only listed base information about Dispatcher. All about writing handlers, filters and etc. you can found in next pages: +Here is only listed base information about Dispatcher. All about writing handlers, filters and etc. you can find in next pages: - :ref:`Router ` - :ref:`Filtering events` .. autoclass:: aiogram.dispatcher.dispatcher.Dispatcher - :members: __init__, feed_update, feed_raw_update, feed_webhook_update, start_polling, run_polling + :members: __init__, feed_update, feed_raw_update, feed_webhook_update, start_polling, run_polling, stop_polling Simple usage diff --git a/tests/test_api/test_types/test_message.py b/tests/test_api/test_types/test_message.py index 04e25578..0b600146 100644 --- a/tests/test_api/test_types/test_message.py +++ b/tests/test_api/test_types/test_message.py @@ -649,6 +649,7 @@ class TestMessage: [TEST_MESSAGE_CONTACT, SendContact], [TEST_MESSAGE_VENUE, SendVenue], [TEST_MESSAGE_LOCATION, SendLocation], + [TEST_MESSAGE_STORY, ForwardMessage], [TEST_MESSAGE_NEW_CHAT_MEMBERS, None], [TEST_MESSAGE_LEFT_CHAT_MEMBER, None], [TEST_MESSAGE_INVOICE, None],