Exemple #1
0
def generate_debtors_call(admin_id: int) -> t.List[str]:
    """
    Генерирует сообщение призыва должников.

    Args:
        admin_id: идентификатор администратора

    Returns:
        List[str]: сообщение(я) призыва должников
    """
    store = db.admin.get_admin_storage(admin_id)
    debtors = db.finances.get_debtors(store.category_id)
    category = FinancialCategory.get_by_id(store.category_id)
    messages = [
        f"Вы не сдали на {category.name} сумму, указанную напротив вашего имени\n",
    ]
    for debtor_id in debtors:
        if donate := FinancialDonate.get_or_none(
            category=category.id,
            student=debtor_id,
        ):
            summ = category.summ - donate.summ
        else:
            summ = category.summ
        student = Student.get_by_id(debtor_id)
        tmp = (
            f"@id{student.vk_id} ({student.first_name} {student.second_name}) - "
            f"{summ} руб.\n"
        )
        if len(messages[-1]) < 2000:
            messages[-1] += tmp
        else:
            messages.append("")
Exemple #2
0
async def register_chat(ans: SimpleBotEvent):
    with logger.contextualize(user_id=ans.object.object.message.from_id):
        store = db.admin.get_admin_storage(
            db.students.get_system_id_of_student(ans.object.object.message.from_id),
        )
        if (
            store.confirm_message in ans.object.object.message.text
            and ans.object.object.message.from_id == Student.get_by_id(store.id).vk_id
        ):
            db.shortcuts.clear_admin_storage(
                db.students.get_system_id_of_student(ans.object.object.message.from_id),
            )

            group = db.admin.get_active_group(
                db.students.get_system_id_of_student(
                    ans.object.object.message.from_id,
                ),
            )
            if db.chats.is_chat_registered(
                ans.object.object.message.peer_id,
                group,
            ):
                await api.messages.send(
                    message="Чат уже зарегистрирован в этой группе",
                    peer_id=ans.object.object.message.from_id,
                    random_id=0,
                    keyboard=await kbs.preferences.connected_chats(
                        db.students.get_system_id_of_student(
                            ans.object.object.message.from_id,
                        ),
                    ),
                )
            else:
                chat = db.chats.register_chat(ans.object.object.message.peer_id, group)
                db.shortcuts.update_admin_storage(
                    db.students.get_system_id_of_student(
                        ans.object.object.message.from_id,
                    ),
                    current_chat_id=chat.id,
                )
                try:
                    chat_object = await api.messages.get_conversations_by_id(
                        peer_ids=ans.object.object.message.peer_id,
                    )
                    chat_name = chat_object.response.items[0].chat_settings.title
                except IndexError:
                    chat_name = "???"
                await api.messages.send(
                    message=f'Чат "{chat_name}" зарегистрирован',
                    peer_id=ans.object.object.message.from_id,
                    random_id=0,
                    keyboard=await kbs.preferences.connected_chats(
                        db.students.get_system_id_of_student(
                            ans.object.object.message.from_id,
                        ),
                    ),
                )
                await ans.answer("Привет!")
Exemple #3
0
    def test_get_list_of_students_by_letter(self):

        test_letter = "Б"
        test_user_id = 1
        test_student = Student.get_by_id(4)

        st = students.get_list_of_students_by_letter(test_user_id, test_letter)

        it(st).should.be_equal([test_student])
Exemple #4
0
async def select_student(ans: SimpleBotEvent):
    with logger.contextualize(user_id=ans.object.object.message.from_id):
        payload = hyperjson.loads(ans.object.object.message.payload)
        db.shortcuts.update_admin_storage(
            db.students.get_system_id_of_student(
                ans.object.object.message.from_id, ),
            state_id=db.bot.get_id_of_state("main"),
        )
        student = Student.get_by_id(payload.get("student_id"))
        contacts = f"""
        Контакты {student.first_name} {student.second_name}:
        ВК: @id{student.vk_id}
        Email: {student.email or "Не указан"}
        Телефон: {student.phone_number or "Не указан"}
        """
        await ans.answer(
            contacts,
            keyboard=kbs.main.main_menu(
                db.students.get_system_id_of_student(
                    ans.object.object.message.from_id), ),
        )