from app.settings_cache import SettingsCache from app.conversation import get_or_create_user, log_consent, get_template_rendered from app.keyboards.inline import build_consent_buttons, build_contact_buttons from app.fsm import BotState, FSM async def handle_consent_request(bot, user_data: dict, db, max_api): max_user_id = user_data["user_id"] user = await get_or_create_user(db, max_user_id, user_data.get("first_name", ""), user_data.get("last_name", ""), user_data.get("username", "")) await db.flush() await SettingsCache.refresh(db) policy_url = SettingsCache.get("consent_policy_url", "https://aegisone.ru/politica.php") text = await get_template_rendered(db, "consent_request", policy_url=policy_url) buttons = build_consent_buttons() await max_api.send_message_with_keyboard(max_user_id, text, buttons, format="markdown") FSM.set_state(max_user_id, BotState.CONSENT_REQUEST) async def handle_consent_given(bot, user_data: dict, db, max_api): max_user_id = user_data["user_id"] user = await get_or_create_user(db, max_user_id) user.consent_given = True from datetime import datetime user.consent_timestamp = datetime.now() user.consent_method = "button" await log_consent(db, user.id, "given", "button", user_data.get("ip", "")) await db.flush() text = await get_template_rendered(db, "contact_request") buttons = build_contact_buttons() await max_api.send_message_with_keyboard(max_user_id, text, buttons) FSM.set_state(max_user_id, BotState.CONTACT_REQUEST) async def handle_consent_refused(bot, user_data: dict, db, max_api): max_user_id = user_data["user_id"] user = await get_or_create_user(db, max_user_id) await log_consent(db, user.id, "revoked", "button", user_data.get("ip", "")) await db.flush() await SettingsCache.refresh(db) phone_1 = SettingsCache.get("phone_1") phone_2 = SettingsCache.get("phone_2") email = SettingsCache.get("support_email") text = await get_template_rendered(db, "consent_refused", phone_1=phone_1, phone_2=phone_2, support_email=email) from app.keyboards.inline import build_phone_email_buttons subject = SettingsCache.get("email_subject") buttons = build_phone_email_buttons(phone_1, phone_2, email, subject) await max_api.send_message_with_keyboard(max_user_id, text, buttons, format="markdown") FSM.reset(max_user_id)