-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathcallbacks.py
More file actions
314 lines (267 loc) · 13.1 KB
/
callbacks.py
File metadata and controls
314 lines (267 loc) · 13.1 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
from aiogram import types
from aiogram.filters.callback_data import CallbackData
from enums.add_type import AddType
from enums.announcement_type import AnnouncementType
from enums.bot_entity import BotEntity
from enums.buy_status import BuyStatus
from enums.cart_action import CartAction
from enums.coupon_type import CouponType
from enums.cryptocurrency import Cryptocurrency
from enums.entity_type import EntityType
from enums.item_type import ItemType
from enums.keyboard_button import KeyboardButton
from enums.language import Language
from enums.shipping_management_action import ShippingManagementAction
from enums.shipping_type_property import ShippingOptionProperty
from enums.sort_order import SortOrder
from enums.sort_property import SortProperty
from enums.statistics_entity import StatisticsEntity
from enums.statistics_timedelta import StatisticsTimeDelta
from enums.user_management_operation import UserManagementOperation
from enums.coupon_number_of_uses import CouponNumberOfUses
from enums.user_role import UserRole
from utils.utils import get_text
class BaseCallback(CallbackData, prefix="base"):
level: int
page: int = 0
def get_back_button(self, language: Language, lvl: int | None = None):
cb_copy = self.__copy__()
if lvl is None:
cb_copy.level = cb_copy.level - 1
else:
cb_copy.level = lvl
return types.InlineKeyboardButton(
text=get_text(language, BotEntity.COMMON, "back_button"),
callback_data=cb_copy.create(**cb_copy.model_dump()).pack())
class SortingCallback(CallbackData, prefix="sorting"):
sort_order: SortOrder
sort_property: SortProperty
is_filter_enabled: bool = False
class AllCategoriesCallback(BaseCallback, SortingCallback, prefix="all_categories"):
item_type: ItemType | None
category_id: int | None
subcategory_id: int | None
quantity: int | None
confirmation: bool
@staticmethod
def create(level: int,
item_type: ItemType | None = None,
category_id: int | None = None,
subcategory_id: int | None = None,
quantity: int | None = None,
sort_order: SortOrder = SortOrder.DISABLE,
sort_property: SortProperty = SortProperty.NAME,
is_filter_enabled: bool = False,
confirmation: bool = False,
page: int = 0) -> 'AllCategoriesCallback':
return AllCategoriesCallback(level=level,
item_type=item_type,
category_id=category_id, subcategory_id=subcategory_id,
sort_order=sort_order, sort_property=sort_property,
quantity=quantity, is_filter_enabled=is_filter_enabled,
confirmation=confirmation, page=page)
class MyProfileCallback(BaseCallback, SortingCallback, prefix="my_profile"):
buy_id: int | None = None
buyItem_id: int | None = None
cryptocurrency: Cryptocurrency | None = None
language: Language | None = None
user_role: UserRole = UserRole.USER
confirmation: bool = False
@staticmethod
def create(level: int,
buy_id: int | None = None,
buyItem_id: int | None = None,
sort_order: SortOrder = SortOrder.DISABLE,
sort_property: SortProperty = SortProperty.BUY_DATETIME,
is_filter_enabled: bool = False,
cryptocurrency: Cryptocurrency | None = None,
language: Language | None = None,
user_role: UserRole = UserRole.USER,
confirmation: bool = False,
page=0) -> 'MyProfileCallback':
return MyProfileCallback(level=level, buy_id=buy_id, buyItem_id=buyItem_id,
sort_order=sort_order, sort_property=sort_property,
is_filter_enabled=is_filter_enabled,
cryptocurrency=cryptocurrency,
language=language,
user_role=user_role,
confirmation=confirmation,
page=page)
class CartCallback(BaseCallback, prefix="cart"):
cart_id: int
cart_item_id: int
cart_action: CartAction | None
shipping_option_id: int | None
confirmation: bool
@staticmethod
def create(level: int = 0,
cart_id: int = -1,
cart_item_id: int = -1,
cart_action: CartAction | None = None,
shipping_option_id: int | None = None,
confirmation=False,
page: int = 0):
return CartCallback(level=level,
cart_id=cart_id,
cart_item_id=cart_item_id,
cart_action=cart_action,
shipping_option_id=shipping_option_id,
confirmation=confirmation,
page=page)
class AdminMenuCallback(BaseCallback, prefix="admin_menu"):
@staticmethod
def create(level: int, page: int = 0):
return AdminMenuCallback(level=level, page=page)
class AnnouncementCallback(BaseCallback, prefix="announcement"):
announcement_type: AnnouncementType | None
@staticmethod
def create(level: int, announcement_type: AnnouncementType | None = None, page: int = 0):
return AnnouncementCallback(level=level, announcement_type=announcement_type, page=page)
class InventoryManagementCallback(BaseCallback, SortingCallback, prefix="inventory_management"):
add_type: AddType | None
entity_type: EntityType | None
entity_id: int | None
confirmation: bool
@staticmethod
def create(level: int,
add_type: AddType | None = None,
entity_type: EntityType | None = None,
entity_id: int | None = None,
sort_order: SortOrder = SortOrder.DISABLE,
sort_property: SortProperty = SortProperty.NAME,
is_filter_enabled: bool = False,
page: int = 0,
confirmation: bool = False):
return InventoryManagementCallback(level=level,
add_type=add_type,
entity_type=entity_type,
entity_id=entity_id,
sort_order=sort_order,
sort_property=sort_property,
is_filter_enabled=is_filter_enabled,
page=page,
confirmation=confirmation)
class UserManagementCallback(BaseCallback, SortingCallback, prefix="user_management"):
operation: UserManagementOperation | None
user_id: int | None
buy_id: int | None
confirmation: bool
@staticmethod
def create(level: int,
operation: UserManagementOperation | None = None,
sort_order: SortOrder = SortOrder.DISABLE,
sort_property: SortProperty = SortProperty.BUY_DATETIME,
is_filter_enabled: bool = False,
user_id: int | None = None,
buy_id: int | None = None,
page: int = 0,
confirmation: bool = False):
return UserManagementCallback(level=level,
operation=operation,
sort_order=sort_order,
sort_property=sort_property,
is_filter_enabled=is_filter_enabled,
user_id=user_id,
buy_id=buy_id,
page=page,
confirmation=confirmation)
class StatisticsCallback(BaseCallback, prefix="statistics"):
statistics_entity: StatisticsEntity | None
timedelta: StatisticsTimeDelta | None
@staticmethod
def create(level: int, statistics_entity: StatisticsEntity | None = None,
timedelta: StatisticsTimeDelta | None = None, page: int = 0):
return StatisticsCallback(level=level, statistics_entity=statistics_entity, timedelta=timedelta, page=page)
class WalletCallback(BaseCallback, prefix="wallet"):
cryptocurrency: Cryptocurrency | None
@staticmethod
def create(level: int, cryptocurrency: Cryptocurrency | None = None):
return WalletCallback(level=level, cryptocurrency=cryptocurrency)
class MediaManagementCallback(BaseCallback, SortingCallback, prefix="media"):
entity_type: EntityType | None
entity_id: int | None = None
keyboard_button: KeyboardButton | None = None
@staticmethod
def create(level: int, entity_type: EntityType | None = None,
keyboard_button: KeyboardButton | None = None,
sort_order: SortOrder = SortOrder.DISABLE,
sort_property: SortProperty = SortProperty.NAME,
is_filter_enabled: bool = False,
entity_id: int | None = None, page: int = 0):
return MediaManagementCallback(level=level,
entity_type=entity_type,
entity_id=entity_id,
sort_order=sort_order,
sort_property=sort_property,
is_filter_enabled=is_filter_enabled,
keyboard_button=keyboard_button,
page=page)
class CouponManagementCallback(BaseCallback, prefix="coupons"):
coupon_id: int | None = None
coupon_type: CouponType | None = None
number_of_uses: CouponNumberOfUses | None = None
confirmation: bool
@staticmethod
def create(level: int, coupon_id: int | None = None, coupon_type: CouponType | None = None,
number_of_uses: CouponNumberOfUses | None = None, confirmation: bool = False, page: int = 0):
return CouponManagementCallback(level=level,
coupon_id=coupon_id,
coupon_type=coupon_type,
number_of_uses=number_of_uses,
confirmation=confirmation,
page=page)
class ShippingManagementCallback(BaseCallback, prefix="shipping_management"):
shipping_management_action: ShippingManagementAction | None = None
shipping_type_property: ShippingOptionProperty | None = None
shipping_id: int | None = None
confirmation: bool
@staticmethod
def create(level: int, shipping_management_action: ShippingManagementAction | None = None,
shipping_type_property: ShippingOptionProperty | None = None,
shipping_id: int | None = None, confirmation: bool = False, page: int = 0):
return ShippingManagementCallback(level=level,
shipping_management_action=shipping_management_action,
shipping_type_property=shipping_type_property,
shipping_id=shipping_id,
confirmation=confirmation,
page=page)
class BuysManagementCallback(BaseCallback, prefix="buys"):
buy_id: int | None = None
item_type: ItemType | None = None
buy_status: BuyStatus | None = None
confirmation: bool = False
@staticmethod
def create(level: int,
buy_id: int | None = None,
item_type: ItemType | None = None,
buy_status: BuyStatus | None = None,
confirmation: bool = False,
page: int = 0):
return BuysManagementCallback(level=level, buy_id=buy_id,
item_type=item_type,
buy_status=buy_status, confirmation=confirmation,
page=page)
class ReviewManagementCallback(BaseCallback, prefix="reviews"):
review_id: int | None = None
buy_id: int | None = None
buyItem_id: int | None = None
rating: int | None = None
user_role: UserRole = UserRole.USER
confirmation: bool = False
@staticmethod
def create(level: int,
review_id: int | None = None,
buy_id: int | None = None,
buyItem_id: int | None = None,
rating: int | None = None,
user_role: UserRole = UserRole.USER,
page: int = 0,
confirmation: bool = False):
return ReviewManagementCallback(level=level,
review_id=review_id,
buy_id=buy_id,
buyItem_id=buyItem_id,
rating=rating,
user_role=user_role,
page=page,
confirmation=confirmation)