mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-07 12:43:35 +08:00
⚡️ 对于启动config进行懒写入
This commit is contained in:
parent
0814748eb6
commit
d0075562f0
Binary file not shown.
Before Width: | Height: | Size: 1.6 MiB |
@ -50,6 +50,7 @@ plugins_sample = {
|
||||
|
||||
class CoreConfig:
|
||||
def __init__(self) -> None:
|
||||
self.lock = False
|
||||
if OLD_CONFIG_PATH.exists():
|
||||
if not CONFIG_PATH.exists():
|
||||
shutil.copy2(OLD_CONFIG_PATH, CONFIG_PATH)
|
||||
@ -143,5 +144,15 @@ class CoreConfig:
|
||||
else:
|
||||
return False
|
||||
|
||||
def lazy_write_config(self):
|
||||
self.write_config()
|
||||
|
||||
def lazy_set_config(
|
||||
self, key: str, value: Union[str, List, Dict, int, bool]
|
||||
):
|
||||
if key in CONFIG_DEFAULT:
|
||||
# 设置值
|
||||
self.config[key] = value
|
||||
|
||||
|
||||
core_config = CoreConfig()
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 20 KiB |
@ -13,6 +13,7 @@ from fastapi import WebSocket
|
||||
|
||||
from gsuid_core.bot import _Bot
|
||||
from gsuid_core.logger import logger
|
||||
from gsuid_core.config import core_config
|
||||
from gsuid_core.utils.plugins_update.utils import check_start_tool
|
||||
from gsuid_core.utils.plugins_config.gs_config import core_plugins_config
|
||||
|
||||
@ -74,10 +75,10 @@ class GsServer:
|
||||
return f'插件{plugin.name}包含"_", 跳过加载!'
|
||||
|
||||
# 如果发现文件夹,则视为插件包
|
||||
logger.trace('===============')
|
||||
logger.debug(f'🔹 导入{plugin.stem}中...')
|
||||
logger.trace('===============')
|
||||
try:
|
||||
module_list = []
|
||||
if plugin.is_dir():
|
||||
plugin_path = plugin / '__init__.py'
|
||||
plugins_path = plugin / '__full__.py'
|
||||
@ -87,7 +88,6 @@ class GsServer:
|
||||
sys.path.append(str(plugin_path.parents))
|
||||
if plugins_path.exists():
|
||||
module_list = self.load_dir_plugins(plugin, plugin_parent)
|
||||
return module_list
|
||||
elif nest_path.exists() or src_path.exists():
|
||||
path = nest_path.parent / plugin.name
|
||||
pyproject = plugin / 'pyproject.toml'
|
||||
@ -97,7 +97,6 @@ class GsServer:
|
||||
module_list = self.load_dir_plugins(
|
||||
path, plugin_parent, True
|
||||
)
|
||||
return module_list
|
||||
# 如果文件夹内有__init_.py,则视为单个插件包
|
||||
elif plugin_path.exists():
|
||||
module_list = [
|
||||
@ -105,7 +104,6 @@ class GsServer:
|
||||
f'{plugin_parent}.{plugin.name}.__init__'
|
||||
)
|
||||
]
|
||||
return module_list
|
||||
# 如果发现单文件,则视为单文件插件
|
||||
elif plugin.suffix == '.py':
|
||||
module_list = [
|
||||
@ -113,9 +111,9 @@ class GsServer:
|
||||
f'{plugin_parent}.{plugin.name[:-3]}'
|
||||
)
|
||||
]
|
||||
return module_list
|
||||
'''导入成功'''
|
||||
logger.success(f'✅ 插件{plugin.stem}导入成功!')
|
||||
return module_list
|
||||
except Exception as e: # noqa
|
||||
exception = sys.exc_info()
|
||||
logger.opt(exception=exception).error(f'加载插件时发生错误: {e}')
|
||||
@ -134,7 +132,9 @@ class GsServer:
|
||||
# 遍历插件文件夹内所有文件
|
||||
for plugin in plug_path_list:
|
||||
self.load_plugin(plugin)
|
||||
logger.info('[GsCore] 插件加载完成!')
|
||||
|
||||
core_config.lazy_write_config()
|
||||
logger.success('[GsCore] 插件加载完成!')
|
||||
|
||||
def load_dir_plugins(
|
||||
self, plugin: Path, plugin_parent: str, nest: bool = False
|
||||
|
@ -195,7 +195,7 @@ class SV:
|
||||
config_plugins[plugins_name] = _plugins_config
|
||||
plugins = Plugins(**_plugins_config)
|
||||
|
||||
core_config.set_config('plugins', config_plugins)
|
||||
core_config.lazy_set_config('plugins', config_plugins)
|
||||
else:
|
||||
if 'prefix' not in config_plugins[plugins_name]:
|
||||
if plugins_name in SL.plugins:
|
||||
@ -236,7 +236,7 @@ class SV:
|
||||
**config_plugins[plugins_name],
|
||||
)
|
||||
|
||||
core_config.set_config('plugins', config_plugins)
|
||||
core_config.lazy_set_config('plugins', config_plugins)
|
||||
|
||||
# SV指向唯一Plugins实例
|
||||
self.plugins = plugins
|
||||
@ -261,7 +261,7 @@ class SV:
|
||||
self.area = config_sv[name]['area']
|
||||
self.white_list = config_sv[name]['white_list']
|
||||
del config_sv[name]
|
||||
core_config.set_config('sv', config_sv)
|
||||
core_config.lazy_set_config('sv', config_sv)
|
||||
elif name in plugin_sv_config:
|
||||
self.priority = plugin_sv_config[name]['priority']
|
||||
self.enabled = plugin_sv_config[name]['enabled']
|
||||
@ -303,7 +303,7 @@ class SV:
|
||||
for var in kwargs:
|
||||
setattr(self, var, kwargs[var])
|
||||
plugin_sv_config[self.name][var] = kwargs[var]
|
||||
core_config.set_config('plugins', config_plugins)
|
||||
core_config.lazy_set_config('plugins', config_plugins)
|
||||
|
||||
def enable(self):
|
||||
self.set(enabled=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user