From acd9f1764d76b0fc83b2e0843d8e47f95910966b Mon Sep 17 00:00:00 2001 From: HgO Date: Thu, 18 Apr 2024 10:18:37 +0200 Subject: [PATCH] replace command prefix with bot mention --- SETUP.md | 8 +- config.sample.yaml | 3 - matrix_alertbot/callback.py | 23 ++-- matrix_alertbot/config.py | 4 - tests/resources/config/config.full.yml | 3 - tests/test_callback.py | 144 ++++++++++++++++--------- tests/test_command.py | 1 - tests/test_config.py | 4 - tests/test_matrix.py | 1 - 9 files changed, 111 insertions(+), 80 deletions(-) diff --git a/SETUP.md b/SETUP.md index d06bf4e..6312cb0 100644 --- a/SETUP.md +++ b/SETUP.md @@ -112,12 +112,12 @@ matrix-alertbot other-config.yaml Invite the bot to a room and it should accept the invite and join. -Matrix AlertBot will process any message starting with the prefix defined in the config. By default, this prefix is `!alert` . Let's test this now. +Matrix AlertBot will process any message where its name is mentionned. Let's test this now. After the bot has successfully joined the room, try sending the following in a message: ``` -!alert help +@bot_name help ``` The bot should reply with an help message, explaining how to handle alerts. @@ -129,7 +129,7 @@ or by reacting with certain emojis. For instance, if you reply to the alert with: ``` -!alert ack +@bot_name ack ``` This will create a silence for this alert until it is resolved. @@ -138,7 +138,7 @@ You can at any moment reply to the alert with the following to remove the silence: ``` -!alert unack +@bot_name unack ``` Removing a reaction to an alert will also remove the silence. diff --git a/config.sample.yaml b/config.sample.yaml index cd01557..c03c1d6 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -2,9 +2,6 @@ # Below you will find various config sections and options # Default values are shown -# The string to prefix messages with to talk to the bot in group chats -command_prefix: "!alert" - # Options for connecting to the bot's Matrix account matrix: accounts: diff --git a/matrix_alertbot/callback.py b/matrix_alertbot/callback.py index 378d68f..8db1d3c 100644 --- a/matrix_alertbot/callback.py +++ b/matrix_alertbot/callback.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +import re from diskcache import Cache from nio.client import AsyncClient @@ -58,7 +59,6 @@ class Callbacks: self.cache = cache self.alertmanager_client = alertmanager_client self.config = config - self.command_prefix = config.command_prefix async def message(self, room: MatrixRoom, event: RoomMessageText) -> None: """Callback for when a message event is received @@ -88,13 +88,22 @@ class Callbacks: f"Event ID {event.event_id} | Sender {event.sender} | " f"Message received: {msg}" ) - # Process as message if in a public room without command prefix - has_command_prefix = msg.startswith(self.command_prefix) - if not has_command_prefix: + + user_id_patterns = [] + for user_id in self.config.user_ids: + user, homeserver = user_id.split(":") + username = user[1:] + user_id_patterns.append(rf"@?{username}(:{homeserver})?") + + pattern = re.compile( + rf"(^|\s+)({'|'.join(user_id_patterns)})(\s+|$)", + re.IGNORECASE | re.MULTILINE, + ) + if pattern.search(msg) is None: logger.debug( f"Bot {self.matrix_client.user_id} | Room ID {room.room_id} | " f"Event ID {event.event_id} | Sender {event.sender} | " - f"Cannot process message: Command prefix {self.command_prefix} not provided." + f"Cannot process message: Bot was not mentionned." ) return @@ -112,8 +121,8 @@ class Callbacks: f"Command received is in reply to event ID {reacted_to_event_id}" ) - # Remove the command prefix - cmd = msg[len(self.command_prefix) :] + # Remove the mention of the bot + cmd = pattern.sub(" ", msg).strip() try: command = CommandFactory.create( cmd, diff --git a/matrix_alertbot/config.py b/matrix_alertbot/config.py index aabf2ea..820fc15 100644 --- a/matrix_alertbot/config.py +++ b/matrix_alertbot/config.py @@ -197,10 +197,6 @@ class Config: "Supplied both webhook.socket and both webhook.address" ) - self.command_prefix: str = ( - self._get_cfg(["command_prefix"], default="!alert") + " " - ) - def _get_cfg( self, path: List[str], diff --git a/tests/resources/config/config.full.yml b/tests/resources/config/config.full.yml index ce3e341..7119d7e 100644 --- a/tests/resources/config/config.full.yml +++ b/tests/resources/config/config.full.yml @@ -2,9 +2,6 @@ # Below you will find various config sections and options # Default values are shown -# The string to prefix messages with to talk to the bot in group chats -command_prefix: "!alert" - # Options for connecting to the bot's Matrix account matrix: accounts: diff --git a/tests/test_callback.py b/tests/test_callback.py index 2dffd0e..4fdbab1 100644 --- a/tests/test_callback.py +++ b/tests/test_callback.py @@ -36,7 +36,6 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): self.fake_config.allowed_rooms = [self.fake_room.room_id] self.fake_config.allowed_reactions = ["🤫", "🤗"] self.fake_config.insult_reactions = ["🤗"] - self.fake_config.command_prefix = "!alert " self.fake_config.user_ids = [self.fake_matrix_client.user_id] self.fake_matrix_client_pool = Mock( @@ -101,8 +100,8 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): ) @patch.object(matrix_alertbot.callback.CommandFactory, "create", autospec=True) - async def test_message_without_prefix(self, fake_command_create: Mock) -> None: - """Tests the callback for RoomMessageText without any command prefix""" + async def test_message_without_mention(self, fake_command_create: Mock) -> None: + """Tests the callback for RoomMessageText without any mention of the bot""" # Tests that the bot process messages in the room fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.sender = "@some_other_fake_user:example.com" @@ -117,12 +116,12 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.command, "HelpCommand", autospec=True) async def test_message_help_client_not_in_pool(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText without any command prefix""" + """Tests the callback for RoomMessageText without any mention of the bot""" # Tests that the bot process messages in the room fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.event_id = "some event id" fake_message_event.sender = "@some_other_fake_user:example.com" - fake_message_event.body = "!alert help" + fake_message_event.body = "@fake_user help" fake_message_event.source = {"content": {}} self.fake_matrix_client_pool.matrix_client = None @@ -134,15 +133,15 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): fake_command.assert_not_called() @patch.object(matrix_alertbot.command, "HelpCommand", autospec=True) - async def test_message_help_not_in_reply_with_prefix( + async def test_message_help_not_in_reply_with_mention( self, fake_command: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.event_id = "some event id" fake_message_event.sender = "@some_other_fake_user:example.com" - fake_message_event.body = "!alert help" + fake_message_event.body = "@fake_user help" fake_message_event.source = {"content": {}} # Pretend that we received a text message event @@ -162,14 +161,14 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): fake_command.return_value.process.assert_called_once() @patch.object(matrix_alertbot.command, "HelpCommand", autospec=True) - async def test_message_help_in_reply_with_prefix(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + async def test_message_help_in_reply_with_mention(self, fake_command: Mock) -> None: + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.event_id = "some event id" fake_message_event.sender = "@some_other_fake_user:example.com" - fake_message_event.body = "!alert help" + fake_message_event.body = "@fake_user help" fake_message_event.source = { "content": { "m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}} @@ -194,7 +193,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.command.CommandFactory, "create", autospec=True) async def test_ignore_message_sent_by_bot(self, fake_create_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_message_event = Mock(spec=nio.RoomMessageText) @@ -210,7 +209,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_ignore_message_sent_on_unauthorized_room( self, fake_create_command: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command self.fake_room.room_id = "!unauthorizedroom@example.com" @@ -225,15 +224,15 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): fake_create_command.assert_not_called() @patch.object(matrix_alertbot.command, "AckAlertCommand", autospec=True) - async def test_message_ack_not_in_reply_with_prefix( + async def test_message_ack_not_in_reply_with_mention( self, fake_command: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.event_id = "some event id" fake_message_event.sender = "@some_other_fake_user:example.com" - fake_message_event.body = "!alert ack" + fake_message_event.body = "@fake_user ack" fake_message_event.source = {"content": {}} # Pretend that we received a text message event @@ -243,13 +242,48 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): fake_command.assert_not_called() @patch.object(matrix_alertbot.command, "AckAlertCommand", autospec=True) - async def test_message_ack_in_reply_with_prefix(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + async def test_message_ack_in_reply_with_full_mention( + self, fake_command: Mock + ) -> None: + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.event_id = "some event id" fake_message_event.sender = "@some_other_fake_user:example.com" - fake_message_event.body = "!alert ack" + fake_message_event.body = "@fake_user:example.com ack" + fake_message_event.source = { + "content": { + "m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}} + } + } + + # Pretend that we received a text message event + await self.callbacks.message(self.fake_room, fake_message_event) + + # Check that the command was not executed + fake_command.assert_called_once_with( + self.fake_matrix_client, + self.fake_cache, + self.fake_alertmanager_client, + self.fake_config, + self.fake_room, + fake_message_event.sender, + fake_message_event.event_id, + "some alert event id", + (), + ) + fake_command.return_value.process.assert_called_once() + + @patch.object(matrix_alertbot.command, "AckAlertCommand", autospec=True) + async def test_message_ack_in_reply_with_short_mention( + self, fake_command: Mock + ) -> None: + """Tests the callback for RoomMessageText with a mention of the bot""" + # Tests that the bot process messages in the room that contain a command + fake_message_event = Mock(spec=nio.RoomMessageText) + fake_message_event.event_id = "some event id" + fake_message_event.sender = "@some_other_fake_user:example.com" + fake_message_event.body = "fake_user ack" fake_message_event.source = { "content": { "m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}} @@ -274,15 +308,15 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): fake_command.return_value.process.assert_called_once() @patch.object(matrix_alertbot.callback, "UnackAlertCommand", autospec=True) - async def test_message_unack_not_in_reply_with_prefix( + async def test_message_unack_not_in_reply_with_mention( self, fake_command: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.event_id = "some event id" fake_message_event.sender = "@some_other_fake_user:example.com" - fake_message_event.body = "!alert unack" + fake_message_event.body = "@fake_user unack" fake_message_event.source = {"content": {}} # Pretend that we received a text message event @@ -292,13 +326,15 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): fake_command.assert_not_called() @patch.object(matrix_alertbot.command, "UnackAlertCommand", autospec=True) - async def test_message_unack_in_reply_with_prefix(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + async def test_message_unack_in_reply_with_mention( + self, fake_command: Mock + ) -> None: + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.event_id = "some event id" fake_message_event.sender = "@some_other_fake_user:example.com" - fake_message_event.body = "!alert unack" + fake_message_event.body = "@fake_user unack" fake_message_event.source = { "content": { "m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}} @@ -327,12 +363,12 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_message_raise_exception( self, fake_command: Mock, fake_logger ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_message_event = Mock(spec=nio.RoomMessageText) fake_message_event.event_id = "some event id" fake_message_event.sender = "@some_other_fake_user:example.com" - fake_message_event.body = "!alert ack" + fake_message_event.body = "@fake_user ack" fake_message_event.source = { "content": { "m.relates_to": {"m.in_reply_to": {"event_id": "some alert event id"}} @@ -364,7 +400,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True) async def test_reaction_client_not_in_pool(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event = Mock(spec=nio.RoomMessageText) fake_alert_event.event_id = "some alert event id" @@ -390,8 +426,10 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.callback, "AngryUserCommand", autospec=True) @patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True) - async def test_reaction_to_existing_alert(self, fake_command: Mock, fake_angry_user_command) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + async def test_reaction_to_existing_alert( + self, fake_command: Mock, fake_angry_user_command + ) -> None: + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event = Mock(spec=nio.RoomMessageText) fake_alert_event.event_id = "some alert event id" @@ -433,7 +471,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_insult_reaction( self, fake_command: Mock, fake_angry_user_command: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event = Mock(spec=nio.RoomMessageText) fake_alert_event.event_id = "some alert event id" @@ -481,7 +519,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True) async def test_reaction_to_inexistent_event(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event_id = "some alert event id" @@ -509,7 +547,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_reaction_to_event_not_from_bot_user( self, fake_command: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event = Mock(spec=nio.RoomMessageText) fake_alert_event.event_id = "some alert event id" @@ -541,7 +579,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_reaction_raise_exception( self, fake_command: Mock, fake_logger: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event = Mock(spec=nio.RoomMessageText) fake_alert_event.event_id = "some alert event id" @@ -584,7 +622,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True) async def test_reaction_unknown(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event_id = "some alert event id" @@ -604,7 +642,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.callback, "AckAlertCommand", autospec=True) async def test_ignore_reaction_sent_by_bot_user(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event_id = "some alert event id" @@ -626,7 +664,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_ignore_reaction_in_unauthorized_room( self, fake_command: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command self.fake_room.room_id = "!unauthorizedroom@example.com" @@ -648,7 +686,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.callback, "UnackAlertCommand", autospec=True) async def test_redaction_client_not_in_pool(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event_id = "some alert event id" @@ -670,7 +708,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.callback, "UnackAlertCommand", autospec=True) async def test_redaction(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event_id = "some alert event id" @@ -703,7 +741,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_redaction_raise_exception( self, fake_command: Mock, fake_logger ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_alert_event_id = "some alert event id" @@ -739,7 +777,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): @patch.object(matrix_alertbot.callback, "UnackAlertCommand", autospec=True) async def test_ignore_redaction_sent_by_bot_user(self, fake_command: Mock) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_redaction_event = Mock(spec=nio.RedactionEvent) fake_redaction_event.sender = self.fake_matrix_client.user_id @@ -758,7 +796,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_ignore_redaction_in_unauthorized_room( self, fake_command: Mock ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command self.fake_room.room_id = "!unauthorizedroom@example.com" @@ -776,7 +814,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): self.fake_cache.__getitem__.assert_not_called() async def test_key_verification_start(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -800,7 +838,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): self.fake_matrix_client.to_device.assert_called_once_with(fake_sas.share_key()) async def test_key_verification_start_with_emoji_not_supported(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -824,7 +862,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_key_verification_start_with_accept_key_verification_error( self, ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -854,7 +892,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): async def test_key_verification_start_with_to_device_error( self, ) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -880,7 +918,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): self.fake_matrix_client.to_device.assert_called_once_with(fake_sas.share_key()) async def test_key_verification_cancel(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_key_verification_event = Mock(spec=nio.KeyVerificationCancel) fake_key_verification_event.sender = "@some_other_fake_user:example.com" @@ -892,7 +930,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): # Check that we attempted to execute the command async def test_key_verification_confirm(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -917,7 +955,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): ) async def test_key_verification_confirm_with_error(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -946,7 +984,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): ) async def test_key_verification_end(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -967,7 +1005,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): self.fake_matrix_client.to_device.assert_called_once_with(fake_sas.get_mac()) async def test_key_verification_end_with_missing_transaction_id(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -987,7 +1025,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): self.fake_matrix_client.to_device.assert_not_called() async def test_key_verification_end_with_mac_error(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" @@ -1008,7 +1046,7 @@ class CallbacksTestCase(unittest.IsolatedAsyncioTestCase): self.fake_matrix_client.to_device.assert_not_called() async def test_key_verification_end_with_to_device_error(self) -> None: - """Tests the callback for RoomMessageText with the command prefix""" + """Tests the callback for RoomMessageText with a mention of the bot""" # Tests that the bot process messages in the room that contain a command fake_transaction_id = "fake transaction id" diff --git a/tests/test_command.py b/tests/test_command.py index 0eabeaf..b1f7834 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -109,7 +109,6 @@ 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.command_prefix = "!alert " @patch.object(matrix_alertbot.command.AckAlertCommand, "process") async def test_process_ack_command(self, fake_ack: Mock) -> None: diff --git a/tests/test_config.py b/tests/test_config.py index eaf9646..685c3f3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -91,8 +91,6 @@ class ConfigTestCase(unittest.TestCase): self.assertIsNone(config.template_dir) - self.assertEqual("!alert ", config.command_prefix) - @patch("os.path.isdir") @patch("os.path.exists") @patch("os.mkdir") @@ -157,8 +155,6 @@ class ConfigTestCase(unittest.TestCase): self.assertEqual("data/templates", config.template_dir) - self.assertEqual("!alert ", config.command_prefix) - def test_read_config_raise_config_error(self) -> None: with self.assertRaises(ParseConfigError): Config("") diff --git a/tests/test_matrix.py b/tests/test_matrix.py index 4555bde..dd09981 100644 --- a/tests/test_matrix.py +++ b/tests/test_matrix.py @@ -62,7 +62,6 @@ class MatrixClientPoolTestCase(unittest.IsolatedAsyncioTestCase): self.fake_account_config_2.token_file = "account2.token.secret" self.fake_config = Mock(spec=Config) self.fake_config.store_dir = "/dev/null" - self.fake_config.command_prefix = "!alert" self.fake_config.accounts = [ self.fake_account_config_1, self.fake_account_config_2,