-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmisc.py
More file actions
83 lines (71 loc) · 2.25 KB
/
misc.py
File metadata and controls
83 lines (71 loc) · 2.25 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from math import ceil
from pyrogram.types import InlineKeyboardButton
from PyrogramBot import LOAD_MODULES, NOLOAD_MODULES
class EqInlineKeyboardButton(InlineKeyboardButton):
def __eq__(self, other):
return self.text == other.text
def __lt__(self, other):
return self.text < other.text
def __gt__(self, other):
return self.text > other.text
def count_modules(page_n, module_dict, prefix, chat=None):
if not chat:
modules = sorted(
[
EqInlineKeyboardButton(
x.__MODULE__,
callback_data="{}_module({})".format(
prefix, x.__MODULE__.lower()),
)
for x in module_dict.values()
]
)
else:
modules = sorted(
[
EqInlineKeyboardButton(
x.__MODULE__,
callback_data="{}_module({},{})".format(
prefix, chat, x.__MODULE__.lower()
),
)
for x in module_dict.values()
]
)
pairs = list(zip(modules[::3], modules[1::3], modules[2::3]))
i = 0
for m in pairs:
for _ in m:
i += 1
if len(modules) - i == 1:
pairs.append((modules[-1],))
elif len(modules) - i == 2:
pairs.append(
(
modules[-2],
modules[-1],
)
)
max_num_pages = ceil(len(pairs) / 7)
modulo_page = page_n % max_num_pages
# can only have a certain amount of buttons side by side
if len(pairs) > 7:
pairs = pairs[modulo_page * 7: 7 * (modulo_page + 1)] + [
(
EqInlineKeyboardButton(
"<",
callback_data="{}_prev({})".format(
prefix, modulo_page
),
),
EqInlineKeyboardButton(
">",
callback_data="{}_next({})".format(
prefix, modulo_page
),
),
)
]
return pairs
def is_module_loaded(name):
return (not LOAD_MODULES or name in LOAD_MODULES) and name not in NOLOAD_MODULES