42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
"""Services handler - show rich service cards with images."""
|
|
from aiogram import Router, F
|
|
from aiogram.types import Message, FSInputFile, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
|
|
from aiogram.fsm.context import FSMContext
|
|
from aiogram import Bot
|
|
|
|
from app.config import SERVICES, BOT_TOKEN
|
|
from app.logger import logger
|
|
|
|
router = Router()
|
|
|
|
_bot = None
|
|
|
|
|
|
def bot():
|
|
global _bot
|
|
if _bot is None:
|
|
_bot = Bot(token=BOT_TOKEN)
|
|
return _bot
|
|
|
|
|
|
@router.message(F.text == "\U0001f4cb \u0423\u0441\u043b\u0443\u0433\u0438")
|
|
async def show_services(message: Message, state: FSMContext):
|
|
await state.clear()
|
|
logger.info("User {uid} requested services list", uid=message.from_user.id)
|
|
|
|
for key, svc in SERVICES.items():
|
|
try:
|
|
card = (
|
|
svc["emoji"] + " " + svc["name"] + "\n\n"
|
|
+ svc["desc"] + "\n\n"
|
|
+ "\u23f1 \u0414\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c: " + str(svc["duration"]) + " \u043c\u0438\u043d\n"
|
|
+ "\U0001f4b0 \u0426\u0435\u043d\u0430: " + str(svc["price"]) + "\u20bd"
|
|
)
|
|
book_btn = InlineKeyboardMarkup(inline_keyboard=[[
|
|
InlineKeyboardButton(text="\U0001f4c5 \u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f", callback_data=key)
|
|
]])
|
|
img = FSInputFile(svc["image"])
|
|
await bot().send_photo(message.chat.id, photo=img, caption=card, reply_markup=book_btn)
|
|
except Exception as e:
|
|
logger.warning("Error sending service card for {key}: {err}", key=key, err=e)
|