Update chatbot/plugins/keyboards.py
Browse files- chatbot/plugins/keyboards.py +26 -21
chatbot/plugins/keyboards.py
CHANGED
@@ -1,28 +1,33 @@
|
|
1 |
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
2 |
from chatbot.plugins.languages import LANGUAGES
|
3 |
|
4 |
-
def get_language_keyboard():
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
keyboard = []
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
keyboard.append([
|
25 |
-
InlineKeyboardButton("Cancel", callback_data="cancel")
|
26 |
-
])
|
27 |
|
28 |
return InlineKeyboardMarkup(keyboard)
|
|
|
1 |
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
2 |
from chatbot.plugins.languages import LANGUAGES
|
3 |
|
4 |
+
def get_language_keyboard(buttons_per_row=2):
|
5 |
+
"""
|
6 |
+
Generates an InlineKeyboardMarkup for language selection.
|
7 |
+
|
8 |
+
:param buttons_per_row: Number of language buttons per row.
|
9 |
+
:return: InlineKeyboardMarkup object.
|
10 |
+
"""
|
11 |
keyboard = []
|
12 |
+
buttons = []
|
13 |
|
14 |
+
for index, lang in enumerate(LANGUAGES, start=1):
|
15 |
+
buttons.append(
|
16 |
+
InlineKeyboardButton(
|
17 |
+
text=lang['name'],
|
18 |
+
callback_data=f"lang_{lang['code']}"
|
19 |
+
)
|
20 |
+
)
|
21 |
+
|
22 |
+
if index % buttons_per_row == 0:
|
23 |
+
keyboard.append(buttons)
|
24 |
+
buttons = []
|
25 |
+
|
26 |
+
# Append any remaining buttons
|
27 |
+
if buttons:
|
28 |
+
keyboard.append(buttons)
|
29 |
+
|
30 |
+
# Add the Cancel button on a new row
|
31 |
+
keyboard.append([InlineKeyboardButton("Cancel", callback_data="cancel")])
|
|
|
|
|
32 |
|
33 |
return InlineKeyboardMarkup(keyboard)
|