"""Функционал в чатах.""" from loguru import logger from vkwave import bots from jacob.services.logger import config as logger_config from jacob.services.media import translate_string chats_router = bots.DefaultRouter() logger.configure(**logger_config.config) @bots.simple_bot_message_handler( chats_router, bots.ChatActionFilter("chat_invite_user"), ) async def _greeting(ans: bots.SimpleBotEvent): await ans.answer("Привет!") @bots.simple_bot_message_handler( chats_router, bots.CommandsFilter("tr"), bots.MessageFromConversationTypeFilter("from_chat"), ) async def _tr_command(ans: bots.SimpleBotEvent): message = ans.object.object.message rep_msg = message.reply_message if rep_msg is not None: await ans.answer(translate_string(rep_msg.text), ) for fwd_msg in message.fwd_messages:
import os import re import ujson from pony import orm from vkwave import api, bots, client from jacob.database import models, redis from jacob.database.utils import admin, chats, finances, students from jacob.database.utils.storages import managers from jacob.services import chats as chat_utils from jacob.services import filters from jacob.services import keyboard as kbs from jacob.services.finances import generate_debtors_call finances_router = bots.DefaultRouter() api_session = api.API(tokens=os.getenv("VK_TOKEN"), clients=client.AIOHTTPClient()) api_context = api_session.get_context() @bots.simple_bot_message_handler( finances_router, filters.PLFilter({"button": "finances"}), bots.MessageFromConversationTypeFilter("from_pm"), ) async def _finances(ans: bots.SimpleBotEvent): await ans.answer( "Список финансовых категорий", keyboard=kbs.finances.list_of_fin_categories( students.get_system_id_of_student(ans.from_id), ),
import os import random import ujson from loguru import logger from pony import orm from vkwave import api, bots, client from jacob.database import models from jacob.database.utils import admin, lists, students from jacob.database.utils.storages import managers from jacob.services import call, chats, exceptions, filters from jacob.services import keyboard as kbs from jacob.services.logger import config as logger_config call_menu_router = bots.DefaultRouter() api_session = api.API( tokens=os.getenv("VK_TOKEN"), clients=client.AIOHTTPClient(), ) api_context = api_session.get_context() logger.configure(**logger_config.config) @bots.simple_bot_message_handler( call_menu_router, filters.PLFilter({"button": "half"}), filters.StateFilter("mention_select_mentioned"), bots.MessageFromConversationTypeFilter("from_pm"), ) async def _select_half(ans: bots.SimpleBotEvent):
"""Блок Студенты.""" from loguru import logger from pony import orm from vkwave import bots from jacob.database import models, redis from jacob.database.utils import admin, lists, students from jacob.database.utils.storages import managers from jacob.services import filters from jacob.services import keyboard as kbs from jacob.services.logger import config as logger_config group_router = bots.DefaultRouter() logger.configure(**logger_config.config) @bots.simple_bot_message_handler( group_router, filters.PLFilter({"button": "group_mgmt"}), bots.MessageFromConversationTypeFilter("from_pm"), ) async def _start_group(ans: bots.SimpleBotEvent): await ans.answer( "Меню группы", keyboard=kbs.group.group_menu(), ) @bots.simple_bot_message_handler( group_router,
"""Главное меню бота.""" from loguru import logger from pony import orm from vkwave import bots from jacob.database import models, redis from jacob.database.utils import admin, students from jacob.database.utils.storages import managers from jacob.services import keyboard as kbs from jacob.services.exceptions import StudentNotFound from jacob.services.filters import PLFilter, RedisStateFilter from jacob.services.logger.config import config main_router = bots.DefaultRouter() logger.configure(**config) @bots.simple_bot_message_handler( main_router, bots.TextFilter(["старт", "начать", "start", "привет", "hi", "hello"]) | PLFilter({"button": "main_menu"}), bots.MessageFromConversationTypeFilter("from_pm"), ) async def _greeting(ans: bots.SimpleBotEvent): try: student_id = students.get_system_id_of_student(ans.from_id, ) except StudentNotFound: await ans.answer( "Вы не являетесь зарегистрированным студентом.\n" + "Желаете попасть в существующую группу или создать свою?",
"""Блок Студенты.""" import re from loguru import logger from pony import orm from vkwave import bots from jacob.database import models, redis from jacob.database.utils import admin, students from jacob.database.utils.storages import managers from jacob.services import filters from jacob.services import keyboard as kbs from jacob.services.logger import config as logger_config students_router = bots.DefaultRouter() logger.configure(**logger_config.config) @bots.simple_bot_message_handler( students_router, filters.PLFilter({"button": "students"}), bots.MessageFromConversationTypeFilter("from_pm"), ) 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(
"""Модуль приглашений.""" from loguru import logger from pony import orm from vkwave import bots from jacob.database import models, redis from jacob.database.utils import admin, students from jacob.services import keyboard as kbs from jacob.services.filters import PLFilter from jacob.services.logger.config import config invite_router = bots.DefaultRouter() logger.configure(**config) @bots.simple_bot_message_handler( invite_router, PLFilter({"button": "invite_user"}), bots.MessageFromConversationTypeFilter("from_pm"), ) async def _invite_user(ans: bots.SimpleBotEvent): user_id = ans.payload.get("user") user = await ans.api_ctx.users.get(user_ids=user_id) admin_id = students.get_system_id_of_student(ans.from_id) group_id = await redis.hget( str(user_id), "requested_group", ) with orm.db_session: student = models.Student(
"""Запуск и первоначальная настройка Призыва.""" import os from loguru import logger from pony import orm from vkwave import api, bots, client from jacob.database.utils import admin, chats, students from jacob.database.utils.storages import managers from jacob.services import filters from jacob.services import keyboard as kbs from jacob.services import media from jacob.services.logger.config import config call_start_router = bots.DefaultRouter() api_session = api.API( tokens=os.getenv("VK_TOKEN"), clients=client.AIOHTTPClient(), ) api_context = api_session.get_context() logger.configure(**config) @bots.simple_bot_message_handler( call_start_router, filters.PLFilter({"button": "call"}), bots.MessageFromConversationTypeFilter("from_pm"), ) async def _start_call(ans: bots.SimpleBotEvent): admin_id = students.get_system_id_of_student(ans.object.object.message.from_id)
import os from pony import orm from vkwave import api, bots, client from jacob.database import models, redis from jacob.database import utils as db from jacob.database.utils import admin from jacob.database.utils import chats as db_chats from jacob.database.utils import groups, students from jacob.database.utils.storages import managers from jacob.services import chats, filters from jacob.services import keyboard as kbs preferences_router = bots.DefaultRouter() api_session = api.API(tokens=os.getenv("VK_TOKEN"), clients=client.AIOHTTPClient()) api_context = api_session.get_context() @bots.simple_bot_message_handler( preferences_router, filters.PLFilter({"button": "settings"}), bots.MessageFromConversationTypeFilter("from_pm"), ) 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
"""Обработка событий. Блок 'Сообщить об ошибке'.""" import os from github import Github from loguru import logger from vkwave import api, bots, client from jacob.database.utils import students from jacob.database.utils.storages import managers from jacob.services import filters from jacob.services import keyboard as kbs from jacob.services.logger import config as logger_config report_router = bots.DefaultRouter() api_session = api.API(tokens=os.getenv("VK_TOKEN"), clients=client.AIOHTTPClient()) api_context = api_session.get_context() logger.configure(**logger_config.config) @bots.simple_bot_message_handler( report_router, filters.PLFilter({"button": "report_error"}), bots.MessageFromConversationTypeFilter("from_pm"), ) async def _start_reporting(ans: bots.SimpleBotEvent): 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_title"), )