Initial commit
Some checks failed
Build and Run VSTU Public TG bot / build_and_run (push) Failing after 6s
Some checks failed
Build and Run VSTU Public TG bot / build_and_run (push) Failing after 6s
This commit is contained in:
36
keyboards.py
Normal file
36
keyboards.py
Normal file
@@ -0,0 +1,36 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user