fix: ignore interactive VK chat messages

This commit is contained in:
nyan404 committed 2026-09-06 18:31:36 +03:00
1 parent ae04d7cb09
commit ed85f94e8d
2 files changed
+21

No files matched your search

+3
View File
@@ -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:
+18
View File
@@ -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] | самостоятельно"