diff --git a/liteyuki/bot/__init__.py b/liteyuki/bot/__init__.py index 49d29c89..e89d8a3a 100644 --- a/liteyuki/bot/__init__.py +++ b/liteyuki/bot/__init__.py @@ -122,8 +122,6 @@ $$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ else: cmd = "nohup" self.process_manager.terminate_all() - # 等待所有进程退出 - self.process_manager.chan_active.receive("main") # 进程退出后重启 threading.Thread(target=os.system, args=(f"{cmd} {executable} {' '.join(args)}",)).start() sys.exit(0) @@ -143,10 +141,9 @@ $$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ self.loop.create_task(self.lifespan.before_shutdown()) # 停止前钩子 if name: - self.chan_active.send(1, name) + self.process_manager.terminate(name) else: - for name in self.process_manager.targets: - self.chan_active.send(1, name) + self.process_manager.terminate_all() def init(self, *args, **kwargs): """ diff --git a/liteyuki/config.py b/liteyuki/config.py index e69de29b..4fcb8d44 100644 --- a/liteyuki/config.py +++ b/liteyuki/config.py @@ -0,0 +1,49 @@ +import os +from typing import List + +import nonebot +import yaml +from pydantic import BaseModel + + +config = {} # 主进程全局配置,确保加载后读取 + + +class SatoriNodeConfig(BaseModel): + host: str = "" + port: str = "5500" + path: str = "" + token: str = "" + + +class SatoriConfig(BaseModel): + comment: str = "These features are still in development. Do not enable in production environment." + enable: bool = False + hosts: List[SatoriNodeConfig] = [SatoriNodeConfig()] + + +class BasicConfig(BaseModel): + host: str = "127.0.0.1" + port: int = 20216 + superusers: list[str] = [] + command_start: list[str] = ["/", ""] + nickname: list[str] = [f"LiteyukiBot"] + satori: SatoriConfig = SatoriConfig() + data_path: str = "data/liteyuki" + + +def load_from_yaml(file: str) -> dict: + global config + nonebot.logger.debug("Loading config from %s" % file) + if not os.path.exists(file): + nonebot.logger.warning(f"Config file {file} not found, created default config, please modify it and restart") + with open(file, "w", encoding="utf-8") as f: + yaml.dump(BasicConfig().dict(), f, default_flow_style=False) + + with open(file, "r", encoding="utf-8") as f: + conf = yaml.load(f, Loader=yaml.FullLoader) + config = conf + if conf is None: + nonebot.logger.warning(f"Config file {file} is empty, use default config. please modify it and restart") + conf = BasicConfig().dict() + return conf diff --git a/liteyuki/utils.py b/liteyuki/utils.py index ccb67a76..14cb8ef3 100644 --- a/liteyuki/utils.py +++ b/liteyuki/utils.py @@ -4,7 +4,6 @@ """ import asyncio import inspect -import threading from pathlib import Path from typing import Any, Callable, Coroutine diff --git a/main.py b/main.py index c2a551c1..59628566 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ from liteyuki import LiteyukiBot -from src.utils import load_from_yaml +from liteyuki.config import load_from_yaml if __name__ == "__main__": bot = LiteyukiBot(**load_from_yaml("config.yml")) diff --git a/src/utils/base/config.py b/src/utils/base/config.py index 5d5c5c8f..b00f60a5 100644 --- a/src/utils/base/config.py +++ b/src/utils/base/config.py @@ -5,8 +5,6 @@ import nonebot import yaml from pydantic import BaseModel -from .data_manager import StoredConfig, TempConfig, common_db -from .ly_typing import T_Bot from ..message.tools import random_hex_string config = {} # 全局配置,确保加载后读取 @@ -70,9 +68,6 @@ def get_config(key: str, default=None): elif key in config: return config[key] - elif key in common_db.where_one(StoredConfig(), default=StoredConfig()).config: - return common_db.where_one(StoredConfig(), default=StoredConfig()).config[key] - elif key in load_from_yaml("config.yml"): return load_from_yaml("config.yml")[key] @@ -80,11 +75,6 @@ def get_config(key: str, default=None): return default -def set_stored_config(key: str, value): - temp_config: TempConfig = common_db.where_one(TempConfig(), default=TempConfig()) - temp_config.data[key] = value - common_db.save(temp_config) - def init_conf(conf: dict) -> dict: """ diff --git a/src/utils/base/data_manager.py b/src/utils/base/data_manager.py index c4176020..1ec893db 100644 --- a/src/utils/base/data_manager.py +++ b/src/utils/base/data_manager.py @@ -3,7 +3,7 @@ import os from pydantic import Field from .data import Database, LiteModel, Database - +print("导入数据库模块") DATA_PATH = "data/liteyuki" user_db: Database = Database(os.path.join(DATA_PATH, "users.ldb")) group_db: Database = Database(os.path.join(DATA_PATH, "groups.ldb"))