-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboards.py
79 lines (54 loc) · 2.6 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
69
70
71
72
73
74
75
76
77
78
79
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from crud import s, get_all_dev_types, get_dev_by_title
from dotenv import load_dotenv
import os
load_dotenv()
def gen_start_kb(telid):
devs = get_all_dev_types(s)
types = []
for d in devs:
if d.device_type not in types:
types.append(d.device_type)
butt = [[InlineKeyboardButton(text= d, callback_data='first_' +d)] for d in types]
if telid != os.getenv('ADMIN_TELID'):
start_kb = InlineKeyboardMarkup(inline_keyboard=butt)
return start_kb
butt += [InlineKeyboardButton(text= 'Админка', callback_data='admin')]
start_kb = InlineKeyboardMarkup(inline_keyboard=butt)
return start_kb
def gen_companyies_kb(typ):
devs = [d for d in get_all_dev_types(s) if d.device_type == typ]
types = []
for d in devs:
if d.company not in types:
types.append(d.company)
butt = [[InlineKeyboardButton(text= d, callback_data='second_' +d+ '_'+typ)] for d in types]
butt.append([InlineKeyboardButton(text= 'Назад', callback_data='start')])
sec_kb = InlineKeyboardMarkup(inline_keyboard=butt)
return sec_kb
def gen_devices_kb(typ, comp, last_cb):
devs = [d for d in get_all_dev_types(s) if (d.company == comp and d.device_type == typ)]
types = []
for d in devs:
if d.device_title not in types:
types.append(d.device_title)
butt = [[InlineKeyboardButton(text=d, callback_data='devs_' + str(d))] for d in types]
butt.append([InlineKeyboardButton(text= 'Назад', callback_data='first_' + typ)])
dev_kb = InlineKeyboardMarkup(inline_keyboard=butt)
return dev_kb
def gen_devices_param_kb(dev_title, last_cb):
devs = get_dev_by_title(s, dev_title)
types = []
for d in devs:
if d.params not in types:
types.append(d.params)
butt = [[InlineKeyboardButton(text=k, callback_data='params_'+dev_title+'#' + str(k))] for k in types]
butt.append([InlineKeyboardButton(text= 'Назад', callback_data='second_' + devs[0].company + '_' + devs[0].device_type)])
dev_kb = InlineKeyboardMarkup(inline_keyboard=butt)
return dev_kb
def gen_last_kb(dev_title):
dev_kb = InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text= 'Назад', callback_data='devs_' + dev_title)]])
return dev_kb
def gen_admin_keyboard():
dev_kb = InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text= 'Сделать рассылку', callback_data='make_spam')], [InlineKeyboardButton(text= 'Назад', callback_data='start')]])
return dev_kb