оцени код from aiogram import Router, types, F, Bot from…
- User
Assistant: User: User: оцени код from aiogram import Router, types, F, Bot from aiogram.fsm.context import FSMContext
from aiogram.utils.keyboard import InlineKeyboardBuilder
from models.user import User, Subscription
from utils.admin import notify_admins from utils.states import SubscriptionStates from utils.payment import create_payment, check_payment
from jinja2 import Environment, FileSystemLoader from datetime import datetime from dateutil.relativedelta import relativedelta from pytz import timezone
import json
router = Router() templates = Environment(loader=FileSystemLoader('templates/subscribe')) available_features = {'chatgpt': 'ChatGPT', 'videomaker': 'Генератор видео + оживление фото', 'dalle': 'Генератор фото'}
@router.callback_query(F.data == 'subscribe_main_menu') async def subscribe_creator_menu(callback: types.CallbackQuery): markup = InlineKeyboardBuilder() markup.row( types.InlineKeyboardButton( text='Создать свою подписку!', callback_data='subscribe_create_button') )
codeawait callback.message.reply(text='Хотите получить доступ к полным функциям? В таком случае вы можете собрать свой тарифный план', reply_markup=markup.as_markup())@router.callback_query(F.data == 'subscribe_create_button') async def subscribe_create_button(callback: types.CallbackQuery, state: FSMContext): markup = InlineKeyboardBuilder() markup.row( *[types.InlineKeyboardButton(text=name, callback_data=f'subscribe_include_{tech_name}') for tech_name, name in available_features.items()], width=2 ) with open('config.json', encoding='utf-8') as config: config = json.load(config)
codeprice = '\n'.join([f'{name} - {config.get(tech_name)} руб.' for tech_name, name in available_features.items()]) await state.set_state(SubscriptionStates.selecting_features) message = await callback.message.reply(f'Какими функциями вы хотите пользоваться в подписке?\n\nЦены:\n\n{price}', reply_markup=markup.as_markup()) await state.update_data(message_id=message.message_id)@router.callback_query(F.data.startswith('subscribe_include_')) async def subscribe_include_feature(callback: types.CallbackQuery, state: FSMContext, bot: Bot): state_data = await state.get_data() selected_features: list = state_data.setdefault('selected_features', [])
- Assistant
The code you provided is part of a bot implementation using the
aiogramlibrary, a popular framework for building Telegram bots in Python. The code appears to focus on managing subscriptions by allowing users to select and customize their subscription features via callback queries. Below is an evaluation of the code: