Add @help remove with confirmation prompt

This commit is contained in:
Jared Miller 2026-02-15 10:03:25 -05:00
parent 24154a052c
commit e361050b93
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 52 additions and 2 deletions

View file

@ -159,8 +159,34 @@ async def _on_edit_admin(
async def _cmd_remove(player: Player, args: str) -> None:
"""Placeholder for topic removal."""
await player.send("Not yet implemented.\r\n")
"""Remove a help topic."""
name = args.strip()
if not name:
await player.send("Usage: @help remove <topic>\r\n")
return
if name not in _help_topics:
await player.send(f"Topic '{name}' not found.\r\n")
return
await player.send(f"Remove topic '{name}'? [y/N]: ")
player.pending_input = lambda p, line: _on_remove_confirm(p, line, name)
async def _on_remove_confirm(player: Player, line: str, name: str) -> None:
if line.strip().lower() not in ("y", "yes"):
await player.send("Cancelled.\r\n")
return
# Remove from memory
_help_topics.pop(name, None)
# Remove file
path = Path(__file__).resolve().parents[2] / "content" / "help" / f"{name}.toml"
if path.exists():
path.unlink()
await player.send(f"Topic '{name}' removed.\r\n")
register(

View file

@ -227,3 +227,27 @@ async def test_at_help_edit_prompts_title(admin_player):
output = "".join(c[0][0] for c in admin_player.writer.write.call_args_list)
# Should show current title as default
assert "combat primer" in output
@pytest.mark.asyncio
async def test_at_help_remove_unknown_topic(admin_player):
await commands.dispatch(admin_player, "@help remove bogus")
output = "".join(c[0][0] for c in admin_player.writer.write.call_args_list)
assert "not found" in output.lower()
@pytest.mark.asyncio
async def test_at_help_remove_no_args(admin_player):
await commands.dispatch(admin_player, "@help remove")
output = "".join(c[0][0] for c in admin_player.writer.write.call_args_list)
assert "usage" in output.lower()
@pytest.mark.asyncio
async def test_at_help_remove_prompts_confirmation(admin_player):
_help_topics["combat"] = HelpTopic(
name="combat", body="fight", title="combat primer"
)
await commands.dispatch(admin_player, "@help remove combat")
output = "".join(c[0][0] for c in admin_player.writer.write.call_args_list)
assert "y/n" in output.lower() or "confirm" in output.lower()