-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
50 lines (37 loc) · 1.16 KB
/
utils.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
from telegram import (
KeyboardButton,
Update,
User as tgUser,
ReplyKeyboardMarkup as tgReplyKeyboardMarkup,
)
from bot.models import User
class Utils:
def getUser(self, update:Update) -> "tuple[tgUser, User]":
user = update.message.from_user if update.message else update.callback_query.from_user
tgUser = User.objects.filter(id=user.id).first()
return user, tgUser
def distribute(self, items, number) -> list:
res = []
start = 0
end = number
for item in items:
if items[start:end] == []:
return res
res.append(items[start:end])
start += number
end += number
return res
class ReplyKeyboardMarkup(tgReplyKeyboardMarkup):
def __init__(self,
keyboard: "list[list[str, KeyboardButton]]",
one_time_keyboard: bool = False,
selective: bool = False,
input_field_placeholder: str = None,
**_kwargs):
super().__init__(
keyboard,
True,
one_time_keyboard,
selective,
input_field_placeholder
)