Some checks failed
Build and Run VSTU Public TG bot / build_and_run (push) Failing after 6s
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
|
from aiogram import types
|
|
|
|
def fac_kb(action_prefix: str, facs: dict, back="menu_start"):
|
|
builder = InlineKeyboardBuilder()
|
|
for f_id, f_data in facs.items():
|
|
if f_id.startswith("_"): continue
|
|
|
|
bt = None
|
|
try:
|
|
bt = f_data['short_names'][0]
|
|
except: pass
|
|
if bt is None:
|
|
try:
|
|
bt = f_data['full_name']
|
|
except: pass
|
|
|
|
if bt is not None:
|
|
builder.row(types.InlineKeyboardButton(
|
|
text=bt,
|
|
callback_data=f"{action_prefix}:{f_id}")
|
|
)
|
|
|
|
builder.adjust(2)
|
|
builder.row(types.InlineKeyboardButton(text="⬅️ Назад", callback_data=back))
|
|
return builder.as_markup()
|
|
|
|
def items_kb(action_prefix: str, items: list, max_col=1, back="menu_start"):
|
|
# items: [(id, name), ...]
|
|
builder = InlineKeyboardBuilder()
|
|
for item_id, item_name in items[:99]: # Лимит TG на кнопки
|
|
builder.row(types.InlineKeyboardButton(text=item_name, callback_data=f"{action_prefix}:{item_id}"))
|
|
|
|
builder.adjust(max_col)
|
|
builder.row(types.InlineKeyboardButton(text="⬅️ Назад", callback_data=back))
|
|
return builder.as_markup() |