channel-block-tg/keyboards/default/utils/misc.py
Forden 2bbbee4651 Added usage example of errors_handler
Optimized generation of default/inline keyboard
Customizing webhook path has become more flexible
Updated aiogram version to 2.7 (BotAPI 4.7)
2020-04-07 01:44:05 +03:00

18 lines
587 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
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
def arrange_default_schema(buttons: List[KeyboardButton], count: List[int]) -> ReplyKeyboardMarkup:
kb = ReplyKeyboardMarkup(resize_keyboard=True)
kb.row_width = max(count)
if sum(count) != len(buttons):
raise ValueError('Количество кнопок не совпадает со схемой')
tmplist = []
for a in count:
tmplist.append([])
for _ in range(a):
tmplist[-1].append(buttons.pop(0))
kb.keyboard = tmplist
return kb