fix: TextHelpCommand показывает standalone-команды (без cog) если они не hidden
This commit is contained in:
parent
49cb1a430b
commit
efee713301
6
bot.py
6
bot.py
@ -38,7 +38,11 @@ class TextHelpCommand(commands.HelpCommand):
|
|||||||
|
|
||||||
for cog_or_none, cog_commands in mapping.items():
|
for cog_or_none, cog_commands in mapping.items():
|
||||||
if cog_or_none is None:
|
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
|
continue
|
||||||
for command in cog_commands:
|
for command in cog_commands:
|
||||||
if not command.hidden:
|
if not command.hidden:
|
||||||
|
|||||||
@ -94,12 +94,12 @@ class TestSendBotHelp:
|
|||||||
assert "hidden_cmd" not in message
|
assert "hidden_cmd" not in message
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_bot_help_skips_none_cog(self, help_command) -> None:
|
async def test_send_bot_help_shows_none_cog(self, help_command) -> None:
|
||||||
"""Команды без cog (None) должны пропускаться."""
|
"""Команды без cog (None) должны показываться, если не hidden."""
|
||||||
cmd = MagicMock()
|
cmd = MagicMock()
|
||||||
cmd.name = "built_in"
|
cmd.name = "standalone"
|
||||||
cmd.hidden = False
|
cmd.hidden = False
|
||||||
cmd.short_doc = "Встроенная"
|
cmd.short_doc = "Самостоятельная"
|
||||||
|
|
||||||
destination = MagicMock()
|
destination = MagicMock()
|
||||||
destination.send = AsyncMock(return_value=None)
|
destination.send = AsyncMock(return_value=None)
|
||||||
@ -110,7 +110,27 @@ class TestSendBotHelp:
|
|||||||
|
|
||||||
destination.send.assert_awaited_once()
|
destination.send.assert_awaited_once()
|
||||||
message = destination.send.call_args[0][0]
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_send_bot_help_empty_doc(self, help_command) -> None:
|
async def test_send_bot_help_empty_doc(self, help_command) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user