Files
balance_bot/bot/handlers/form_utils/form_callback.py
2026-01-23 04:45:55 +07:00

45 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from aiogram import Router, F
from aiogram.types import CallbackQuery
from bot.data.topic_map import user_topic_map
router = Router(name="form_callbacks")
TEXTS = {
"anketa": {
"accept": "<b>🎉 Ваша анкета принята!</b>\n\nДобро пожаловать в проект!",
"reject": "<b>❌ Ваша анкета отклонена.</b>\n\nВы можете попробовать позже."
},
"application": {
"accept": "<b>🎉 Ваша анкета принята!</b>\n\nДобро пожаловать в проект!",
"reject": "<b>❌ Ваша анкета отклонена.</b>\n\nВы можете попробовать позже."
},
"union": {
"accept": "<b>🤝 Союз одобрен!</b>\n\nТеперь вы в союзе.",
"reject": "<b>💔 Союз отклонён.</b>\n\nВы можете обсудить детали с администрацией."
}
}
@router.callback_query(F.data.regexp(r"^([a-z_]+):(accept|reject):(\d+)$"))
async def process_decision_callback(callback: CallbackQuery):
kind, action, thread_id_str = callback.data.split(":")
thread_id = int(thread_id_str)
user_id = None
for (uid, k), tid in user_topic_map.items():
if k == kind and tid == thread_id:
user_id = uid
break
if not user_id:
await callback.answer("Пользователь не найден.", show_alert=True)
return
text_to_send = TEXTS.get(kind, {}).get(action)
if not text_to_send:
await callback.answer("Некорректные данные.", show_alert=True)
return
await callback.message.bot.send_message(chat_id=user_id, text=text_to_send, parse_mode="HTML")
await callback.message.edit_reply_markup(reply_markup=None)
await callback.answer("Ответ отправлен пользователю.")