def start(message): classroom_slug = message.text[12:] if message.text[7:] else None if classroom_slug: teacher = Teacher.get(message.chat.id) if teacher: ru_text = "Вы учитель и не можете добавляться в классы как ученик" en_text = "You are a teacher and can't be added to classrooms as a student" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text) bot.send_message( message.chat.id, "Классные комнаты", reply_markup=get_classroom_list_inline_markup(teacher)) else: student = Student.get(message.chat.id) or \ Student(message.chat.id, language_code='en', registered_utc=datetime.now(timezone.utc)).save() classroom = Classroom.get_by_slug(classroom_slug) teacher = Teacher.get(classroom.teacher_id) if not student.check_classroom_student(classroom.id): ClassroomStudent(classroom.id, student.id, joined_utc=datetime.now(timezone.utc)).save() if not student.fullname: student_fullname_request(message) else: ru_text = f"Вы добавлены в классную комнату *{classroom.name}*. Учитель: _{teacher.fullname}_" en_text = f"You have been added to the classroom *{classroom.name}*. Teacher: _{teacher.fullname}_" text = ru_text if student.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, parse_mode='Markdown') bot.send_message( message.chat.id, 'Классные комнаты', reply_markup=get_classroom_list_inline_markup(student)) else: user = Student.get(message.chat.id) or Teacher.get(message.chat.id) if user: ru_text = "Вы уже зарегистрированы" en_text = "You are already registered" text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text) classroom_list_view(user) else: # teacher = Teacher(message.chat.id, language_code=message.from_user.language_code) Teacher(message.chat.id, language_code='en', registered_utc=datetime.now(timezone.utc)).save() teacher_fullname_request(message)
def handle_classroom_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) classroom = Classroom.get(data['classroom_id']) teacher = Teacher.get(call.message.chat.id) delete_classroom_scenario.are_you_sure_request(call.message, teacher, classroom)
def teacher_fullname_receive(message): teacher = Teacher.get(message.chat.id) teacher.fullname = message.text teacher.save() classroom_name_request(message)
def submission_assessment_receive(message, submission_id): teacher = Teacher.get(message.chat.id) if len(message.text) > 15: ru_text = "Длина оценки не должна превышать 15 символов. Попробуйте ещё раз" en_text = "The length of the rate mustn't exceed 15 characters. Try again" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_assessment_markup(teacher), parse_mode='Markdown') bot.register_next_step_handler(message, submission_assessment_receive, submission_id) else: submission = Submission.get(submission_id) submission.assessment = message.text submission.status = SubmissionStatus.REVIEWED.value submission.save() ru_text = "Результат проверки отправлен ученику" en_text = "The review result has been sent to the student" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=remove_markup(), parse_mode='Markdown') task = Task.get(submission.task_id) task_detail_view(teacher, task) new_submission_review_result_notification(submission)
def handle_submissions_reviewed_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) teacher = Teacher.get(call.message.chat.id) task = Task.get(data['task_id']) task_assessments_view(teacher, task) task_detail_view(teacher, task)
def handle_classroom_link_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) teacher = Teacher.get(call.message.chat.id) classroom = Classroom.get(data['classroom_id']) classroom_link_view(teacher, classroom) classroom_detail_view(teacher, classroom)
def handle_task_messages_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) task = Task.get(data['task_id']) task_message_list_view(user, task) task_detail_view(user, task)
def handle_submission_message_list_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) submission = Submission.get(data['submission_id']) task = Task.get(submission.task_id) submission_message_list_view(user, submission, task) task_detail_view(user, task)
def teacher_fullname_request(message): teacher = Teacher.get(message.chat.id) ru_text = "Введите своё ФИО. Его будут видеть ваши ученики." en_text = "Send your full name. Your students will see it." text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text) bot.register_next_step_handler(message, teacher_fullname_receive)
def classroom_name_request(message): teacher = Teacher.get(message.chat.id) ru_text = "Отправьте название класса" en_text = "Send the name of the classroom" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text) bot.register_next_step_handler(message, classroom_name_receive)
def handle_submission_review_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) submission = Submission.get(data['submission_id']) task = Task.get(submission.task_id) submission_message_list_view(user, submission, task) review_submission_scenario.submission_comment_request( call.message, data['submission_id'])
def new_task_notification(task): classroom = Classroom.get(task.classroom_id) teacher = Teacher.get(classroom.teacher_id) students = Student.get_classroom_students(classroom.id) ru_text = f"🔔 Новое задание: *{task.name}*\n\n*{classroom.name}*. Учитель: _{teacher.fullname}_" en_text = f"🔔 New task: *{task.name}*\n\n*{classroom.name}*. Teacher: _{teacher.fullname}_" for student in students: text = ru_text if student.language_code == 'ru' else en_text bot.send_message(student.id, text, parse_mode='MarkDown') task_detail_view(student, task)
def task_name_request(message, classroom_id): teacher = Teacher.get(message.chat.id) ru_text = "Отправьте название задания" en_text = "Send the name of the task" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, # reply_markup=markups.get_compose_task_markup(teacher), TODO Добавить автоматически сгенерированное задание parse_mode='Markdown') bot.register_next_step_handler(message, task_name_receive, classroom_id)
def new_submission_review_result_notification(submission): task = Task.get(submission.task_id) classroom = Classroom.get(task.classroom_id) student = Student.get(submission.student_id) teacher = Teacher.get(classroom.teacher_id) ru_text = f"🔔 Ваше задание проверено\n\n*{classroom.name}*\n_{teacher.fullname}_" en_text = f"🔔 New submission review\n\n*{classroom.name}*\n_{teacher.fullname}_" text = ru_text if student.language_code == 'ru' else en_text bot.send_message(student.id, text, parse_mode='MarkDown') submission_review_result_view(student, submission, task) task_detail_view(student, task)
def submission_assessment_request(message, submission_id): teacher = Teacher.get(message.chat.id) ru_text = "Поставьте оценку" en_text = "Rate submission" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=markups.get_assessment_markup(teacher), parse_mode='Markdown') bot.register_next_step_handler(message, submission_assessment_receive, submission_id)
def submission_comment_request(message, submission_id): teacher = Teacher.get(message.chat.id) ru_text = "Прокомментируйте задание, отправив любое сообщение" en_text = "Comment submission by sending any message" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message( message.chat.id, text, # reply_markup=markups.get_compose_task_markup(teacher), TODO Добавить клавиатуру parse_mode='Markdown') bot.register_next_step_handler(message, submission_comment_receive, submission_id)
def new_photo(message): teacher = Teacher.get(message.chat.id) if teacher: bot.delete_message(message.chat.id, message.message_id) ru_text = "Нажмите, чтобы исправить ошибки 👇🏻" en_text = "Tap to review 👇🏻" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_photo(teacher.id, message.photo[-1].file_id, caption=text, reply_markup=get_drawer_markup( message.photo[-1].file_id, teacher))
def task_name_receive(message, classroom_id): teacher = Teacher.get(message.chat.id) task = Task(classroom_id, message.text, datetime.now(timezone.utc)).save() ru_text = "Отправьте мне задание в любом формате: " \ "текст, фото, видео, файлы или аудиосообщения; одним или несколькими сообщениями." en_text = "Send me the task in any format: " \ "text, photo, video, files or audio messages; one or more messages." text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, parse_mode='Markdown') bot.register_next_step_handler(message, compose_task, task)
def student_fullname_receive(message): student = Student.get(message.chat.id) student.fullname = message.text student.save() classroom = student.get_classrooms()[-1] teacher = Teacher.get(classroom.teacher_id) ru_text = f"Вы добавлены в классную комнату *{classroom.name}*. Учитель: _{teacher.fullname}_" en_text = f"You have been added to the classroom *{classroom.name}*. Teacher: _{teacher.fullname}_" text = ru_text if student.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, parse_mode='Markdown') classroom_list_view(student)
def compose_task(message, task): teacher = Teacher.get(message.chat.id) if message.text in ['Выдать задание', 'Assign task']: ru_text = "Задание выдано вашим ученикам" en_text = "The task has been sent to your students" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=remove_markup()) classroom = Classroom.get(task.classroom_id) classroom_detail_view(teacher, classroom) new_task_notification(task) elif message.text in ['❌ Отмена', '❌ Cancel']: ru_text = "Отмена" en_text = "Cancel" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=remove_markup()) classroom = Classroom.get(task.classroom_id) classroom_detail_view(teacher, classroom) task.delete() else: task.add(message) ru_text = "Отправьте ещё что-то или нажмите *Выдать задание*" en_text = "Send something else or tap *Assign task*" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message( message.chat.id, text, reply_markup=markups.get_compose_task_markup(teacher), parse_mode='Markdown', ) bot.register_next_step_handler(message, compose_task, task)
def handle_classroom_query(call): data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) classroom = Classroom.get(data['classroom_id']) classroom_detail_view(user, classroom, message_to_edit=call.message)
def handle_classrooms_query(call): user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) classroom_list_view(user, message_to_edit=call.message)
def handle_classrooms_command(message): user = Teacher.get(message.chat.id) or Student.get(message.chat.id) classroom_list_view(user)
def classroom_name_receive(message): teacher = Teacher.get(message.chat.id) classroom = Classroom(teacher.id, message.text, created_utc=datetime.now(timezone.utc)).save() classroom_link_view(teacher, classroom) classroom_list_view(teacher)
def handle_submissions_for_review_query(call): data = get_call_data(call) teacher = Teacher.get(call.message.chat.id) task = Task.get(data['task_id']) submission_list_view(teacher, task, message_to_edit=call.message)
def classroom_name_receive(message, classroom): teacher = Teacher.get(message.chat.id) classroom.name = message.text classroom.save() classroom_detail_view(teacher, classroom)
def handle_task_query(call): data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) task = Task.get(data['task_id']) task_detail_view(user, task, message_to_edit=call.message)