replace command prefix with bot mention

This commit is contained in:
HgO 2024-04-18 10:18:37 +02:00
parent 928d587a45
commit acd9f1764d
9 changed files with 111 additions and 80 deletions

View file

@ -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.

View file

@ -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:

View file

@ -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,

View file

@ -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],

View file

@ -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:

View file

@ -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"

View file

@ -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:

View file

@ -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("")

View file

@ -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,