feat: mirror VK photos to image host

This commit is contained in:
nyan404 committed 2026-08-16 15:58:15 +03:00
1 parent 20b434dbcd
commit f6c2275af3
7 files changed
+98 -6

No files matched your search

+12 -1
View File
@@ -11,6 +11,7 @@ from urllib.request import Request, urlopen
from .api import ApiError, calculate_payload
from .history import CalculationStore
from .image_host import ImageHostClient
from .identity import Identity, IdentityDirectory
@@ -307,6 +308,7 @@ class BelkiBot:
IdentityDirectory.from_environment(persistent=True),
onboarding=True,
calculation_store=CalculationStore.from_environment(),
attachment_mirror=ImageHostClient().mirror,
)
def response_for_text(self, text: str) -> str:
@@ -402,12 +404,13 @@ class BelkiDialog:
}
def __init__(self, identity_directory: IdentityDirectory | None = None, *, onboarding: bool = False,
calculation_store: CalculationStore | None = None) -> None:
calculation_store: CalculationStore | None = None, attachment_mirror=None) -> None:
self._states: dict[int, dict[str, Any]] = {}
self._pending_attachments: dict[int, list[dict[str, Any]]] = {}
self.identity_directory = identity_directory or IdentityDirectory()
self.onboarding = onboarding
self.calculation_store = calculation_store
self.attachment_mirror = attachment_mirror
def _reset(self, peer_id: int) -> None:
self._states.pop(peer_id, None)
@@ -754,6 +757,14 @@ class BelkiDialog:
self._attach_pending(actor_id)
if state and state.get("confirm"):
if text.lower() in ("да", "подтвердить", "подтверждаю"):
if self.attachment_mirror:
for photo in state.get("attachments", []):
try:
mirror_url = self.attachment_mirror(photo)
except Exception:
mirror_url = None
if mirror_url:
photo["mirror_url"] = mirror_url
payload = {key: value for key, value in state.items() if key not in {"confirm", "escort", "kitten", "character", "independence", "_independence_provided"}}
response = calculate_payload(payload)
if self.calculation_store: