from __future__ import annotations from adapter.matrix.store import clear_pending_confirm, get_pending_confirm from core.protocol import IncomingCallback, OutgoingMessage def make_handle_confirm(store=None): async def handle_confirm( event: IncomingCallback, auth_mgr, platform, chat_mgr, settings_mgr ) -> list: if store is None: return [OutgoingMessage(chat_id=event.chat_id, text="Нет ожидающих подтверждений.")] pending = await get_pending_confirm(store, event.chat_id) if not pending: return [OutgoingMessage(chat_id=event.chat_id, text="Нет ожидающих подтверждений.")] description = pending.get("description", "действие") await clear_pending_confirm(store, event.chat_id) return [OutgoingMessage(chat_id=event.chat_id, text=f"Подтверждено: {description}")] return handle_confirm def make_handle_cancel(store=None): async def handle_cancel( event: IncomingCallback, auth_mgr, platform, chat_mgr, settings_mgr ) -> list: if store is None: return [OutgoingMessage(chat_id=event.chat_id, text="Нет ожидающих подтверждений.")] pending = await get_pending_confirm(store, event.chat_id) if not pending: return [OutgoingMessage(chat_id=event.chat_id, text="Нет ожидающих подтверждений.")] await clear_pending_confirm(store, event.chat_id) return [OutgoingMessage(chat_id=event.chat_id, text="Действие отменено.")] return handle_cancel