feat: schedule VK conversation messages
This commit is contained in:
1 parent
f7c5eb994e
commit
4590070bbc
9 files changed
+314
-2
No files matched your search
@@ -21,6 +21,7 @@ from .image_host import ImageHostClient
|
||||
from .identity import Identity, IdentityDirectory
|
||||
from .applications import APPLICATION_TYPES, ApplicationError, ApplicationStore, validate_application
|
||||
from .google_sheets_export import GoogleSheetsExportService
|
||||
from .vk_scheduler import VkConversationStore, VkScheduler
|
||||
|
||||
"""
|
||||
Обработка VK-бота:
|
||||
@@ -853,6 +854,8 @@ class BelkiBot:
|
||||
self.application_store = ApplicationStore.from_environment()
|
||||
self.application_dialog = ApplicationDialog(identities, self.application_store)
|
||||
self.application_exporter = GoogleSheetsExportService(self.application_store)
|
||||
self.conversation_store = VkConversationStore.from_environment()
|
||||
self.scheduler = VkScheduler(self.conversation_store, self.client.send)
|
||||
|
||||
def response_for_text(self, text: str) -> str:
|
||||
"""Обработка текстового сообщения и возврат ответа."""
|
||||
@@ -874,6 +877,14 @@ class BelkiBot:
|
||||
return
|
||||
message = event.get("object", {}).get("message", event.get("object", {}))
|
||||
peer_id = message.get("peer_id")
|
||||
action = (message.get("action") or {}).get("type")
|
||||
if peer_id and int(peer_id) >= 2_000_000_000:
|
||||
chat_id = int(peer_id) - 2_000_000_000
|
||||
if action in {"chat_invite_user", "chat_invite_user_by_link"}:
|
||||
self.conversation_store.upsert_conversation(peer_id=int(peer_id), chat_id=chat_id,
|
||||
title=(message.get("chat_settings") or {}).get("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)
|
||||
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:
|
||||
@@ -963,6 +974,7 @@ class BelkiBot:
|
||||
self.application_exporter.sync_pending()
|
||||
time.sleep(15)
|
||||
threading.Thread(target=notification_loop, name="belki-application-notifier", daemon=True).start()
|
||||
threading.Thread(target=self.scheduler.run_forever, name="belki-vk-scheduler", daemon=True).start()
|
||||
for event in self.events():
|
||||
self.handle_event(event)
|
||||
|
||||
|
||||
Reference in new issue
Block a user