-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboards.py
223 lines (173 loc) · 9.15 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
from aiogram.types import InlineKeyboardMarkup
from aiogram.utils.keyboard import InlineKeyboardBuilder
import texts.buttons
from callbacks import ActionButton, RemindButton, RemindButtonAction, NavigateButton, NavigateButtonLocation, \
ActionButtonAction
from entities.remind import Remind
from entities.remind_group import RemindGroup
from texts.buttons import back_to_menu, remind_creation_confirm, remind_creation_change_text, \
remind_creation_change_time
from texts.messages import TIME_FORMAT
def get_menu_keyboard() -> InlineKeyboardMarkup:
builder = InlineKeyboardBuilder()
builder.button(
text=texts.buttons.new_remind,
callback_data=ActionButton(action=ActionButtonAction.new_remind)
)
builder.button(
text=texts.buttons.new_group_remind,
callback_data=ActionButton(action=ActionButtonAction.new_group_remind)
)
builder.button(
text=texts.buttons.remind_from_voice,
callback_data=ActionButton(action=ActionButtonAction.create_remind_from_voice)
)
builder.button(
text=texts.buttons.my_remind_list,
callback_data=ActionButton(action=ActionButtonAction.remind_list)
)
builder.button(
text=texts.buttons.my_remind_groups_list,
callback_data=ActionButton(action=ActionButtonAction.show_remind_groups_list)
)
builder.button(
text=texts.buttons.help_section,
callback_data=ActionButton(action=ActionButtonAction.show_help_section)
)
builder.adjust(1)
return builder.as_markup()
def get_confirm_remind_creation_keyboard(raw: bool = False) -> InlineKeyboardBuilder:
builder = InlineKeyboardBuilder()
builder.button(text=remind_creation_change_text,
callback_data=ActionButton(action=ActionButtonAction.edit_remind_text))
builder.button(text=remind_creation_change_time,
callback_data=ActionButton(action=ActionButtonAction.edit_remind_time))
builder.button(text=texts.buttons.remind_creation_change_remind_group,
callback_data=ActionButton(action=ActionButtonAction.edit_remind_group))
if raw:
builder.button(
text=texts.buttons.back_to_raw_remind_list,
callback_data=ActionButton(action=ActionButtonAction.back_to_raw_remind_list))
else:
builder.button(
text=remind_creation_confirm,
callback_data=ActionButton(action=ActionButtonAction.confirm_remind_creation))
builder.adjust(2, 1)
return builder
def get_remind_list_keyboard(reminds: list[Remind]) -> InlineKeyboardBuilder:
builder = InlineKeyboardBuilder()
for i, remind in enumerate(reminds, 1):
r = RemindButton(remind_id=remind.id, action=RemindButtonAction.show)
builder.button(text=f"{i}. {remind.text}",
callback_data=r)
builder.button(text=back_to_menu, callback_data=ActionButton(action=ActionButtonAction.show_menu))
builder.adjust(1)
return builder
def get_remind_menu_markup(remind: Remind) -> InlineKeyboardBuilder:
builder = InlineKeyboardBuilder()
builder.button(text="Удалить",
callback_data=RemindButton(remind_id=remind.id, action=RemindButtonAction.delete))
builder.button(text="Редактировать текст",
callback_data=RemindButton(remind_id=remind.id, action=RemindButtonAction.edit_text))
builder.button(text="Редактировать время",
callback_data=RemindButton(remind_id=remind.id, action=RemindButtonAction.edit_time))
builder.button(text="🔙 Назад к списку",
callback_data=NavigateButton(location=NavigateButtonLocation.remind_list))
builder.adjust(1)
return builder
def get_groups_list_keyboard(groups: list[RemindGroup], action: ActionButtonAction) -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.button(text=texts.buttons.create_remind_group, callback_data=ActionButton(action=ActionButtonAction.create_remind_group))
kb.attach(get_groups_list_raw_keyboard(action, groups))
kb.button(text=back_to_menu, callback_data=ActionButton(action=ActionButtonAction.show_menu))
kb.adjust(1)
return kb
def get_groups_list_raw_keyboard(action: ActionButtonAction, groups: list[RemindGroup]):
kb = InlineKeyboardBuilder()
for group in groups:
text = f"{group.name} (#{group.id})"
kb.button(text=text,
callback_data=ActionButton(action=action, data=f"{group.id}"))
kb.adjust(1)
return kb
def get_grop_management_keyboard(group: RemindGroup, is_owner: bool = False) -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.button(text=texts.buttons.leave_from_remind_group,
callback_data=ActionButton(action=ActionButtonAction.leave_from_remind_group, data=f"{group.id}"))
kb.button(text=texts.buttons.change_remind_group_name,
callback_data=ActionButton(action=ActionButtonAction.change_remind_group_name, data=f"{group.id}"))
if is_owner:
kb.button(text=texts.buttons.remind_group_member_management,
callback_data=ActionButton(action=ActionButtonAction.remind_group_member_management, data=f"{group.id}"))
kb.button(text=texts.buttons.delete_remind_group,
callback_data=ActionButton(action=ActionButtonAction.delete_remind_group, data=f"{group.id}"))
kb.button(text=texts.buttons.back_to_group_list,
callback_data=ActionButton(action=ActionButtonAction.show_group_list))
kb.adjust(1)
return kb
def get_new_group_remind_keyboard(groups: list[RemindGroup]) -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.attach(get_groups_list_raw_keyboard(ActionButtonAction.select_group_for_new_remind, groups))
kb.button(text=texts.buttons.back, callback_data=ActionButton(action=ActionButtonAction.show_menu))
kb.adjust(1)
return kb
def get_edit_remind_group_keyboard(groups: list[RemindGroup]) -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.attach(get_groups_list_raw_keyboard(ActionButtonAction.edit_group_for_new_remind, groups))
kb.button(text=texts.buttons.back,
callback_data=ActionButton(action=ActionButtonAction.show_confirm_remind_creation_menu))
kb.adjust(1)
return kb
def get_edit_remind_group_for_all_raw_keyboard(groups: list[RemindGroup]) -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.attach(get_groups_list_raw_keyboard(ActionButtonAction.edit_group_for_all_raw_reminds, groups))
kb.button(text=texts.buttons.back,
callback_data=ActionButton(action=ActionButtonAction.back_to_raw_remind_list))
kb.adjust(1)
return kb
def get_remind_creation_successful_keyboard() -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.button(
text=texts.buttons.create_another_remind,
callback_data=ActionButton(action=ActionButtonAction.new_remind)
)
kb.button(text=back_to_menu, callback_data=ActionButton(action=ActionButtonAction.show_menu))
kb.adjust(1)
return kb
def get_entering_remind_creation_keyboard() -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.button(text=back_to_menu, callback_data=ActionButton(action=ActionButtonAction.show_menu))
return kb
def get_create_remind_group_markup() -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.button(text=texts.buttons.back_to_group_list, callback_data=ActionButton(action=ActionButtonAction.show_remind_groups_list))
return kb
def get_help_section_keyboard() -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.button(text=back_to_menu, callback_data=ActionButton(action=ActionButtonAction.show_menu))
return kb
def get_success_group_creating_keyboard() -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.button(text=texts.buttons.back_to_group_list, callback_data=ActionButton(action=ActionButtonAction.show_remind_groups_list))
return kb
def get_parsed_reminds_keyboard(raw_reminds: list[list[str]]) -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
for i, raw_remind in enumerate(raw_reminds):
time = raw_remind[0].strftime(TIME_FORMAT)
text = raw_remind[1]
button_text = texts.buttons.raw_remind_button.format(time=time, text=text)
kb.button(text=button_text,
callback_data=ActionButton(action=ActionButtonAction.edit_raw_remind, data=f"{i}"))
kb.button(text=texts.buttons.remind_creation_change_remind_group,
callback_data=ActionButton(action=ActionButtonAction.edit_remind_group_for_all_raw))
kb.button(text=texts.buttons.approve_all_reminds,
callback_data=ActionButton(action=ActionButtonAction.approve_all_reminds))
kb.button(text=back_to_menu, callback_data=ActionButton(action=ActionButtonAction.show_menu))
kb.adjust(1)
return kb
def get_navigation_keyboard(text: str, action: ActionButtonAction) -> InlineKeyboardBuilder:
kb = InlineKeyboardBuilder()
kb.button(text=text, callback_data=ActionButton(action=action))
return kb
def get_create_remind_from_voice_keyboard() -> InlineKeyboardBuilder:
return get_navigation_keyboard(texts.buttons.back_to_menu, ActionButtonAction.show_menu)