diff --git a/scripts/init.py b/scripts/init.py index 45d14b7..362e4da 100644 --- a/scripts/init.py +++ b/scripts/init.py @@ -6,12 +6,12 @@ def main(): pwd = Path().cwd() dir_core = pwd / "src" / "ocab_core" dir_modules_standard = pwd / "src" / "ocab_modules" / "standard" - dir_modules_custom = pwd / "src" / "ocab_modules" / "custom" + dir_modules_external = pwd / "src" / "ocab_modules" / "external" json = { "core": str(dir_core), "modules standard": str(dir_modules_standard), - "modules custom": str(dir_modules_custom), + "modules external": str(dir_modules_external), } with open("src/paths.json", "w", encoding="utf8") as f: f.write(dumps(json, indent=4)) diff --git a/src/ocab_core/main.py b/src/ocab_core/main.py index 33d8836..2960a8a 100644 --- a/src/ocab_core/main.py +++ b/src/ocab_core/main.py @@ -15,11 +15,13 @@ bot_modules = [ UnsafeFSLoader(f"{paths.modules_standard}/config"), UnsafeFSLoader(f"{paths.modules_standard}/database"), UnsafeFSLoader(f"{paths.modules_standard}/roles"), + UnsafeFSLoader(f"{paths.modules_external}/yandexgpt"), FSLoader(f"{paths.modules_standard}/command_helper"), FSLoader(f"{paths.modules_standard}/info"), FSLoader(f"{paths.modules_standard}/filters"), FSLoader(f"{paths.modules_standard}/create_report_apps"), FSLoader(f"{paths.modules_standard}/admin"), + FSLoader(f"{paths.modules_standard}/message_processing"), ] diff --git a/src/ocab_core/routers.py b/src/ocab_core/routers.py deleted file mode 100644 index 03ba987..0000000 --- a/src/ocab_core/routers.py +++ /dev/null @@ -1,15 +0,0 @@ -from aiogram import Dispatcher - -from src.ocab_modules.standard.message_processing.message_api import ( - router as process_message, -) - - -async def include_routers(dp: Dispatcher): - """ - Подключение роутеров в бота - dp.include_router() - """ - # dp.include_router(info_router) - # dp.include_router(admin_router) - dp.include_router(process_message) diff --git a/src/ocab_modules/external/yandexgpt/__init__.py b/src/ocab_modules/external/yandexgpt/__init__.py index e69de29..cb94c2b 100644 --- a/src/ocab_modules/external/yandexgpt/__init__.py +++ b/src/ocab_modules/external/yandexgpt/__init__.py @@ -0,0 +1 @@ +from .handlers import answer_to_message diff --git a/src/ocab_modules/external/yandexgpt/info.json b/src/ocab_modules/external/yandexgpt/info.json index 2c331b1..562921f 100644 --- a/src/ocab_modules/external/yandexgpt/info.json +++ b/src/ocab_modules/external/yandexgpt/info.json @@ -1,6 +1,9 @@ { - "name": "YandexGPT", +w "id": "external.yandexgpt", + "name": "Yandex GPT", "description": "Модуль для работы с Yandex GPT", "author": "OCAB Team", - "version": "1.0" + "version": "1.0.0", + "privileged": true, + "dependencies": {} } diff --git a/src/ocab_modules/standard/admin/routers.py b/src/ocab_modules/standard/admin/routers.py index 4b8ad81..b2dc7a5 100644 --- a/src/ocab_modules/standard/admin/routers.py +++ b/src/ocab_modules/standard/admin/routers.py @@ -15,9 +15,6 @@ from .handlers import ( "standard.filters", ["ChatModerOrAdminFilter", "ChatNotInApproveFilter"] ) -log(ChatModerOrAdminFilter) -log(ChatNotInApproveFilter) - router = Router() # Если сообщение содержит какой либо текст и выполняется фильтр ChatNotInApproveFilter, то вызывается функция chat_not_in_approve_list diff --git a/src/ocab_modules/standard/config/__init__.py b/src/ocab_modules/standard/config/__init__.py index a99fadf..24fd17a 100644 --- a/src/ocab_modules/standard/config/__init__.py +++ b/src/ocab_modules/standard/config/__init__.py @@ -1 +1,7 @@ -from .config import get_approved_chat_id, get_default_chat_tag, get_roles +from .config import ( + get_approved_chat_id, + get_default_chat_tag, + get_roles, + get_yandexgpt_in_words, + get_yandexgpt_start_words, +) diff --git a/src/ocab_modules/standard/message_processing/__init__.py b/src/ocab_modules/standard/message_processing/__init__.py index e69de29..90d8eda 100644 --- a/src/ocab_modules/standard/message_processing/__init__.py +++ b/src/ocab_modules/standard/message_processing/__init__.py @@ -0,0 +1 @@ +from .message_api import module_init diff --git a/src/ocab_modules/standard/message_processing/info.json b/src/ocab_modules/standard/message_processing/info.json new file mode 100644 index 0000000..b138c6a --- /dev/null +++ b/src/ocab_modules/standard/message_processing/info.json @@ -0,0 +1,13 @@ +{ + "id": "standard.message_processing", + "name": "Info", + "description": "Модуль с информацией", + "author": "OCAB Team", + "version": "1.0.0", + "privileged": false, + "dependencies": { + "standard.roles": "^1.0.0", + "standard.database": "^1.0.0", + "standard.command_helper": "^1.0.0" + } +} diff --git a/src/ocab_modules/standard/message_processing/message_api.py b/src/ocab_modules/standard/message_processing/message_api.py index bf7a613..29ceb99 100644 --- a/src/ocab_modules/standard/message_processing/message_api.py +++ b/src/ocab_modules/standard/message_processing/message_api.py @@ -2,14 +2,45 @@ from aiogram import Bot, F, Router, types -from ocab_core.logger import log -from ocab_modules.external.yandexgpt.handlers import answer_to_message -from ocab_modules.standard.config.config import ( - get_approved_chat_id, - get_yandexgpt_in_words, - get_yandexgpt_start_words, +from ocab_core.modules_system.public_api import get_module, log, register_router + +# from ocab_modules.standard.database.db_api import * + +(get_approved_chat_id, get_yandexgpt_in_words, get_yandexgpt_start_words) = get_module( + "standard.config", + ["get_approved_chat_id", "get_yandexgpt_in_words", "get_yandexgpt_start_words"], +) + +answer_to_message = get_module("external.yandexgpt", "answer_to_message") + +( + get_chat, + add_chat, + get_user, + add_user, + get_user_name, + change_user_name, + get_user_tag, + change_user_tag, + update_chat_all_stat, + update_user_all_stat, + add_message, +) = get_module( + "standard.database", + [ + "db_api.get_chat", + "db_api.add_chat", + "db_api.get_user", + "db_api.add_user", + "db_api.get_user_name", + "db_api.change_user_name", + "db_api.get_user_tag", + "db_api.change_user_tag", + "db_api.update_chat_all_stat", + "db_api.update_user_all_stat", + "db_api.add_message", + ], ) -from ocab_modules.standard.database.db_api import * async def chat_check(message: types.Message): @@ -19,15 +50,13 @@ async def chat_check(message: types.Message): if get_chat(message.chat.id) is None: if message.chat.id in get_approved_chat_id(): # print(f"Chat in approve list: {message.chat.id} {message.chat.title}") - await log(f"Chat in approve list: {message.chat.id} {message.chat.title}") + log(f"Chat in approve list: {message.chat.id} {message.chat.title}") add_chat(message.chat.id, message.chat.title) # print(f"Chat added: {message.chat.id} {message.chat.title}") - await log(f"Chat added: {message.chat.id} {message.chat.title}") + log(f"Chat added: {message.chat.id} {message.chat.title}") else: # print(f"Chat not in approve list: {message.chat.id} {message.chat.title}") - await log( - f"Chat not in approve list: {message.chat.id} {message.chat.title}" - ) + log(f"Chat not in approve list: {message.chat.id} {message.chat.title}") pass else: # Проверяем обновление названия чата @@ -36,10 +65,10 @@ async def chat_check(message: types.Message): chat.chat_name = message.chat.title chat.save() # print(f"Chat updated: {message.chat.id} {message.chat.title}") - await log(f"Chat updated: {message.chat.id} {message.chat.title}") + log(f"Chat updated: {message.chat.id} {message.chat.title}") else: # print(f"Chat already exists: {message.chat.id} {message.chat.title}") - await log(f"Chat already exists: {message.chat.id} {message.chat.title}") + log(f"Chat already exists: {message.chat.id} {message.chat.title}") pass @@ -62,23 +91,19 @@ async def user_check(message: types.Message): message.from_user.last_name, message.from_user.username, ) - # print(f"User added: {message.from_user.id} {message.from_user.first_name} {message.from_user.last_name}") - await log(f"User added: {message.from_user.id} {current_user_name}") + log(f"User added: {message.from_user.id} {current_user_name}") else: - # print(f"User already exists: {message.from_user.id} {message.from_user.first_name} {message.from_user.last_name} {message.from_user.username}") - await log( + log( f"User already exists: {message.from_user.id} {current_user_name} {message.from_user.username}" ) # Проверяем обновление имени пользователя if get_user_name(message.from_user.id) != current_user_name: change_user_name(message.from_user.id, current_user_name) - # print(f"User updated: {message.from_user.id} {message.from_user.first_name} {message.from_user.last_name}") - await log(f"User name updated: {message.from_user.id} {current_user_name}") + log(f"User name updated: {message.from_user.id} {current_user_name}") # Проверяем обновление username пользователя if get_user_tag(message.from_user.id) != message.from_user.username: change_user_tag(message.from_user.id, message.from_user.username) - # print(f"User updated: {message.from_user.id} {message.from_user.username}") - await log( + log( f"User tag updated: {message.from_user.id} {message.from_user.username}" ) pass @@ -101,17 +126,19 @@ async def message_processing(message: types.Message, bot: Bot): if (message.text.split(" ")[0] in get_yandexgpt_start_words()) or ( any(word in message.text for word in get_yandexgpt_in_words()) ): - # print("message_processing") - await log("message_processing") + log("message_processing") await answer_to_message(message, bot) elif message.reply_to_message is not None: if message.reply_to_message.from_user.is_bot: - # print("message_processing") - await log("message_processing") + log("message_processing") await answer_to_message(message, bot) router = Router() # Если сообщение содержит текст то вызывается функция message_processing router.message.register(message_processing, F.text) + + +async def module_init(): + register_router(router) diff --git a/src/service.py b/src/service.py index 64a0293..5cac2dd 100644 --- a/src/service.py +++ b/src/service.py @@ -7,7 +7,7 @@ from json import loads class Path: core: str modules_standard: str - modules_custom: str + modules_external: str def _get_paths(path_to_json: str): @@ -16,7 +16,7 @@ def _get_paths(path_to_json: str): return Path( core=paths["core"], modules_standard=paths["modules standard"], - modules_custom=paths["modules custom"], + modules_external=paths["modules external"], )