From 8fe4d0ed6d4f66020ea6422cb0a8b4ef2a4c49ac Mon Sep 17 00:00:00 2001 From: Konstantin Raikhert <69113745+KonstantinRaikhert@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:27:08 +0300 Subject: [PATCH] Dev (#251) --- src/bot/bot_interface.py | 8 ++++---- src/bot/handlers/was_the_lesson.py | 5 ++++- src/schooling/signals_bot.py | 8 -------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/bot/bot_interface.py b/src/bot/bot_interface.py index 2c1aab1..c586919 100644 --- a/src/bot/bot_interface.py +++ b/src/bot/bot_interface.py @@ -17,7 +17,7 @@ lesson_end_handler, schedule_handler, start_handler, success_registration_webapp_handler, unknown_command_handler) -from bot.handlers.conversation import help, schedule +from bot.handlers.conversation import help from bot.handlers.feedback import body, subject from bot.persistence import DjangoPersistence from bot.states import UserStates @@ -79,7 +79,7 @@ async def _build_app(self): start_handler, help_handler, success_registration_webapp_handler, - unknown_command_handler, # Переименованный echo handler + unknown_command_handler, feedback_handler, schedule_handler, lesson_end_handler, @@ -195,10 +195,10 @@ async def build_main_handler(): persistent=True, states={ UserStates.START: [ - feedback_handler, + start_handler, CallbackQueryHandler(help, pattern=f'^{UserStates.HELP.value}$'), - CallbackQueryHandler(schedule, + CallbackQueryHandler(schedule_handler, pattern=f'^{UserStates.SCHEDULE.value}$'), ], UserStates.HELP: [ diff --git a/src/bot/handlers/was_the_lesson.py b/src/bot/handlers/was_the_lesson.py index 2773dd1..b0638bc 100644 --- a/src/bot/handlers/was_the_lesson.py +++ b/src/bot/handlers/was_the_lesson.py @@ -4,7 +4,7 @@ ) from telegram.ext import CallbackContext, CallbackQueryHandler -from schooling.models import Lesson +from schooling.models import Lesson, Student from bot.states import UserStates from bot.messages_texts.constants import ( UNCOMPLETED_LESSON_FEEDBACK_MSG, @@ -80,6 +80,9 @@ async def was_the_lesson_completed(update: Update, context: CallbackContext): if lesson.is_passed_teacher and lesson.is_passed_student: lesson.is_passed = True await lesson.asave() + student = await Student.objects.aget(telegram_id=student_tg_id) + student.paid_lessons -= 1 + await student.asave() context.user_data['lesson_responses'].clear() if teacher_answ == 'no' or student_answ == 'no': diff --git a/src/schooling/signals_bot.py b/src/schooling/signals_bot.py index 01ad87c..c3cf4c2 100644 --- a/src/schooling/signals_bot.py +++ b/src/schooling/signals_bot.py @@ -179,7 +179,6 @@ async def msg_change_lesson(sender, instance, created, **kwargs): lambda: instance.teacher_old.telegram_id, )() chat_ids = (student_telegram_id, teacher_old_telegram_id) - msg_teacher = await get_message_text(instance) msg_text = ( f'Ваше занятие на тему "{instance.name}" ' f'проведёт преподаватель {instance.teacher_id}\n' @@ -205,7 +204,6 @@ async def msg_change_lesson(sender, instance, created, **kwargs): await sync_to_async(lambda: instance.student_id.telegram_id)(), await sync_to_async(lambda: instance.teacher_id.telegram_id)(), ) - chat_id = None elif instance.teacher_old != instance.teacher_id: message_text = msg_text @@ -230,12 +228,6 @@ async def msg_change_lesson(sender, instance, created, **kwargs): reply_markup=reply_markup, ) - if chat_id: - bot_token = settings.TELEGRAM_TOKEN - await send_message_to_user( - bot_token, chat_id, msg_teacher, reply_markup, - ) - @receiver(pre_delete, sender=Lesson) async def delete_lesson_and_send_msg(sender, instance, *args, **kwargs):