Example #1
0
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)
Example #2
0
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))
Example #3
0
def send_message_or_file(message, subject_id):
    if message.text == '/cancel':
        bot.send_message(chat_id=message.from_user.id,
                         text=f'Дія була скасована {emojize(":white_check_mark:", use_aliases=True)}')
        bot.clear_step_handler_by_chat_id(chat_id=message.from_user.id)
    elif message.content_type not in ['text', 'photo', 'document']:
        bot.send_message(chat_id=message.from_user.id,
                         text=f'Файл/повідомлення не відправлено {emojize(":x:", use_aliases=True)}\n'
                              'Некорректний формат\n\n'
                              'Відправте файл/повідомлення боту і він його передасть всім студентам цього предмету\n\n'
                              'Щоб скасувати дію можна скористатися командою /cancel')

        bot.register_next_step_handler(message, send_message_or_file, subject_id)
    else:
        subject = Subject.get_subject_fullname_by_id(subject_id)
        students = []

        for group in Group.get_groups():
            for student in Student.get_students_by_group(group.id):
                students.append(student)

        caption = '' if message.caption is None else message.caption

        if message.content_type == 'text':
            for student in students:
                try:
                    bot.send_message(chat_id=student.id,
                                     text=f'Повідомлення по предмету {subject}:\n\n{message.text}')
                except ApiException:
                    continue
            bot.send_message(chat_id=message.from_user.id,
                             text=f'Повідомлення було відправлено '
                                  f'{emojize(":white_check_mark:", use_aliases=True)}')
        elif message.content_type == 'document':
            for student in students:
                try:
                    bot.send_document(chat_id=student.id,
                                      data=message.document.file_id,
                                      caption=f'Методичний матеріал з предмету {subject} '
                                              f'\n\n{caption}')
                except ApiException:
                    continue
            bot.send_message(chat_id=message.from_user.id,
                             text=f'Файл було відправлено {emojize(":white_check_mark:", use_aliases=True)}')
            save_file_to_local(message.document.file_id, subject)
        elif message.content_type == 'photo':
            for student in students:
                try:
                    bot.send_photo(chat_id=student.id,
                                   photo=message.photo[-1].file_id,
                                   caption=f'Методичний матеріал з предмету {subject} '
                                           f'\n\n{caption}')

                except ApiException:
                    continue
            bot.send_message(chat_id=message.from_user.id,
                             text=f'Фото було відправлено {emojize(":white_check_mark:", use_aliases=True)}')
            save_file_to_local(message.photo[-1].file_id, subject)
Example #4
0
def get_debtors_by_group(call):
    group_keyboard = make_keyboard(keyboard_type='group',
                                   elem_list=Group.get_groups(),
                                   marker='grdebtor_')

    bot.send_message(chat_id=call.from_user.id,
                     text='Вибери групу:',
                     reply_markup=group_keyboard)

    bot.register_next_step_handler_by_chat_id(call.from_user.id, show_debtors_by_group_callback)
Example #5
0
def add_profcomdebtor(call):
    group_keyboard = make_keyboard(keyboard_type='group',
                                   elem_list=Group.get_groups(),
                                   marker='debtorgroup_')

    bot.send_message(chat_id=call.from_user.id,
                     text='Вибери групу:',
                     reply_markup=group_keyboard)

    bot.register_next_step_handler_by_chat_id(call.from_user.id, get_group_for_profcomdebt)
Example #6
0
def headman_assignment(call):
    group_keyboard = make_keyboard(keyboard_type='group',
                                   elem_list=Group.get_groups(),
                                   marker='headmangroup_')

    bot.send_message(chat_id=call.from_user.id,
                     text='Вибери групу:',
                     reply_markup=group_keyboard)

    bot.register_next_step_handler_by_chat_id(call.from_user.id,
                                              get_group_headman_assign)
Example #7
0
def headman_changing(call):
    group_keyboard = make_keyboard(keyboard_type='group',
                                   elem_list=Group.get_groups(),
                                   marker='chheadgroup_')

    bot.send_message(chat_id=call.from_user.id,
                     text='Змінити старосту групи:',
                     reply_markup=group_keyboard)

    bot.register_next_step_handler_by_chat_id(call.from_user.id,
                                              get_group_headman_change)
Example #8
0
def add_extragrade(message):

    group_keyboard = make_keyboard(keyboard_type='group',
                                   elem_list=Group.get_groups(),
                                   marker='extragradegroup_')

    bot.send_message(chat_id=message.from_user.id,
                     text='Вибери групу:',
                     reply_markup=group_keyboard)

    bot.register_next_step_handler_by_chat_id(message.from_user.id, get_group_for_extragrade)
Example #9
0
def get_grade_type(call):
    subject_id = call.data.split('_')[1]
    grade_type_id = call.data.split('_')[2]

    group_keyboard = make_keyboard(
        'student',
        Group.get_groups()[:4], f'studentsgroup_{subject_id}_{grade_type_id}_')

    bot.edit_message_text(chat_id=call.from_user.id,
                          message_id=call.message.message_id,
                          text='Виберіть групу:',
                          reply_markup=group_keyboard)
Example #10
0
def register(message):
    group_keyboard = make_keyboard(keyboard_type='group',
                                   elem_list=Group.get_groups(),
                                   marker='group_')

    bot.delete_message(chat_id=message.from_user.id,
                       message_id=message.message.message_id)

    bot.send_message(chat_id=message.from_user.id,
                     text='Вибери свою групу:',
                     reply_markup=group_keyboard)
    bot.register_next_step_handler_by_chat_id(message.from_user.id, get_group)
Example #11
0
def register_for_admins(message):
    if Student.get_student_by_id(message.from_user.id) is None:
        group_keyboard = make_keyboard(keyboard_type='group',
                                       elem_list=Group.get_groups(),
                                       marker='group_')

        bot.send_message(chat_id=message.from_user.id,
                         text='Вибери свою групу:',
                         reply_markup=group_keyboard)
        bot.register_next_step_handler_by_chat_id(message.from_user.id,
                                                  get_group)
    else:
        bot.send_message(chat_id=message.from_user.id,
                         text='Ти вже зареєстрований')
        bot.clear_step_handler_by_chat_id(chat_id=message.from_user.id)
Example #12
0
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)
Example #13
0
    def add_grades():
        if len(session.query(Grade).all()) > 0:
            return
        else:
            random.seed(5)

            for group in Group.get_groups()[:4]:
                for student in Student.get_students_by_group(group.id):
                    grade = random.randint(75, 100)
                    session.add(Grade(grade=grade,
                                      ects=Grade.convert_to_ects(grade),
                                      date=date.today().strftime("%m/%d/%Y"),
                                      gradetype_id=5,
                                      student_id=student.id,
                                      subject_id=1))
                    grade = random.randint(75, 100)
                    session.add(Grade(grade=grade,
                                      ects=Grade.convert_to_ects(grade),
                                      date=date.today().strftime("%m/%d/%Y"),
                                      gradetype_id=4,
                                      student_id=student.id,
                                      subject_id=2))
                    grade = random.randint(75, 100)
                    session.add(Grade(grade=grade,
                                      ects=Grade.convert_to_ects(grade),
                                      date=date.today().strftime("%m/%d/%Y"),
                                      gradetype_id=3,
                                      student_id=student.id,
                                      subject_id=3))
                    grade = random.randint(75, 100)
                    session.add(Grade(grade=grade,
                                      ects=Grade.convert_to_ects(grade),
                                      date=date.today().strftime("%m/%d/%Y"),
                                      gradetype_id=5,
                                      student_id=student.id,
                                      subject_id=4))
                    grade = random.randint(75, 100)
                    session.add(Grade(grade=grade,
                                      ects=Grade.convert_to_ects(grade),
                                      date=date.today().strftime("%m/%d/%Y"),
                                      gradetype_id=5,
                                      student_id=student.id,
                                      subject_id=5))
                    session.commit()

            print("grades added")
Example #14
0
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)
Example #15
0
def get_group(message):
    group_id = Group.get_id_by_group(message.text)

    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='Вибери свою групу:')

        bot.register_next_step_handler_by_chat_id(message.from_user.id,
                                                  get_group)
    else:
        student = Student()
        student.id = message.from_user.id
        student.username = message.from_user.username
        student.group_id = group_id

        message = bot.send_message(chat_id=message.from_user.id,
                                   text='Введи ПІБ українською мовою')
        bot.register_next_step_handler(message, get_name, student)
Example #16
0
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))
Example #17
0
def prepare_event_visitors_table(event_id):
    visitor_ids = EventVisitor.get_visitors(event_id)
    stud_dict = {}
    otherfac_list = []

    for visitor_id in visitor_ids:
        student = Student.get_student_by_id(visitor_id)

        if Group.get_group_by_id(student.group_id) == 'other':
            otherfac_list.append(EventVisitor.get_visitor_by_id(visitor_id).note)
        else:
            try:
                s_name = get_fio(student.name)
                s_group = f'КНТ-{Group.get_group_by_id(student.group_id)}'

                stud_dict.setdefault(s_group, []).append(s_name)
            except AttributeError:
                continue

    return stud_dict, otherfac_list
Example #18
0
def list_headman(call):
    headmans_list = Headman.get_all_headmans()
    message_text = f'<b>Старости {len(headmans_list)}/52:</b>\n\n'

    for group in Group.get_groups():
        headman = Headman.get_headman_by_group(group_id=group.id)
        if headman:
            student = Student.get_student_by_id(headman.student_id)

            link = f'<a href="t.me/{student.username}">{get_fio(student.name)}</a> ({headman.rating})\n'
        else:
            link = '-\n'

        message_text += ''.join(f'КНТ-{group.name}: {link}')

    bot.edit_message_text(chat_id=call.from_user.id,
                          message_id=call.message.message_id,
                          text=message_text,
                          parse_mode='html',
                          disable_web_page_preview=True)
Example #19
0
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))
Example #20
0
def prepare_student_events_table():
    group_dict = {}

    for group in Group.get_groups():
        students = EventVisitor.get_visitor_students(group.id)
        if not students:
            continue
        else:
            stud_dict = {}

            for student in students:
                try:
                    s_name = get_fio(Student.get_student_by_id(student[1].student_id).name)
                    s_event = Event.get_event(student[1].event_id).name

                    stud_dict.setdefault(s_name, []).append(s_event)
                except AttributeError:
                    continue

        group_dict[group.name] = stud_dict

    return group_dict
Example #21
0
def register_on_event(call):
    event_id = call.data.split('_')[1]
    chat_id = call.from_user.id

    if Group.get_group_by_id(
            Student.get_student_by_id(chat_id).group_id) == 'other':
        message = bot.send_message(
            chat_id=chat_id,
            text="Введіть прізвище ім'я факультет групу\n"
            "<b>Наприклад:</b> <i>Петров Петро ФЕУ 123</i>",
            parse_mode='html')
        bot.register_next_step_handler(message, reg_on_event_other, event_id)
    else:
        EventVisitor.add_visitor(event_id, chat_id)

        bot.edit_message_text(
            chat_id=chat_id,
            message_id=call.message.message_id,
            text=
            f'Реєстрація пройшла успішно {emojize(":white_check_mark:", use_aliases=True)}'
        )

        user = Student.get_student_by_id(chat_id)
Example #22
0
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)
Example #23
0
def add_another_fac(message):
    Student.add_student(
        Student(id=message.from_user.id,
                username=message.from_user.username,
                group_id=Group.get_id_by_group('other')))
Example #24
0
 def check_fac(id_):
     if Student.get_student_by_id(id_).group_id != Group.get_id_by_group('other'):
         return True