feat(command_manager): enhance help command channel access handling

- Updated the `CommandManager` to respect the `channels` override for the help command, ensuring it checks channel permissions directly when processing help requests.
- Refactored the logic to fall back to global `monitor_channels` only when no specific help command is loaded, improving channel-specific access control.
- Added unit tests to verify the correct behavior of the help command in disallowed channels, ensuring it only responds in permitted contexts.
This commit is contained in:
agessaman committed 2026-06-28 09:52:37 -07:00
1 parent 0c37f48a45
commit b8decd8d66
2 files changed
+34 -2

No files matched your search

+24
View File
@@ -264,6 +264,30 @@ class TestCheckKeywords:
matches = manager.check_keywords(msg)
assert any(trigger == "help" for trigger, _ in matches)
def test_help_channel_override_blocks_disallowed_channel(self, cm_bot):
"""[Help_Command] channels override must gate the special help path too.
The path bypasses the plugin loop (where is_channel_allowed is enforced), so
it has to consult the help command's channel access directly.
"""
cm_bot.config.set("Keywords", "help", "Help: ping, test")
mock_help = MagicMock()
mock_help.help_enabled = True
mock_help.keywords = ["help"]
# Disallow the channel the message arrives on.
mock_help.is_channel_allowed = Mock(return_value=False)
mock_help.should_execute = Mock(return_value=False)
manager = make_manager(cm_bot, commands={"help": mock_help})
msg = mock_message(content="help", channel="general", is_dm=False)
matches = manager.check_keywords(msg)
assert not any(trigger == "help" for trigger, _ in matches)
# Allowed channel still responds.
mock_help.is_channel_allowed = Mock(return_value=True)
matches = manager.check_keywords(mock_message(content="help", channel="general", is_dm=False))
assert any(trigger == "help" for trigger, _ in matches)
class TestGetHelpForCommand:
"""Tests for command-specific help."""