def show_debtors_by_group_callback(message): group = message.text group_id = Group.get_id_by_group(group) if group_id is False: bot.clear_step_handler_by_chat_id(message.from_user.id) bot.send_message(chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons)) else: debtors_list = ProfcomDebtor.get_debtors_by_group(group_id) if not debtors_list: message_text = 'В цій групі немає боржників' else: debtors_str = ''.join((f'<a href="t.me/{debtor.username}">' f'{debtor.name}</a> - {ProfcomDebtor.get_debt(debtor.id)}\n' for debtor in debtors_list)) message_text = f'Боржники групи {group}:\n{debtors_str}' bot.send_message(chat_id=message.from_user.id, text=message_text, parse_mode='html', disable_web_page_preview=True) bot.send_message(chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons))
def get_group_headman_assign(message): group = message.text group_id = Group.get_id_by_group(group) if group_id is False: bot.clear_step_handler_by_chat_id(message.from_user.id) bot.send_message( chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons)) else: if not Headman.get_headman_by_group(group_id): student_keyboard = make_keyboard( keyboard_type='student', elem_list=Student.get_students_by_group(group_id), marker=f'headman_{Group.get_group_by_id(group_id)}_') bot.send_message(chat_id=message.from_user.id, text='Вибери старосту:', reply_markup=student_keyboard) else: keyboard = InlineKeyboardMarkup() keyboard.add( InlineKeyboardButton( text= f'Змінити старосту {emojize(":repeat:", use_aliases=True)}', callback_data='change_headman')) bot.send_message( chat_id=message.from_user.id, text='Цій групі вже призначено старосту.\n' 'Якщо потрібно його змінити, скористайся командою ' f'{emojize(":point_down:", use_aliases=True)}', reply_markup=keyboard)
def show_headman_info(message): group = message.text group_id = Group.get_id_by_group(group) if group_id is False: bot.clear_step_handler_by_chat_id(message.from_user.id) bot.send_message( chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons)) else: headman = Headman.get_headman_by_group(group_id) if not headman: keyboard = InlineKeyboardMarkup() keyboard.add( InlineKeyboardButton( text=f'Призначити старосту ' f'{emojize(":white_check_mark:", use_aliases=True)}', callback_data='assign_headman')) bot.send_message(chat_id=message.from_user.id, text=f'Групі {group} непризначено старосту.\n' 'Для призначення старости скористайся командою ' f'{emojize(":point_down:", use_aliases=True)}', reply_markup=keyboard) else: username = Student.get_student_by_id(headman.student_id).username name = Student.get_student_by_id(headman.student_id).name phone = Student.get_student_by_id(headman.student_id).phone bot.send_message( chat_id=message.from_user.id, text= f'Староста групи {group}: <a href="t.me/{username}">{name}</a>\n' f'Номер телефону: {phone}', parse_mode='html', disable_web_page_preview=True) bot.send_message( chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons))
def save_extragrade(message, student_id): ExtraGrade.add_extragrade(extra_grade=int(message.text), student_id=student_id) student = Student.get_student_by_id(student_id) bot.send_message(chat_id=message.from_user.id, text=f'Додатковий бал студенту ' f'<a href="t.me/{student.username}">{student.name}</a>' f' було поставлено {emojize(":white_check_mark:", use_aliases=True)}', parse_mode='html') bot.send_message(chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons))
def get_group_for_profcomdebt(message): group = message.text group_id = Group.get_id_by_group(group) if group_id is False: bot.clear_step_handler_by_chat_id(message.from_user.id) bot.send_message(chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons)) else: student_keyboard = make_keyboard(keyboard_type='student', elem_list=[student for student in Student.get_students_by_group(group_id)], marker=f'debtor_{Group.get_group_by_id(group_id)}_') bot.send_message(chat_id=message.from_user.id, text='Вибери студента:', reply_markup=student_keyboard)
def save_profcomdebtor(message, debtor_id, group): debt = message.text ProfcomDebtor.add_debtor(debtor_id, debt) username = Student.get_student_by_id(debtor_id).username name = Student.get_student_by_id(debtor_id).name bot.send_message(chat_id=message.from_user.id, text=f'Студент <a href="t.me/{username}">{name}</a> ' f'групи {group} занесений до боржників ' f'{emojize(":heavy_exclamation_mark:", use_aliases=True)}', parse_mode='html', disable_web_page_preview=True) bot.send_message(chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons))
def get_profcomdebtor_for_add(call): group = call.data.split('_')[1] debtor_id = call.data.split('_')[2] if ProfcomDebtor.debtor_exists(debtor_id): bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Студент вже занесений до боржників') bot.send_message(chat_id=call.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons)) else: bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Введи борг студента') bot.register_next_step_handler_by_chat_id(call.from_user.id, save_profcomdebtor, debtor_id, group)
def change_headman(call): group = call.data.split('_')[1] new_headman_id = call.data.split('_')[2] Headman.change_headman(new_headman_id) username = Student.get_student_by_id(new_headman_id).username name = Student.get_student_by_id(new_headman_id).name bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=f'<a href="t.me/{username}">{name}</a> ' f'призначений старостою групи {group} ' f'{emojize(":white_check_mark:", use_aliases=True)}', parse_mode='html') bot.send_message(chat_id=call.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons))
def get_group_headman_change(message): group = message.text group_id = Group.get_id_by_group(group) if group_id is False: bot.clear_step_handler_by_chat_id(message.from_user.id) bot.send_message( chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons)) else: student_keyboard = make_keyboard( keyboard_type='student', elem_list=Student.get_students_by_group(group_id), marker=f'chheadman_{Group.get_group_by_id(group_id)}_') bot.send_message(chat_id=message.from_user.id, text='Вибери нового старосту:', reply_markup=student_keyboard)
def get_profcomdebtor_for_del(call): debtor_id = call.data.split('_')[1] group = Group.get_group_by_id(Student.get_student_by_id(debtor_id).group_id) username = Student.get_student_by_id(debtor_id).username name = Student.get_student_by_id(debtor_id).name bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=f'Студент <a href="t.me/{username}">{name}</a> ' f'групи {group} видалений з боржників ' f'{emojize(":heavy_exclamation_mark:", use_aliases=True)}', parse_mode='html', disable_web_page_preview=True) ProfcomDebtor.delete_debtor(debtor_id) bot.send_message(chat_id=call.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons))
def get_group_for_del_profcomdebt(message): group = message.text group_id = Group.get_id_by_group(group) if group_id is False: bot.clear_step_handler_by_chat_id(message.from_user.id) bot.send_message(chat_id=message.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons)) else: debtor_list = ProfcomDebtor.get_debtors_by_group(group_id) debtor_list_keyboard = InlineKeyboardMarkup() if not debtor_list: message_text = 'В цій групі немає боржників' else: debtor_list_keyboard = make_keyboard(keyboard_type='student', elem_list=debtor_list, marker='deldebtor_') message_text = 'Вибери боржника:' bot.send_message(chat_id=message.from_user.id, text=message_text, reply_markup=debtor_list_keyboard)