Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
anasty17
GitHub Repository: anasty17/mirror-leech-telegram-bot
Path: blob/master/bot/helper/telegram_helper/button_build.py
1640 views
1
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
2
3
4
class ButtonMaker:
5
def __init__(self):
6
self._button = []
7
self._header_button = []
8
self._footer_button = []
9
10
def url_button(self, key, link, position=None):
11
if not position:
12
self._button.append(InlineKeyboardButton(text=key, url=link))
13
elif position == "header":
14
self._header_button.append(InlineKeyboardButton(text=key, url=link))
15
elif position == "footer":
16
self._footer_button.append(InlineKeyboardButton(text=key, url=link))
17
18
def data_button(self, key, data, position=None):
19
if not position:
20
self._button.append(InlineKeyboardButton(text=key, callback_data=data))
21
elif position == "header":
22
self._header_button.append(
23
InlineKeyboardButton(text=key, callback_data=data)
24
)
25
elif position == "footer":
26
self._footer_button.append(
27
InlineKeyboardButton(text=key, callback_data=data)
28
)
29
30
def build_menu(self, b_cols=1, h_cols=8, f_cols=8):
31
menu = [
32
self._button[i : i + b_cols] for i in range(0, len(self._button), b_cols)
33
]
34
if self._header_button:
35
h_cnt = len(self._header_button)
36
if h_cnt > h_cols:
37
header_buttons = [
38
self._header_button[i : i + h_cols]
39
for i in range(0, len(self._header_button), h_cols)
40
]
41
menu = header_buttons + menu
42
else:
43
menu.insert(0, self._header_button)
44
if self._footer_button:
45
if len(self._footer_button) > f_cols:
46
[
47
menu.append(self._footer_button[i : i + f_cols])
48
for i in range(0, len(self._footer_button), f_cols)
49
]
50
else:
51
menu.append(self._footer_button)
52
return InlineKeyboardMarkup(menu)
53
54
def reset(self):
55
self._button = []
56
self._header_button = []
57
self._footer_button = []
58
59