channel-block-tg/keyboards/inline/utils/misc.py
2020-04-06 00:12:41 +03:00

18 lines
679 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 InlineKeyboardButton, InlineKeyboardMarkup
def arrange_inline_schema(buttons: List[InlineKeyboardButton], count: List[int]) -> InlineKeyboardMarkup:
kb = InlineKeyboardMarkup()
btns = buttons
kb.row_width = max(count)
if sum(count) != len(buttons):
raise ValueError('Количество кнопок не совпадает со схемой')
tmplist = [[InlineKeyboardButton('') for _ in range(count[i])] for i in range(len(count))]
for a in range(len(tmplist)):
for b in range(len(tmplist[a])):
tmplist[a][b] = btns.pop(0)
kb.inline_keyboard = tmplist
return kb