summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Guschin <guschin@altlinux.org>2024-10-15 16:02:54 +0400
committerAndrew Guschin <guschin@altlinux.org>2024-10-15 16:02:54 +0400
commita9f89b6a3fd22da90b58d3f2353b5965957531a3 (patch)
tree3cdf946e8b108deaf767dc71da5660b6322c803b
parentc0e082252bd5bf7700aef62c78b1ada4d90931cf (diff)
Basealt adaptation
-rw-r--r--.gitignore7
-rw-r--r--bot.py4
-rw-r--r--keyboards.py25
-rw-r--r--requirements.txt4
-rw-r--r--states.py29
5 files changed, 42 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index 2999ba7..1cace06 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
-.idea
+.*
+!.gitignore
+logs
+__pycache__
config.py
-venv \ No newline at end of file
+venv
diff --git a/bot.py b/bot.py
index 29e9d82..2218c48 100644
--- a/bot.py
+++ b/bot.py
@@ -23,9 +23,7 @@ def start(bot: Bot, update: Update, user_data: dict):
user_data.update({"chosen_task": None})
update.message.reply_text(
- "Привет! Ты вошел в телеграм-квиз от программистов нашего любимого КНиИТа!\n"
- "Если возникнут какие-то проблемы с ботом, то нажмите на кнопку Задать вопрос, "
- "а в крайнем случае пишите сюда -> @vasthecat",
+ "Квиз для дня работодателей",
reply_markup=ReplyKeyboardRemove()
)
diff --git a/keyboards.py b/keyboards.py
index 5bfc2cb..aa8d761 100644
--- a/keyboards.py
+++ b/keyboards.py
@@ -13,10 +13,10 @@ class MenuKeyboard(Keyboard):
TOP_10 = "hidden Топ-10📊"
RULES = "Правилаℹ️"
ADMIN = "/admin"
- HELP = "Задать вопрос🆘"
+ HELP = "Связаться с Базальт СПО🐧"
@classmethod
- def get_keyboard(cls, telegram_id=None):
+ def get_keyboard(cls, telegram_id=None, solved=False):
if telegram_id is not None:
status_code, data = backend_api.get_profile(telegram_id)
if status_code == 200 and data["is_admin"]:
@@ -27,11 +27,17 @@ class MenuKeyboard(Keyboard):
[cls.HELP],
]
- return [
- [cls.CHOOSE_TASK],
- [cls.RULES],
- [cls.HELP],
- ]
+ if solved:
+ return [
+ [cls.RULES],
+ [cls.HELP],
+ ]
+ else:
+ return [
+ [cls.CHOOSE_TASK],
+ [cls.RULES],
+ [cls.HELP],
+ ]
class BackToMenuKeyboard(Keyboard):
@@ -50,7 +56,10 @@ class TasksKeyboard(Keyboard):
status, tasks = backend_api.get_published_tasks()
titles_keyboard = [[cls.CANCEL]]
if status == 200:
- titles_keyboard.extend([task.get("title")] for task in tasks)
+ titles = []
+ for task in sorted(tasks, key=lambda t: t.get("title")):
+ titles.append([task.get("title")])
+ titles_keyboard.extend(titles)
return titles_keyboard
diff --git a/requirements.txt b/requirements.txt
index 4ca965a..039891d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,7 +1,7 @@
certifi==2019.11.28
-cffi==1.13.2
+cffi==1.17.1
chardet==3.0.4
-cryptography==2.8
+cryptography==43.0.1
future==0.18.2
idna==2.8
pycparser==2.19
diff --git a/states.py b/states.py
index aa40286..316357f 100644
--- a/states.py
+++ b/states.py
@@ -43,8 +43,8 @@ class States:
@save_state
def prompt_question(bot: Bot, update: Update, user_data: dict):
update.message.reply_text(
- "Введите свой вопрос, админы вам ответят, как только появится возможность, "
- "поэтому следите за сообщениями от бота.",
+ "Введите свой вопрос, он будет перенаправлен представителям компании. "
+ "Вам ответят как только появится возможность, поэтому следите за сообщениями от бота.",
reply_markup=ReplyKeyboardMarkup(BackToMenuKeyboard.get_keyboard())
)
@@ -70,11 +70,11 @@ class States:
)
update.message.reply_text(
- "Ваш вопрос был отправлен на рассмотрение, ожидайте ответ.",
+ "Ваш вопрос отправлен на рассмотрение, ожидайте ответ.",
reply_markup=ReplyKeyboardMarkup(ContinueKeyboard.get_keyboard())
)
- return ANSWER_RIGHT
+ return States.main_menu(bot, update, user_data)
@staticmethod
@@ -100,9 +100,12 @@ class States:
menu_text = [
]
+ solved = False
full_score = Decimal(0.0)
if status_code == 200:
+ if len(response) == 5:
+ solved = True
if len(response) != 0:
menu_text.append("Твои решенные задачи:")
@@ -118,7 +121,8 @@ class States:
fp = dt.datetime.strptime(attempt["task"]["first_published"], "%Y-%m-%dT%H:%M:%SZ")
t = Decimal((ts - fp).total_seconds()) / Decimal(60)
- plr_score = calc_score(t, attempt["task"]["base_score"])
+ # plr_score = calc_score(t, attempt["task"]["base_score"])
+ plr_score = int(attempt["task"]["base_score"])
full_score += plr_score
menu_text.append(
@@ -138,8 +142,13 @@ class States:
update.message.reply_text("\n".join(menu_text), parse_mode="Markdown")
update.message.reply_text(
+ "*У тебя решены все задачи! Подойди к нам, чтобы получить приз.*",
+ parse_mode="Markdown"
+ )
+
+ update.message.reply_text(
"Выбери следующее действие...",
- reply_markup=ReplyKeyboardMarkup(MenuKeyboard.get_keyboard(update.message.from_user.id))
+ reply_markup=ReplyKeyboardMarkup(MenuKeyboard.get_keyboard(update.message.from_user.id, solved))
)
return MAIN_MENU
@@ -306,8 +315,6 @@ class States:
message = '\n'.join([
f"*{task['title']}*",
f"{task['statement']}",
- "",
- f"_Теги: {task['tags']}_",
])
keyboard = TaskChosenKeyboard.get_keyboard()
@@ -355,11 +362,9 @@ class States:
if answer == task["answer"]:
update.message.reply_text(
- "Ты ввел правильный ответ! Возвращайся к другим задачам",
- reply_markup=ReplyKeyboardMarkup(ContinueKeyboard.get_keyboard())
+ "Ты ввел правильный ответ! Возвращаемся в главное меню."
)
-
- return ANSWER_RIGHT
+ return States.main_menu(bot, update, user_data)
else:
update.message.reply_text(
"К сожалению, твой ответ неверный =( Попробуй ввести другой ответ.",