5
app/keyboards/__init__.py
Normal file
5
app/keyboards/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .inline import create_inline_kb, button_create
|
||||
from .menu_commands import set_main_menu,commands
|
||||
|
||||
|
||||
__all__ = ["create_inline_kb", "button_create", "set_main_menu","commands"]
|
35
app/keyboards/inline.py
Normal file
35
app/keyboards/inline.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder, ReplyKeyboardBuilder
|
||||
|
||||
|
||||
def button_create(iterable: iter, width: int = 1):
|
||||
""" Функуия для преобразования списка в кнопки для клавиатуры """
|
||||
kb_builder = ReplyKeyboardBuilder()
|
||||
kb_builder.row(*[KeyboardButton(text=f'{iterable[i]}') for i in range(len(iterable))], width=width)
|
||||
return kb_builder.as_markup(resize_keyboard=True, one_time_keyboard=True)
|
||||
|
||||
|
||||
def create_inline_kb(width: int = 1,
|
||||
*args: str, **kwargs: str) -> InlineKeyboardMarkup:
|
||||
# Инициализируем билдер
|
||||
kb_builder = InlineKeyboardBuilder()
|
||||
# Инициализируем список для кнопок
|
||||
buttons: list[InlineKeyboardButton] = []
|
||||
|
||||
# Заполняем список кнопками из аргументов args и kwargs
|
||||
if args:
|
||||
for button in args:
|
||||
buttons.append(InlineKeyboardButton(
|
||||
text=button,
|
||||
callback_data=button))
|
||||
if kwargs:
|
||||
for button, text in kwargs.items():
|
||||
buttons.append(InlineKeyboardButton(
|
||||
text=text,
|
||||
callback_data=button))
|
||||
|
||||
# Распаковываем список с кнопками в билдер методом row c параметром width
|
||||
kb_builder.row(*buttons, width=width)
|
||||
|
||||
# Возвращаем объект инлайн-клавиатуры
|
||||
return kb_builder.as_markup(resize_keyboard=True, one_time_keyboard=True)
|
10
app/keyboards/menu_commands.py
Normal file
10
app/keyboards/menu_commands.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from aiogram import Bot
|
||||
from aiogram.types import BotCommand
|
||||
|
||||
commands = {'/help': 'Помощь по работе с ботом', '/support': 'Получить контакты техподдержки',
|
||||
'/orders': 'Заказы', '/components': 'Товары', '/start': 'Запуск/перезапуск бота'}
|
||||
|
||||
|
||||
async def set_main_menu(bot: Bot):
|
||||
await bot.set_my_commands([
|
||||
BotCommand(command=command, description=description) for command, description in commands.items()])
|
Reference in New Issue
Block a user