diff --git a/app/belki/vk_bot.py b/app/belki/vk_bot.py index 4f17777..723605f 100644 --- a/app/belki/vk_bot.py +++ b/app/belki/vk_bot.py @@ -891,6 +891,9 @@ class BelkiBot: title=title, invited_by=message.get("from_id")) elif action in {"chat_kick_user", "chat_leave_user"}: self.conversation_store.mark_removed(int(peer_id), action) + # Interactive commands are private-message only. Keep the registry + # event handling above, but never start a dialog or reply in chats. + return sender_id = message.get("from_id", message.get("sender_id", peer_id)) text = self._button_text(message) or message.get("text", "") if peer_id is not None: diff --git a/tests/test_vk_bot.py b/tests/test_vk_bot.py index e6e7aeb..7c21fb7 100644 --- a/tests/test_vk_bot.py +++ b/tests/test_vk_bot.py @@ -13,6 +13,24 @@ from app.belki.vk_bot import ( class VkBotTests(unittest.TestCase): + def test_public_chat_messages_are_ignored_but_invite_is_registered(self): + class Client: + def __init__(self): self.sent = [] + def call(self, method, params): return {"title": "Тестовая беседа"} + def send(self, *args, **kwargs): self.sent.append((args, kwargs)) + class Store: + def __init__(self): self.items = [] + def upsert_conversation(self, **kwargs): self.items.append(kwargs) + bot = BelkiBot.__new__(BelkiBot) + bot.client = Client(); bot.conversation_store = Store() + bot.application_dialog = bot.dialog = object() + bot.handle_event({"type": "message_new", "object": {"message": { + "peer_id": 2000000007, "from_id": 42, "text": "/help", + "action": {"type": "chat_invite_user"}, + }}}) + self.assertEqual(bot.client.sent, []) + self.assertEqual(bot.conversation_store.items[0]["title"], "Тестовая беседа") + def test_parse_coaching_command(self): command = parse_text_command( "/лу 15.08 11:00 11:20 | Дикая Вишня [1604614] | Серолап [1617140] | самостоятельно"