0
0
mirror of https://gitflic.ru/project/maks1ms/ocab.git synced 2024-12-23 16:23:01 +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:
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: "помогите | не работает"

View File

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

View File

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

View File

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

View File

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

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