Exemple #1
0
async def _start_students(ans: bots.SimpleBotEvent):
    state_storage = managers.StateStorageManager(
        students.get_system_id_of_student(ans.from_id), )
    state_storage.update(
        state=state_storage.get_id_of_state("students_select_student"))
    await ans.answer(
        "Выберите студента",
        keyboard=kbs.contacts.ContactsNavigator(
            students.get_system_id_of_student(
                ans.from_id, ), ).render().menu(),
    )
Exemple #2
0
async def _list_of_chats(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    state_store = managers.StateStorageManager(admin_id)
    state_store.update(state=state_store.get_id_of_state("pref_select_chat"))
    await ans.answer(
        "Список подключенных чатов",
        keyboard=await kbs.preferences.connected_chats(
            api_context,
            students.get_system_id_of_student(ans.from_id, ),
        ),
    )
Exemple #3
0
async def _ask_for_issue_text(ans: bots.SimpleBotEvent):
    issue_store = managers.IssueStorageManager(
        students.get_system_id_of_student(ans.from_id, ), )
    logger.debug(ans.text)
    issue_store.update(title=ans.object.object.message.text, )
    state_manager = managers.StateStorageManager(
        students.get_system_id_of_student(ans.from_id), )
    state_manager.update(
        state=state_manager.get_id_of_state("report_wait_text"), )

    await ans.answer("Отправьте текст проблемы с подробным описанием бага")
Exemple #4
0
async def _open_preferences(ans: bots.SimpleBotEvent):
    with orm.db_session:
        active_group = admin.get_active_group(
            students.get_system_id_of_student(ans.from_id), )
        group_num = active_group.group_num
        specialty = active_group.specialty

    await ans.answer(
        "Настройки\nАктивная группа: {0} ({1})".format(
            group_num,
            specialty,
        ),
        keyboard=kbs.preferences.preferences(
            students.get_system_id_of_student(ans.from_id), ),
    )
Exemple #5
0
async def _remove_list(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)

    state_store = managers.StateStorageManager(admin_id)
    state_store.update(state=state_store.get_id_of_state("groups_remove_list"))
    await ans.answer("Удалить список?",
                     keyboard=kbs.common.prompt().get_keyboard())
Exemple #6
0
async def _save_list(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)

    state_store = managers.StateStorageManager(admin_id)
    state_store.update(state=state_store.get_id_of_state("main"))

    await ans.answer("Список сохранён", keyboard=kbs.group.list_menu())
Exemple #7
0
async def _select_student(ans: bots.SimpleBotEvent):
    student_id = ans.payload.get("student_id")
    admin_id = students.get_system_id_of_student(ans.from_id)

    with orm.db_session:
        student = models.Student[student_id]
        student_dict = student.to_dict()
        student_dict["subgroup"] = student.subgroup or "Не указано"
        student_dict["group"] = student.group.group_num
        student_dict["academic_status"] = student.academic_status.description

    await redis.hmset(
        "students_selected_students:{0}".format(ans.from_id),
        student_id=student_id,
    )
    with orm.db_session:
        is_admin = students.is_admin_in_group(
            student_id,
            admin.get_active_group(admin_id).id,
        )

    await ans.answer(
        "Студент {first_name} {last_name}\nГруппа: {group}\nПодгруппа: {subgroup}\nФорма обучения: {academic_status}"
        .format(**student_dict, ),
        keyboard=kbs.students.student_card(is_admin),
    )
Exemple #8
0
async def _demote_admin(ans: bots.SimpleBotEvent):
    student_id = await redis.hget(
        "students_selected_students:{0}".format(ans.from_id),
        "student_id",
    )

    with orm.db_session:
        admin_id = students.get_system_id_of_student(ans.from_id)
        group_id = admin.get_active_group(admin_id).id

        is_admin = students.is_admin_in_group(
            student_id,
            group_id,
        )

    if int(student_id) != admin_id:
        with orm.db_session:
            models.Admin.get(student=student_id, group=group_id).delete()
            is_admin = students.is_admin_in_group(
                student_id,
                admin.get_active_group(admin_id).id,
            )
        await ans.answer(
            "Администратор разжалован",
            keyboard=kbs.students.student_card(is_admin),
        )
    else:
        await ans.answer(
            "Вы не можете разжаловать сами себя",
            keyboard=kbs.students.student_card(is_admin),
        )
Exemple #9
0
async def _delete_student(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    state_store = managers.StateStorageManager(admin_id)

    student_id = await redis.hget(
        "students_selected_students:{0}".format(ans.from_id),
        "student_id",
    )
    with orm.db_session:
        student = models.Student[student_id]
        is_admin = students.is_admin_in_group(
            student_id,
            admin.get_active_group(admin_id).id,
        )
    if int(student_id) != admin_id:
        state_store.update(
            state=state_store.get_id_of_state("students_delete_student"))
        await ans.answer(
            "Удалить студента {0} {1}?".format(student.first_name,
                                               student.last_name),
            keyboard=kbs.common.prompt().get_keyboard(),
        )
    else:
        await ans.answer(
            "Вы не можете удалить сами себя",
            keyboard=kbs.students.student_card(is_admin),
        )
Exemple #10
0
async def _show_contacts(ans: bots.SimpleBotEvent):
    student_id = await redis.hget(
        "students_selected_students:{0}".format(ans.from_id),
        "student_id",
    )
    admin_id = students.get_system_id_of_student(ans.from_id)
    with orm.db_session:
        student = models.Student[student_id]
        is_admin = students.is_admin_in_group(
            student_id,
            admin.get_active_group(admin_id).id,
        )
    email = student.email or "Не указан"
    phone_number = student.phone_number or "Не указан"
    contacts = "Контакты {0} {1}:\nВК: @id{2}\nEmail: {3}\nТелефон: {4}".format(
        student.first_name,
        student.last_name,
        student.vk_id,
        email,
        phone_number,
    )
    await ans.answer(
        contacts,
        keyboard=kbs.students.student_card(is_admin),
    )
Exemple #11
0
async def _decline_user(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    user_id = ans.payload.get("user")
    group_id = await redis.hget(
        str(user_id),
        "requested_group",
    )
    await ans.answer(
        "Вы отклонили запрос на добавление студента",
        keyboard=kbs.main.main_menu(admin_id),
    )
    await ans.api_ctx.messages.send(
        message="Администратор отклонил ваш запрос на добавление в группу",
        peer_id=user_id,
        random_id=0,
    )
    with orm.db_session:
        admins = admin.get_admins_of_group(group_id)
        for adm in admins:
            if adm.vk_id != ans.from_id:
                await ans.api_ctx.messages.send(
                    message="Другой администратор отклонил запрос пользователя",
                    peer_id=adm.vk_id,
                    random_id=0,
                    keyboard=kbs.main.main_menu(adm.student.id),
                )
Exemple #12
0
async def _register_call_message(ans: bots.SimpleBotEvent):
    attachments = ""
    message = ans.object.object.message
    raw_attachments = message.attachments
    admin_id = students.get_system_id_of_student(message.from_id)
    if message.is_cropped:
        extended_message = await ans.api_ctx.messages.get_by_id(message.id)
        raw_attachments = extended_message.response.items[0].attachments
    if raw_attachments:
        attachments = await media.load_attachments(
            api_context,
            raw_attachments,
            ans.object.object.message.peer_id,
        )
        await ans.answer("Загрузка вложений может занять некоторое время")
    state_store = managers.StateStorageManager(admin_id)
    state_store.update(
        state=state_store.get_id_of_state("mention_select_mentioned"),
    )
    mention_store = managers.MentionStorageManager(admin_id)
    mention_store.update_text(ans.object.object.message.text)
    mention_store.update_attaches(attachments)
    await ans.answer(
        "Сообщение сохранено. Выберите призываемых студентов",
        keyboard=kbs.call.CallNavigator(admin_id).render().menu(),
    )
Exemple #13
0
async def _register_students(ans: bots.SimpleBotEvent):

    admin_id = students.get_system_id_of_student(ans.from_id)
    group = managers.AdminConfigManager(admin_id).get_active_group()

    students_ids = await redis.hget(
        "index:{0}".format(ans.from_id),
        "diff_vk_db",
    )

    student_objects = await api_context.users.get(
        user_ids=students_ids.split(","))
    with orm.db_session:
        for student in student_objects.response:
            models.Student(
                first_name=student.first_name,
                last_name=student.last_name,
                vk_id=student.id,
                group=group.id,
                academic_status=1,
            )
    await ans.answer(
        "{0} студент(ов) зарегистрировано".format(len(
            student_objects.response)),
        keyboard=kbs.preferences.configure_chat(ans.payload["chat_id"]),
    )
Exemple #14
0
async def _confirm_send_alarm(ans: bots.SimpleBotEvent):

    student_id = students.get_system_id_of_student(ans.from_id)
    admin_store = managers.AdminConfigManager(student_id)
    state_storage = managers.StateStorageManager(student_id)
    state_storage.update(state=state_storage.get_id_of_state("main"))

    fin_store = managers.FinancialConfigManager(student_id)

    with orm.db_session:
        chat_vk_id = admin_store.get_active_chat().vk_id
        category_name = fin_store.get_or_create().financial_category.name
        category_sum = fin_store.get_or_create().financial_category.summ

    await ans.api_ctx.messages.send(
        peer_id=chat_vk_id,
        random_id=0,
        message="Начат сбор средств на {0}. Сумма {1} руб.".format(
            category_name,
            category_sum,
        ),
    )

    await ans.answer(
        "Сообщение отправлено",
        keyboard=kbs.finances.fin_prefs(),
    )
Exemple #15
0
    def test_get_system_id_of_existing_student(self):

        test_student_id = 549350532

        student_id = students.get_system_id_of_student(test_student_id)

        expect(student_id).is_equal(23)
Exemple #16
0
async def _custom_presets(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    group_id = admin.get_active_group(admin_id).id
    await ans.answer(
        "Список пользовательских пресетов",
        keyboard=kbs.common.custom_presets(group_id),
    )
Exemple #17
0
async def _register_category(ans: bots.SimpleBotEvent):
    if re.match(r"^\w+ \d+$", ans.object.object.message.text):
        message = ans.object.object.message
        student_id = students.get_system_id_of_student(message.from_id)
        category = finances.get_or_create_finances_category(
            admin.get_active_group(student_id).id,
            *message.text.split(),
        )
        admin_store = managers.AdminConfigManager(student_id)
        fin_store = managers.FinancialConfigManager(student_id)
        fin_store.update(financial_category=category.id)
        state_storage = managers.StateStorageManager(student_id)
        state_storage.update(
            state=state_storage.get_id_of_state("fin_send_alert"), )
        with orm.db_session:
            chat_id = admin_store.get_active_chat().vk_id

        chat_title = await chat_utils.get_chat_name(api_context, chat_id)

        await ans.answer(
            "Категория {0} зарегистрирована. Вы можете отправить сообщение о начале сбора в чат {1}"
            .format(
                category.name,
                chat_title,
            ),
            keyboard=kbs.common.confirm_with_chat_update(),
        )
    else:
        await ans.answer("Неверный формат данных")
Exemple #18
0
async def _call_by_ac_status(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    with orm.db_session:
        active_students = students.get_students_by_academic_status(
            admin.get_active_group(admin_id),
            ans.payload.get("status"),
        )
        mentioned_list = [st.id for st in active_students]
        mention_storage = managers.MentionStorageManager(admin_id)
        if set(mentioned_list).issubset(
                mention_storage.get_mentioned_students()):
            list_ = [
                elem for elem in mention_storage.get_mentioned_students()
                if elem not in mentioned_list
            ]
            logger.debug(list_)
            mention_storage.update_mentioned_students(list_)
            await ans.answer(
                "Все студенты {0} формы обучения удалены из списка Призыва".
                format(
                    models.AcademicStatus[ans.payload.get(
                        "status")].description, ), )
        else:
            mention_storage.update_mentioned_students(mentioned_list)
            await ans.answer(
                "Все студенты {0} формы обучения выбраны для Призыва".format(
                    models.AcademicStatus[ans.payload.get(
                        "status")].description, ), )
Exemple #19
0
async def _call_by_subgroup(ans: bots.SimpleBotEvent):
    admin_id: int = students.get_system_id_of_student(ans.from_id)
    with orm.db_session:
        active_students: list[
            models.Student] = students.get_active_students_by_subgroup(
                admin.get_active_group(admin_id),
                ans.payload.get("subgroup"),
            )
        mentioned_list: list[int] = [st.id for st in active_students]
        mention_storage = managers.MentionStorageManager(admin_id)

        if set(mentioned_list).issubset(
                mention_storage.get_mentioned_students()):
            mention_storage.update_mentioned_students([
                elem for elem in mention_storage.get_mentioned_students()
                if elem not in mentioned_list
            ], )
            await ans.answer(
                "Все студенты подгруппы {0} удалены из списка Призыва".format(
                    ans.payload.get("subgroup"), ), )
        else:
            mention_storage.update_mentioned_students(mentioned_list)
            await ans.answer(
                "Все студенты подгруппы {0} выбраны для Призыва".format(
                    ans.payload.get("subgroup"), ), )
Exemple #20
0
async def _call_debtors(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    group_id = admin.get_active_group(admin_id)
    state_store = managers.StateStorageManager(admin_id)
    admin_store = managers.AdminConfigManager(admin_id)
    fin_store = managers.FinancialConfigManager(admin_id)
    with orm.db_session:
        if chats.get_list_of_chats_by_group(group_id):
            category_id = fin_store.get_or_create().financial_category.id
            msgs = generate_debtors_call(category_id)
            state_store.update(state=state_store.get_id_of_state(
                "fin_confirm_debtors_call"), )
            chat_id = admin_store.get_active_chat().vk_id
            chat_title = await chat_utils.get_chat_name(api_context, chat_id)
            for msg in msgs:
                await ans.answer(msg)
            if len(msgs) > 1:
                text = "Сообщения будут отправлены в {0}"
            else:
                text = "Сообщение будет отправлено в {0}"
            await ans.answer(
                text.format(chat_title),
                keyboard=kbs.common.confirm_with_chat_update(),
            )
        else:
            await ans.answer(
                "У вашей группы нет зарегистрированных чатов. Возврат в главное меню",
                keyboard=kbs.finances.fin_category(),
            )
Exemple #21
0
async def _cancel_send_alarm(ans: bots.SimpleBotEvent):
    student_id = students.get_system_id_of_student(ans.from_id)
    state_storage = managers.StateStorageManager(student_id)
    state_storage.update(state=state_storage.get_id_of_state("main"))
    await ans.answer(
        "Хорошо, уведемление отправлено не будет",
        keyboard=kbs.finances.fin_category(),
    )
Exemple #22
0
async def _academic_statuses(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    group_id = admin.get_active_group(admin_id).id

    await ans.answer(
        "Выберите форму обучения",
        keyboard=kbs.common.academic_statuses(group_id),
    )
Exemple #23
0
async def _cancel_remove_cat(ans: bots.SimpleBotEvent):
    student_id = students.get_system_id_of_student(ans.from_id)
    state_storage = managers.StateStorageManager(student_id)
    state_storage.update(state=state_storage.get_id_of_state("main"))
    await ans.answer(
        "Отмена",
        keyboard=kbs.finances.fin_prefs(),
    )
Exemple #24
0
async def _cancel_changing_sum_of_category(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    state_store = managers.StateStorageManager(admin_id)
    state_store.update(state=state_store.get_id_of_state("main"))
    await ans.answer(
        "Изменение суммы отменено",
        keyboard=kbs.finances.fin_prefs(),
    )
Exemple #25
0
async def _cancel_creating_category(ans: bots.SimpleBotEvent):
    student_id = students.get_system_id_of_student(ans.from_id)
    state_storage = managers.StateStorageManager(student_id)
    state_storage.update(state=state_storage.get_id_of_state("main"))
    await ans.answer(
        "Создание категории отменено",
        keyboard=kbs.finances.list_of_fin_categories(student_id, ),
    )
Exemple #26
0
async def _update_category_sum(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    state_store = managers.StateStorageManager(admin_id)
    state_store.update(state=state_store.get_id_of_state("fin_wait_new_sum"))
    await ans.answer(
        "Введите новую сумму сбора",
        keyboard=kbs.common.cancel().get_keyboard(),
    )
Exemple #27
0
async def _rename_category(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    state_store = managers.StateStorageManager(admin_id)
    state_store.update(state=state_store.get_id_of_state("fin_wait_new_name"))
    await ans.answer(
        "Введите новое название категории",
        keyboard=kbs.common.cancel().get_keyboard(),
    )
Exemple #28
0
async def _select_letter(ans: bots.SimpleBotEvent):
    letter = ans.payload["value"]
    await ans.answer(
        "Список студентов на букву {0}".format(letter),
        keyboard=kbs.finances.IncomeNavigator(
            students.get_system_id_of_student(
                ans.from_id), ).render().students(letter),
    )
Exemple #29
0
async def _select_half(ans: bots.SimpleBotEvent):
    await ans.answer(
        "Выберите студента, сдавшего деньги",
        keyboard=kbs.finances.IncomeNavigator(
            students.get_system_id_of_student(
                ans.object.object.message.from_id), ).render().submenu(
                    ans.payload["half"]),
    )
Exemple #30
0
async def _cancel_saving_list(ans: bots.SimpleBotEvent):
    admin_id = students.get_system_id_of_student(ans.from_id)
    state_store = managers.StateStorageManager(admin_id)
    state_store.update(state=state_store.get_id_of_state("main"))
    await ans.answer(
        "Создание списка отменено",
        keyboard=kbs.group.list_of_lists(admin.get_active_group(admin_id).id),
    )