chatgpt_bot/bot/kbs/inline.py

63 lines
2.5 KiB
Python
Raw Normal View History

2024-10-05 14:35:26 +00:00
from aiogram.filters.callback_data import CallbackData
from aiogram.types import InlineKeyboardButton
from aiogram.utils.keyboard import InlineKeyboardBuilder
from bot.handlers.user.model_processing import get_model_page
class PageCallBack(CallbackData, prefix="page"):
page: int
page_name: str
name_of_model: str
def get_user_main_btns(*, page: int): # page 0
btns = [
InlineKeyboardButton(text="Бесплатные уроки", callback_data=PageCallBack(page=page+1, page_name="lessons").pack()),#1
InlineKeyboardButton(text="Выбрать тариф", callback_data=PageCallBack(page=page+2, page_name="tarif").pack()),#2
InlineKeyboardButton(text="Больше о моделях", callback_data=PageCallBack(page=page+3, page_name="modelsDescription").pack()),#3
]
return get_kb_buttons(btns=btns)
def get_user_lessons_page(*, page): # page 1
btns = [
InlineKeyboardButton(text="Выбрать модель", callback_data=PageCallBack(page=page + 1, page_name="tarif").pack()), # 2
InlineKeyboardButton(text="⬅️Назад", callback_data=PageCallBack(page=page - 1, page_name="main").pack()), # 2
]
return get_kb_buttons(btns=btns)
def get_user_tarif_page(*, page): # page 2
btns = [
InlineKeyboardButton(text="1o", callback_data=PageCallBack(page=4, name_of_model='1o').pack()), # 4
InlineKeyboardButton(text="1o mini", callback_data=PageCallBack(page=5, name_of_model='1o mini').pack()), # 5
InlineKeyboardButton(text="4o", callback_data=PageCallBack(page=6, name_of_model='4o').pack()), # 6
InlineKeyboardButton(text="4o mini", callback_data=PageCallBack(page=7, name_of_model='4o mini').pack()), # 7
InlineKeyboardButton(text="⬅️Назад", callback_data=PageCallBack(page=page - 1, page_name="main").pack()), # 1
]
return get_kb_buttons(btns=btns)
def get_user_model_description_page(*, page: int, name_of_model: str):
text, kbd = get_model_page(name_of_model=name_of_model)
return text, kbd
def get_kb_buttons(*, btns: list[InlineKeyboardButton], sizes: tuple[int] = (1,)):
kb_temp = InlineKeyboardBuilder()
for btn in btns:
kb_temp = kb_temp.add(btn)
return kb_temp.adjust(*sizes).as_markup()
def get_callback_btns(*, btns: dict[str, str]):
keyboard = InlineKeyboardBuilder
for text, data in btns.items():
keyboard.add(InlineKeyboardButton(text=text, callback_data=data).pack())
return keyboard.as_markup()