diff --git a/matrix_alertbot/command.py b/matrix_alertbot/command.py index 3969566..7998bcd 100644 --- a/matrix_alertbot/command.py +++ b/matrix_alertbot/command.py @@ -238,22 +238,34 @@ class HelpCommand(BaseCommand): async def process(self) -> None: """Show the help text""" logger.debug(f"Displaying help to room {self.room.display_name}") - if not self.args: + if len(self.args) == 0: text = ( - "Hello, I am a bot made with matrix-nio! Use `help commands` to view " + "Hello, I am a bot made with matrix-nio! Use 'help commands' to view " "available commands." ) - await send_text_to_room(self.matrix_client, self.room.room_id, text) - return - - topic = self.args[0] - if topic == "rules": - text = "These are the rules!" - elif topic == "commands": - text = "Available commands: ..." else: - text = "Unknown help topic!" - await send_text_to_room(self.matrix_client, self.room.room_id, text) + topic = self.args[0] + if topic == "commands": + reactions = " ".join( + sorted(self.config.allowed_reactions - self.config.insult_reactions) + ) + text = ( + "Here is the list of available commands:\n" + "- help: Display this help message.\n" + "- ack: Create a silence for the alert that is replied to.\n" + "- unack: Remove a silence for the alert that is replied to.\n\n" + "You can also react with an emoji to an alert to create a silence. " + "Removing a reaction will remove the silence.\n" + f"Here is the list of allowed emoji to trigger a silence: {reactions}\n" + ) + else: + text = ( + "I'm sorry, I don't know much about this topic. " + "You can type 'help commands' to view a list of available commands." + ) + await send_text_to_room( + self.matrix_client, self.room.room_id, text, notice=False + ) class AngryUserCommand(BaseCommand): diff --git a/tests/test_command.py b/tests/test_command.py index 8cef56a..ad68b08 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -109,6 +109,7 @@ class CommandTestCase(unittest.IsolatedAsyncioTestCase): # We don't spec config, as it doesn't currently have well defined attributes self.fake_config = Mock() self.fake_config.allowed_rooms = [self.fake_room.room_id] + self.fake_config.allowed_reactions = {"🤫", "😶", "🤐"} @patch.object(matrix_alertbot.command.AckAlertCommand, "process") async def test_process_ack_command(self, fake_ack: Mock) -> None: @@ -648,29 +649,6 @@ class CommandTestCase(unittest.IsolatedAsyncioTestCase): _, _, text = fake_send_text_to_room.call_args.args self.assertIn("help commands", text) - @patch.object(matrix_alertbot.command, "send_text_to_room") - async def test_help_with_rules_topic(self, fake_send_text_to_room: Mock) -> None: - """Tests the callback for InviteMemberEvents""" - # Tests that the bot attempts to join a room after being invited to it - - command = HelpCommand( - self.fake_matrix_client, - self.fake_cache, - self.fake_alertmanager_client, - self.fake_config, - self.fake_room, - self.fake_sender, - self.fake_event_id, - ("rules",), - ) - - await command.process() - - # Check that we attempted to create silences - fake_send_text_to_room.assert_called_once() - _, _, text = fake_send_text_to_room.call_args.args - self.assertIn("rules!", text) - @patch.object(matrix_alertbot.command, "send_text_to_room") async def test_help_with_commands_topic(self, fake_send_text_to_room: Mock) -> None: """Tests the callback for InviteMemberEvents""" @@ -692,7 +670,7 @@ class CommandTestCase(unittest.IsolatedAsyncioTestCase): # Check that we attempted to create silences fake_send_text_to_room.assert_called_once() _, _, text = fake_send_text_to_room.call_args.args - self.assertIn("Available commands", text) + self.assertIn("Here is the list of available commands", text) @patch.object(matrix_alertbot.command, "send_text_to_room") async def test_angry_user(self, fake_send_text_to_room: Mock) -> None: @@ -744,7 +722,7 @@ class CommandTestCase(unittest.IsolatedAsyncioTestCase): # Check that we attempted to create silences fake_send_text_to_room.assert_called_once() _, _, text = fake_send_text_to_room.call_args.args - self.assertEqual("Unknown help topic!", text) + self.assertIn("I'm sorry, I don't know much about this topic.", text) @patch.object(matrix_alertbot.command, "send_text_to_room") async def test_unknown_command(self, fake_send_text_to_room: Mock) -> None: