|
|
@@ -713,6 +713,46 @@ class TestChatTypeMapping:
|
|
|
assert event.source.chat_type == "channel"
|
|
|
|
|
|
|
|
|
+# -- require_mention --
|
|
|
+
|
|
|
+class TestRequireMention:
|
|
|
+ """require_mention gates channels only — a DM is already addressed at the bot."""
|
|
|
+
|
|
|
+ def _adapter(self):
|
|
|
+ adapter = _make_adapter()
|
|
|
+ adapter.chatto_config.allow_all_users.value = True
|
|
|
+ adapter.chatto_config.require_mention.value = True
|
|
|
+ adapter.me = _make_user("bot-user-id", "hermes_bot")
|
|
|
+ adapter._user_cache["user-1"] = _make_user("user-1", "alice")
|
|
|
+ adapter.handle_message = AsyncMock()
|
|
|
+ return adapter
|
|
|
+
|
|
|
+ async def _dispatch(self, adapter, room_id, body):
|
|
|
+ payload = _make_posted_payload(room_id=room_id)
|
|
|
+ payload.fetch_message = AsyncMock(
|
|
|
+ return_value=_make_message(body=body, room_id=room_id))
|
|
|
+ await adapter._dispatch_message_posted(payload)
|
|
|
+
|
|
|
+ async def test_channel_without_mention_is_discarded(self):
|
|
|
+ adapter = self._adapter()
|
|
|
+ adapter._room_kinds["room-1"] = RoomKind.CHANNEL
|
|
|
+ await self._dispatch(adapter, "room-1", "hi there")
|
|
|
+ adapter.handle_message.assert_not_called()
|
|
|
+
|
|
|
+ async def test_channel_with_mention_is_answered(self):
|
|
|
+ adapter = self._adapter()
|
|
|
+ adapter._room_kinds["room-1"] = RoomKind.CHANNEL
|
|
|
+ await self._dispatch(adapter, "room-1", "@hermes_bot hi there")
|
|
|
+ adapter.handle_message.assert_called_once()
|
|
|
+
|
|
|
+ async def test_dm_is_answered_without_a_mention(self):
|
|
|
+ """The point of the room_kind check: require_mention must not mute DMs."""
|
|
|
+ adapter = self._adapter()
|
|
|
+ adapter._room_kinds["dm-1"] = RoomKind.DM
|
|
|
+ await self._dispatch(adapter, "dm-1", "hi there")
|
|
|
+ adapter.handle_message.assert_called_once()
|
|
|
+
|
|
|
+
|
|
|
# -- Inbound attachments --
|
|
|
|
|
|
class TestInboundAttachments:
|