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
|
import backend_api
from abc import ABC
class Keyboard(ABC):
@classmethod
def get_keyboard(cls, telegram_id=None):
pass
class MenuKeyboard(Keyboard):
CHOOSE_TASK = "Выбрать задание📚"
TOP_10 = "Топ-10📊"
RULES = "Правилаℹ️"
ADMIN = "/admin"
@classmethod
def get_keyboard(cls, telegram_id=None):
if telegram_id is not None:
status_code, data = backend_api.get_profile(telegram_id)
if status_code == 200 and data["is_admin"]:
return [
[cls.ADMIN],
[cls.CHOOSE_TASK],
[cls.TOP_10, cls.RULES],
]
return [
[cls.CHOOSE_TASK],
[cls.TOP_10, cls.RULES],
]
class BackToMenuKeyboard(Keyboard):
CANCEL = "Вернуться в меню↩️"
@classmethod
def get_keyboard(cls, telegram_id=None):
return [[cls.CANCEL]]
class TasksKeyboard(Keyboard):
CANCEL = "Вернуться в меню↩️"
@classmethod
def get_keyboard(cls, telegram_id=None):
status, tasks = backend_api.get_published_tasks()
titles_keyboard = [[cls.CANCEL]]
if status == 200:
titles_keyboard.extend([task.get("title")] for task in tasks)
return titles_keyboard
class PublishTasksKeyboard(Keyboard):
CANCEL = "Вернуться в меню↩️"
@classmethod
def get_keyboard(cls, telegram_id=None):
status, tasks = backend_api.get_tasks()
titles_keyboard = [[cls.CANCEL]]
if status == 200:
titles_keyboard.extend([task.get("title")] for task in tasks)
return titles_keyboard
class TaskChosenKeyboard(Keyboard):
TYPE_ANSWER = "Ввести ответ✏️"
CANCEL = "Назад↩️"
@classmethod
def get_keyboard(cls, telegram_id=None):
return [
[cls.TYPE_ANSWER],
[cls.CANCEL],
]
class ContinueKeyboard(Keyboard):
CONTINUE = "Продолжить➡️"
@classmethod
def get_keyboard(cls, telegram_id=None):
return [[cls.CONTINUE]]
class AnsweringKeyboard(Keyboard):
CANCEL = "Отмена↩️"
@classmethod
def get_keyboard(cls, telegram_id=None):
return [[cls.CANCEL]]
class AdminKeyboard(Keyboard):
CANCEL = "Вернуться в меню↩️"
PUBLISH_TASK = "Опубликовать задачу"
HIDE_TASK = "Скрыть задачу"
@classmethod
def get_keyboard(cls, telegram_id=None):
return [
[cls.CANCEL],
[cls.PUBLISH_TASK],
[cls.HIDE_TASK],
]
|