Spaces:
Sleeping
Sleeping
File size: 1,329 Bytes
72ed22a 11ae35a 17b7442 72ed22a 17b7442 483f4a5 56e6de1 483f4a5 de77774 51e1c40 de77774 80d7d9c 5e80b5a 17b7442 51e1c40 11ae35a c0ed2cf 72ed22a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
def ikb(rows=None, back=False, todo="start_back"):
"""
rows = pass the rows
back - if want to make back button
todo - callback data of back button
"""
if rows is None:
rows = []
lines = []
try:
for row in rows:
line = []
for button in row:
btn_text = button.split(".")[1].capitalize()
button = btn(btn_text, button) # InlineKeyboardButton
line.append(button)
lines.append(line)
except AttributeError:
for row in rows:
line = []
for button in row:
# Will make the kb which don't have "." in them
button = btn(*button)
line.append(button)
lines.append(line)
except TypeError:
# make a code to handel that error
line = []
for button in rows:
button = btn(*button) # InlineKeyboardButton
line.append(button)
lines.append(line)
if back:
back_btn = [(btn("« Back", todo))]
lines.append(back_btn)
return InlineKeyboardMarkup(inline_keyboard=lines)
def btn(text, value, type="callback_data"):
return InlineKeyboardButton(text, **{type: value})
|