Spaces:
Paused
Paused
Download Powers/utils/kbhelpers.py from Dragdev/telegrambot: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/Dragdev/telegrambot/resolve/492d7fcd90594de1ce93896bb2a9b2f9e1927150/Powers/utils/kbhelpers.py
- Command line
-
hf download hf://spaces/Dragdev/telegrambot@492d7fcd90594de1ce93896bb2a9b2f9e1927150/Powers/utils/kbhelpers.py
-
curl -L -o kbhelpers.py https://huggingface.co/spaces/Dragdev/telegrambot/resolve/492d7fcd90594de1ce93896bb2a9b2f9e1927150/Powers/utils/kbhelpers.py
1.31 kB
| 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].upper() | |
| button = btn(btn_text, button) # InlineKeyboardButton | |
| line.append(button) | |
| lines.append(line) | |
| except AttributeError: | |
| for row in rows: | |
| line = [] | |
| for button in row: | |
| button = btn(*button) # Will make the kb which don't have "." in them | |
| 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}) | |