-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboards.py
69 lines (52 loc) · 3.26 KB
/
keyboards.py
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
from aiogram import types
from main_interface.main_classes import Text, Product
from database.run_main_db import text_tb
async def start_keyboard(language: str):
texts = Text(text_tb)
but1_text = await texts.get_const_text(language=language, text_name="start_but1")
but2_text = await texts.get_const_text(language=language, text_name="start_but2")
print(but1_text, "\n", but2_text)
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
keyboard.add(types.KeyboardButton(but1_text),
types.KeyboardButton(but2_text))
return keyboard
async def shop_keyboard(language: str, product_dict: dict, current_key: int):
keyboard = types.InlineKeyboardMarkup(row_width=2)
prod_key_list = list(product_dict.keys())
current_id = prod_key_list.index(current_key)
texts = Text(text_tb)
but_l_text = await texts.get_const_text(language=language, text_name="shop_but_l")
but_r_text = await texts.get_const_text(language=language, text_name="shop_but_r")
but_buy_text = await texts.get_const_text(language=language, text_name="buy")
if (len(product_dict)-1 > current_id) and (current_id > 0):
keyboard.add(types.InlineKeyboardButton(text=but_l_text,
callback_data="shop_move.{}".format(prod_key_list[current_id-1])),
types.InlineKeyboardButton(text=but_r_text,
callback_data="shop_move.{}".format(prod_key_list[current_id+1])))
keyboard.add(types.InlineKeyboardButton(text=but_buy_text, callback_data="shop_buy.{}".format(prod_key_list[current_id])))
elif len(product_dict)-1 > current_id:
keyboard.add(types.InlineKeyboardButton(text=but_r_text,
callback_data="shop_move.{}".format(prod_key_list[current_id+1])))
keyboard.add(types.InlineKeyboardButton(text=but_buy_text, callback_data="shop_buy.{}".format(prod_key_list[current_id])))
elif current_id > 0:
keyboard.add(types.InlineKeyboardButton(text=but_l_text,
callback_data="shop_move.{}".format(prod_key_list[current_id-1])))
keyboard.add(types.InlineKeyboardButton(text=but_buy_text, callback_data="shop_buy.{}".format(prod_key_list[current_id])))
else:
keyboard.add(types.InlineKeyboardButton(text=but_buy_text, callback_data="shop_buy.{}".format(prod_key_list[current_id])))
return keyboard
def admin_keyboard():
keyboard = types.InlineKeyboardMarkup(row_width=1)
keyboard.add(types.InlineKeyboardButton(text="add product", callback_data="admin_add_prod"))
keyboard.add(types.InlineKeyboardButton(text="delete product", callback_data="admin_delete_prod"))
return keyboard
def adm_cancel_keyboard():
keyboard = types.InlineKeyboardMarkup(row_width=1)
keyboard.add(types.InlineKeyboardButton(text="cancel", callback_data="admin_cancel"))
return keyboard
def adm_del_prod_keyboard(product_list: list[Product]):
keyboard = types.InlineKeyboardMarkup(row_width=1)
for product in product_list:
keyboard.add(types.InlineKeyboardButton(text=product.title,
callback_data="admin_del_prod.{}".format(product.row_id)))
return keyboard