diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index 0161b65..0000000 --- a/src/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -import ocab_core -import service diff --git a/src/ocab_core/example_config.yaml b/src/ocab_core/example_config.yaml index 4ed979a..0054586 100644 --- a/src/ocab_core/example_config.yaml +++ b/src/ocab_core/example_config.yaml @@ -1,21 +1,21 @@ -TELEGRAM: - TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxx - APPROVED_CHAT_ID: "-123456789 | -012345678" - ADMINCHATID: -12345678 - DEFAULT_CHAT_TAG: "@alt_gnome_chat" - CHECK_BOT: True +core: + token: xxxxxxxxxxxxxxxxxxxxxxxxx + mode: WEBHOOK + webhook: + public_url: https://.../webhook -YANDEXGPT: - TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxx - TOKEN_FOR_REQUEST: 8000 - TOKEN_FOR_ANSWER: 2000 - CATALOGID: xxxxxxxxxxxxxxxxxxxxxxxxx - PROMPT: "Ты чат-бот ..." - STARTWORD: "Бот| Бот, | бот | бот," - INWORD: "помогите | не работает" +miniapp: + public_url: https://.../webapp -ROLES: - ADMIN: 2 - MODERATOR: 1 - USER: 0 - BOT: 3 +filters: + approved_chat_id: "-123456789 | -012345678" + default_chat_tag: "@alt_gnome_chat" + +yandexgpt: + token: xxxxxxxxxxxxxxxxxxxxxxxxx + token_for_request: 8000 + token_for_answer: 2000 + catalogid: xxxxxxxxxxxxxxxxxxxxxxxxx + prompt: "Ты чат-бот ..." + startword: "Бот| Бот, | бот | бот," + inword: "помогите | не работает" diff --git a/src/ocab_core/main.py b/src/ocab_core/main.py index 04af9bc..68c80d1 100644 --- a/src/ocab_core/main.py +++ b/src/ocab_core/main.py @@ -1,5 +1,6 @@ import asyncio import traceback +from typing import TYPE_CHECKING from aiogram import Bot, Dispatcher from fastapi import FastAPI @@ -13,6 +14,9 @@ from ocab_core.modules_system.loaders import FSLoader, UnsafeFSLoader from ocab_core.modules_system.public_api import get_module from ocab_core.singleton import Singleton +if TYPE_CHECKING: + from ocab_modules.standard.config import IConfig + ocab_modules_path = get_module_directory("ocab_modules") @@ -63,7 +67,7 @@ async def webhook_mode(): def register_config(): - config = get_module("standard.config", "config") + config: "IConfig" = get_module("standard.config", "config") config.register( "core::token", diff --git a/src/ocab_modules/standard/config/config.py b/src/ocab_modules/standard/config/config.py index 8b4f487..edb91bd 100644 --- a/src/ocab_modules/standard/config/config.py +++ b/src/ocab_modules/standard/config/config.py @@ -4,14 +4,4 @@ from .config_manager import ConfigManager IConfig = ConfigManager -config: ConfigManager = ConfigManager( - config_path="/home/maxim/dev/alt-gnome-infrastructure/ocab/src/ocab_core/config.yaml" -) - - -def get_telegram_check_bot() -> bool: - return config["TELEGRAM"]["CHECK_BOT"] - - -def get_access_rights() -> dict: - return config["ACCESS_RIGHTS"] +config: ConfigManager = ConfigManager(config_path="config.yaml") diff --git a/src/ocab_modules/standard/database/db_api.py b/src/ocab_modules/standard/database/db_api.py index eb55f5a..855a673 100644 --- a/src/ocab_modules/standard/database/db_api.py +++ b/src/ocab_modules/standard/database/db_api.py @@ -1,9 +1,7 @@ import peewee as pw from aiogram.types import Message -from src.service import paths - -from .exceptions import MissingModuleName, NotExpectedModuleName +from .exceptions import NotExpectedModuleName from .models.chat_stats import ChatStats from .models.chats import Chats from .models.db import database_proxy @@ -14,14 +12,9 @@ from .models.users import Users def connect_database(is_test: bool = False, module: str | None = None): - if is_test: - if not module: - raise MissingModuleName() - db_path = f"{paths.modules_standard}/{module}/tests/database" - else: - if module: - raise NotExpectedModuleName() - db_path = f"{paths.core}/database" + if module: + raise NotExpectedModuleName() + db_path = "database" database = pw.SqliteDatabase(f"{db_path}/OCAB.db") database_proxy.initialize(database) diff --git a/src/ocab_modules/standard/filters/filters.py b/src/ocab_modules/standard/filters/filters.py index a0bbf74..6e71916 100644 --- a/src/ocab_modules/standard/filters/filters.py +++ b/src/ocab_modules/standard/filters/filters.py @@ -1,10 +1,15 @@ +from typing import TYPE_CHECKING + from aiogram import Bot from aiogram.filters import BaseFilter from aiogram.types import Message from ocab_core.modules_system.public_api import get_module, log -config = get_module("standard.config", "config") +if TYPE_CHECKING: + from ocab_modules.standard.config import IConfig + +config: "IConfig" = get_module("standard.config", "config") Roles = get_module("standard.roles", "Roles") diff --git a/src/service.py b/src/service.py deleted file mode 100644 index 5cac2dd..0000000 --- a/src/service.py +++ /dev/null @@ -1,26 +0,0 @@ -import os.path -from dataclasses import dataclass -from json import loads - - -@dataclass -class Path: - core: str - modules_standard: str - modules_external: str - - -def _get_paths(path_to_json: str): - with open(path_to_json, encoding="utf8") as f: - paths = loads(f.read()) - return Path( - core=paths["core"], - modules_standard=paths["modules standard"], - modules_external=paths["modules external"], - ) - - -cwd = os.getcwd() -cwd = cwd + "/src" - -paths = _get_paths(f"{cwd}/paths.json")