0
0
mirror of https://gitflic.ru/project/maks1ms/ocab.git synced 2024-12-24 16:44:44 +03:00
This commit is contained in:
Maxim Slipenko 2024-07-28 15:24:28 +03:00
parent 5b02c2ce6a
commit bfa1d13931
7 changed files with 35 additions and 71 deletions

View File

@ -1,2 +0,0 @@
import ocab_core
import service

View File

@ -1,21 +1,21 @@
TELEGRAM: core:
TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxx token: xxxxxxxxxxxxxxxxxxxxxxxxx
APPROVED_CHAT_ID: "-123456789 | -012345678" mode: WEBHOOK
ADMINCHATID: -12345678 webhook:
DEFAULT_CHAT_TAG: "@alt_gnome_chat" public_url: https://.../webhook
CHECK_BOT: True
YANDEXGPT: miniapp:
TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxx public_url: https://.../webapp
TOKEN_FOR_REQUEST: 8000
TOKEN_FOR_ANSWER: 2000
CATALOGID: xxxxxxxxxxxxxxxxxxxxxxxxx
PROMPT: "Ты чат-бот ..."
STARTWORD: "Бот| Бот, | бот | бот,"
INWORD: "помогите | не работает"
ROLES: filters:
ADMIN: 2 approved_chat_id: "-123456789 | -012345678"
MODERATOR: 1 default_chat_tag: "@alt_gnome_chat"
USER: 0
BOT: 3 yandexgpt:
token: xxxxxxxxxxxxxxxxxxxxxxxxx
token_for_request: 8000
token_for_answer: 2000
catalogid: xxxxxxxxxxxxxxxxxxxxxxxxx
prompt: "Ты чат-бот ..."
startword: "Бот| Бот, | бот | бот,"
inword: "помогите | не работает"

View File

@ -1,5 +1,6 @@
import asyncio import asyncio
import traceback import traceback
from typing import TYPE_CHECKING
from aiogram import Bot, Dispatcher from aiogram import Bot, Dispatcher
from fastapi import FastAPI 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.modules_system.public_api import get_module
from ocab_core.singleton import Singleton from ocab_core.singleton import Singleton
if TYPE_CHECKING:
from ocab_modules.standard.config import IConfig
ocab_modules_path = get_module_directory("ocab_modules") ocab_modules_path = get_module_directory("ocab_modules")
@ -63,7 +67,7 @@ async def webhook_mode():
def register_config(): def register_config():
config = get_module("standard.config", "config") config: "IConfig" = get_module("standard.config", "config")
config.register( config.register(
"core::token", "core::token",

View File

@ -4,14 +4,4 @@ from .config_manager import ConfigManager
IConfig = ConfigManager IConfig = ConfigManager
config: ConfigManager = ConfigManager( config: ConfigManager = ConfigManager(config_path="config.yaml")
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"]

View File

@ -1,9 +1,7 @@
import peewee as pw import peewee as pw
from aiogram.types import Message from aiogram.types import Message
from src.service import paths from .exceptions import NotExpectedModuleName
from .exceptions import MissingModuleName, NotExpectedModuleName
from .models.chat_stats import ChatStats from .models.chat_stats import ChatStats
from .models.chats import Chats from .models.chats import Chats
from .models.db import database_proxy 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): 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: if module:
raise NotExpectedModuleName() raise NotExpectedModuleName()
db_path = f"{paths.core}/database" db_path = "database"
database = pw.SqliteDatabase(f"{db_path}/OCAB.db") database = pw.SqliteDatabase(f"{db_path}/OCAB.db")
database_proxy.initialize(database) database_proxy.initialize(database)

View File

@ -1,10 +1,15 @@
from typing import TYPE_CHECKING
from aiogram import Bot from aiogram import Bot
from aiogram.filters import BaseFilter from aiogram.filters import BaseFilter
from aiogram.types import Message from aiogram.types import Message
from ocab_core.modules_system.public_api import get_module, log 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") Roles = get_module("standard.roles", "Roles")

View File

@ -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")