From 37d8f8023646acf57789f0c2b82f249a63816b18 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 30 Oct 2026 14:52:27 +0200 Subject: [PATCH] Revert "fix(posts): keep copy button after press, count every tap" This reverts commit 992d8645cf8c8dacb1b7853f72189db2d4700c9a. --- VERSION | 2 +- bot.py | 12 ++++++++---- tests/test_writer_features.py | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/VERSION b/VERSION index cfdc2af..68cc106 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0+86 +0.1.0+85 diff --git a/bot.py b/bot.py index cc59fba..6c642e5 100644 --- a/bot.py +++ b/bot.py @@ -760,12 +760,16 @@ async def clear_command(message: Message, state: FSMContext) -> None: @router.callback_query(F.data.startswith("copy_post:")) async def post_copy_pressed(callback: CallbackQuery) -> None: - """Кнопка «Скопировать»: текст копирует сам Telegram (copy_text), здесь пишем только статистику. - - Кнопку не убираем — она работает бесконечно, каждое нажатие считается отдельно. - """ + """Кнопка «Скопировать»: текст копирует сам Telegram (copy_text), здесь пишем только статистику.""" if callback.from_user is not None: await asyncio.to_thread(analytics.record_event, callback.from_user.id, "generation", "post_copy") + message = callback.message + if isinstance(message, Message): + try: + await message.edit_reply_markup(reply_markup=None) + except Exception as exc: + if "message is not modified" not in str(exc).casefold(): + logger.debug("Copy button removal failed: %s", str(exc)[:120]) await callback.answer() diff --git a/tests/test_writer_features.py b/tests/test_writer_features.py index 60e7e34..78c78aa 100644 --- a/tests/test_writer_features.py +++ b/tests/test_writer_features.py @@ -1236,17 +1236,18 @@ class PostCopyButtonTests(unittest.IsolatedAsyncioTestCase): self.assertEqual(button.copy_text.text, "Пост А") self.assertEqual(button.callback_data, "copy_post:0") - async def test_copy_callback_records_event_and_keeps_button(self): + async def test_copy_callback_records_event_and_clears_button(self): callback = SimpleNamespace( from_user=SimpleNamespace(id=42), message=MagicMock(spec=bot.Message), answer=AsyncMock(), ) + callback.message.edit_reply_markup = AsyncMock() with patch.object(bot.asyncio, "to_thread", new=AsyncMock()) as to_thread: await bot.post_copy_pressed(cast(Any, callback)) to_thread.assert_awaited_once() self.assertEqual(to_thread.await_args.args[1:], (42, "generation", "post_copy")) - callback.message.edit_reply_markup.assert_not_awaited() + callback.message.edit_reply_markup.assert_awaited_once_with(reply_markup=None) callback.answer.assert_awaited_once()