From efee7133015be377fd19ec80c9bee168abd63650 Mon Sep 17 00:00:00 2001 From: deadzilla Date: Sat, 11 Jul 2026 23:59:41 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20TextHelpCommand=20=D0=BF=D0=BE=D0=BA?= =?UTF-8?q?=D0=B0=D0=B7=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=20standalone-=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20(=D0=B1=D0=B5=D0=B7=20co?= =?UTF-8?q?g)=20=D0=B5=D1=81=D0=BB=D0=B8=20=D0=BE=D0=BD=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B5=20hidden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 6 +++++- tests/test_help_command.py | 30 +++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index e6706cd..5c3aaba 100644 --- a/bot.py +++ b/bot.py @@ -38,7 +38,11 @@ class TextHelpCommand(commands.HelpCommand): for cog_or_none, cog_commands in mapping.items(): if cog_or_none is None: - # Команды без cog (встроенная help) — пропускаем + # Standalone-команды (без cog) — показываем если не hidden + for command in cog_commands: + if not command.hidden: + desc = command.short_doc or "" + lines.append(f" !{command.name} - {desc}") continue for command in cog_commands: if not command.hidden: diff --git a/tests/test_help_command.py b/tests/test_help_command.py index 20e7dfa..4af09f6 100644 --- a/tests/test_help_command.py +++ b/tests/test_help_command.py @@ -94,12 +94,12 @@ class TestSendBotHelp: assert "hidden_cmd" not in message @pytest.mark.asyncio - async def test_send_bot_help_skips_none_cog(self, help_command) -> None: - """Команды без cog (None) должны пропускаться.""" + async def test_send_bot_help_shows_none_cog(self, help_command) -> None: + """Команды без cog (None) должны показываться, если не hidden.""" cmd = MagicMock() - cmd.name = "built_in" + cmd.name = "standalone" cmd.hidden = False - cmd.short_doc = "Встроенная" + cmd.short_doc = "Самостоятельная" destination = MagicMock() destination.send = AsyncMock(return_value=None) @@ -110,7 +110,27 @@ class TestSendBotHelp: destination.send.assert_awaited_once() message = destination.send.call_args[0][0] - assert "built_in" not in message + assert "standalone" in message + assert "Самостоятельная" in message + + @pytest.mark.asyncio + async def test_send_bot_help_hides_none_cog_hidden_cmd(self, help_command) -> None: + """Hidden команды без cog не должны показываться.""" + cmd = MagicMock() + cmd.name = "hidden_standalone" + cmd.hidden = True + cmd.short_doc = "Скрытая" + + destination = MagicMock() + destination.send = AsyncMock(return_value=None) + + with patch.object(help_command, "get_destination", return_value=destination): + mapping = {None: [cmd]} + await help_command.send_bot_help(mapping) + + destination.send.assert_awaited_once() + message = destination.send.call_args[0][0] + assert "hidden_standalone" not in message @pytest.mark.asyncio async def test_send_bot_help_empty_doc(self, help_command) -> None: