aiogram-bot-template/keyboards/keyboard_utils/schema_generator.py

18 lines
612 B
Python
Raw 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 typing import List, Union
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup
def create_keyboard_layout(
buttons: List[Union[InlineKeyboardButton, KeyboardButton]],
count: List[int]
) -> Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]:
if sum(count) != len(buttons):
raise ValueError('Количество кнопок не совпадает со схемой')
tmplist = []
for a in count:
tmplist.append([])
for _ in range(a):
tmplist[-1].append(buttons.pop(0))
return tmplist