♻️ 将config.json
移动至data
内, 并将内置插件移动至buildin_plugins
@ -1,9 +1,8 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from gsuid_core.utils.plugins_update._plugins import update_from_git_in_tread
|
from gsuid_core.utils.plugins_update._plugins import update_from_git_in_tread
|
||||||
from gsuid_core.plugins.core_command.core_restart.restart import (
|
|
||||||
restart_genshinuid,
|
from ..core_restart.restart import restart_genshinuid
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def update_core() -> List[str]:
|
async def update_core() -> List[str]:
|
@ -5,11 +5,9 @@ from gsuid_core.bot import Bot
|
|||||||
from gsuid_core.gss import gss
|
from gsuid_core.gss import gss
|
||||||
from gsuid_core.models import Event
|
from gsuid_core.models import Event
|
||||||
from gsuid_core.logger import logger
|
from gsuid_core.logger import logger
|
||||||
from gsuid_core.plugins.core_command.core_status.command_global_val import (
|
|
||||||
save_global_val,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .restart import restart_message, restart_genshinuid
|
from .restart import restart_message, restart_genshinuid
|
||||||
|
from ..core_status.command_global_val import save_global_val
|
||||||
|
|
||||||
sv_core_config = SV('Core管理', pm=0)
|
sv_core_config = SV('Core管理', pm=0)
|
||||||
|
|
@ -7,9 +7,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
from gsuid_core.server import check_start_tool
|
from gsuid_core.server import check_start_tool
|
||||||
from gsuid_core.utils.plugins_config.gs_config import core_plugins_config
|
from gsuid_core.utils.plugins_config.gs_config import core_plugins_config
|
||||||
from gsuid_core.plugins.core_command.core_status.command_global_val import (
|
|
||||||
save_global_val,
|
from ..core_status.command_global_val import save_global_val
|
||||||
)
|
|
||||||
|
|
||||||
bot_start = Path(__file__).parents[3] / 'core.py'
|
bot_start = Path(__file__).parents[3] / 'core.py'
|
||||||
restart_sh_path = Path().cwd() / 'gs_restart.sh'
|
restart_sh_path = Path().cwd() / 'gs_restart.sh'
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 162 KiB |
@ -2,7 +2,10 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Union, Literal, overload
|
from typing import Any, Dict, List, Union, Literal, overload
|
||||||
|
|
||||||
CONFIG_PATH = Path(__file__).parent / 'config.json'
|
from gsuid_core.data_store import get_res_path
|
||||||
|
|
||||||
|
CONFIG_PATH = get_res_path() / 'config.json'
|
||||||
|
OLD_CONFIG_PATH = Path(__file__).parent / 'config.json'
|
||||||
|
|
||||||
CONFIG_DEFAULT = {
|
CONFIG_DEFAULT = {
|
||||||
'HOST': 'localhost',
|
'HOST': 'localhost',
|
||||||
@ -46,6 +49,9 @@ plugins_sample = {
|
|||||||
|
|
||||||
class CoreConfig:
|
class CoreConfig:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
if OLD_CONFIG_PATH.exists():
|
||||||
|
OLD_CONFIG_PATH.rename(CONFIG_PATH)
|
||||||
|
|
||||||
if not CONFIG_PATH.exists():
|
if not CONFIG_PATH.exists():
|
||||||
with open(CONFIG_PATH, 'w', encoding='UTF-8') as file:
|
with open(CONFIG_PATH, 'w', encoding='UTF-8') as file:
|
||||||
json.dump(CONFIG_DEFAULT, file, indent=4, ensure_ascii=False)
|
json.dump(CONFIG_DEFAULT, file, indent=4, ensure_ascii=False)
|
||||||
|
@ -23,6 +23,9 @@ core_shutdown_def = set()
|
|||||||
installed_dependencies: Dict[str, str] = {}
|
installed_dependencies: Dict[str, str] = {}
|
||||||
ignore_dep = ['python', 'fastapi', 'pydantic']
|
ignore_dep = ['python', 'fastapi', 'pydantic']
|
||||||
|
|
||||||
|
PLUGIN_PATH = Path(__file__).parent / 'plugins'
|
||||||
|
BUILDIN_PLUGIN_PATH = Path(__file__).parent / 'buildin_plugins'
|
||||||
|
|
||||||
|
|
||||||
def on_core_start(func: Callable):
|
def on_core_start(func: Callable):
|
||||||
if func not in core_start_def:
|
if func not in core_start_def:
|
||||||
@ -58,17 +61,14 @@ class GsServer:
|
|||||||
logger.info('[GsCore] 开始加载插件...')
|
logger.info('[GsCore] 开始加载插件...')
|
||||||
get_installed_dependencies()
|
get_installed_dependencies()
|
||||||
sys.path.append(str(Path(__file__).parents[1]))
|
sys.path.append(str(Path(__file__).parents[1]))
|
||||||
plug_path = Path(__file__).parent / 'plugins'
|
|
||||||
|
|
||||||
# 优先加载core_command
|
plug_path_list = list(BUILDIN_PLUGIN_PATH.iterdir()) + list(
|
||||||
plug_path_list = list(plug_path.iterdir())
|
PLUGIN_PATH.iterdir()
|
||||||
core_command_path = plug_path / 'core_command'
|
)
|
||||||
if core_command_path in plug_path_list:
|
|
||||||
plug_path_list.remove(core_command_path)
|
|
||||||
plug_path_list.insert(0, core_command_path)
|
|
||||||
|
|
||||||
# 遍历插件文件夹内所有文件
|
# 遍历插件文件夹内所有文件
|
||||||
for plugin in plug_path_list:
|
for plugin in plug_path_list:
|
||||||
|
plugin_parent = plugin.parent.name
|
||||||
if plugin.stem.startswith('_'):
|
if plugin.stem.startswith('_'):
|
||||||
continue
|
continue
|
||||||
# 如果发现文件夹,则视为插件包
|
# 如果发现文件夹,则视为插件包
|
||||||
@ -84,39 +84,24 @@ class GsServer:
|
|||||||
# 如果文件夹内有__full_.py,则视为插件包合集
|
# 如果文件夹内有__full_.py,则视为插件包合集
|
||||||
sys.path.append(str(plugin_path.parents))
|
sys.path.append(str(plugin_path.parents))
|
||||||
if plugins_path.exists():
|
if plugins_path.exists():
|
||||||
self.load_dir_plugins(plugin)
|
self.load_dir_plugins(plugin, plugin_parent)
|
||||||
elif nest_path.exists() or src_path.exists():
|
elif nest_path.exists() or src_path.exists():
|
||||||
path = nest_path.parent / plugin.name
|
path = nest_path.parent / plugin.name
|
||||||
pyproject = plugin / 'pyproject.toml'
|
pyproject = plugin / 'pyproject.toml'
|
||||||
if pyproject.exists:
|
if pyproject.exists:
|
||||||
check_pyproject(pyproject)
|
check_pyproject(pyproject)
|
||||||
if path.exists():
|
if path.exists():
|
||||||
self.load_dir_plugins(path, True)
|
self.load_dir_plugins(path, plugin_parent, True)
|
||||||
# 如果文件夹内有__init_.py,则视为单个插件包
|
# 如果文件夹内有__init_.py,则视为单个插件包
|
||||||
elif plugin_path.exists():
|
elif plugin_path.exists():
|
||||||
importlib.import_module(
|
importlib.import_module(
|
||||||
f'plugins.{plugin.name}.__init__'
|
f'{plugin_parent}.{plugin.name}.__init__'
|
||||||
)
|
)
|
||||||
# 如果发现单文件,则视为单文件插件
|
# 如果发现单文件,则视为单文件插件
|
||||||
elif plugin.suffix == '.py':
|
elif plugin.suffix == '.py':
|
||||||
importlib.import_module(f'plugins.{plugin.name[:-3]}')
|
importlib.import_module(
|
||||||
|
f'{plugin_parent}.{plugin.name[:-3]}'
|
||||||
'''trick 注释掉'''
|
)
|
||||||
'''
|
|
||||||
if plugin.stem in ['StarRailUID', 'ArknightsUID']:
|
|
||||||
logger.info('[BAI] 检测是否存在失效仓库...')
|
|
||||||
origin_url = sync_get_plugin_url(plugin)
|
|
||||||
if (
|
|
||||||
origin_url
|
|
||||||
and 'baiqwerdvd' not in origin_url
|
|
||||||
and 'qwerdvd' in origin_url
|
|
||||||
):
|
|
||||||
logger.warning(f'[BAI] 检测到失效仓库: {origin_url}')
|
|
||||||
new_url = origin_url.replace('qwerdvd', 'baiqwerdvd')
|
|
||||||
logger.success(f'[BAI] 替换新仓库地址成功: {new_url}')
|
|
||||||
sync_change_plugin_url(plugin, new_url)
|
|
||||||
'''
|
|
||||||
|
|
||||||
'''导入成功'''
|
'''导入成功'''
|
||||||
logger.success(f'插件{plugin.stem}导入成功!')
|
logger.success(f'插件{plugin.stem}导入成功!')
|
||||||
except Exception as e: # noqa
|
except Exception as e: # noqa
|
||||||
@ -126,13 +111,15 @@ class GsServer:
|
|||||||
)
|
)
|
||||||
logger.warning(f'插件{plugin.name}加载失败')
|
logger.warning(f'插件{plugin.name}加载失败')
|
||||||
|
|
||||||
def load_dir_plugins(self, plugin: Path, nest: bool = False):
|
def load_dir_plugins(
|
||||||
|
self, plugin: Path, plugin_parent: str, nest: bool = False
|
||||||
|
):
|
||||||
init_path = plugin / '__init__.py'
|
init_path = plugin / '__init__.py'
|
||||||
name = plugin.name
|
name = plugin.name
|
||||||
if init_path.exists():
|
if init_path.exists():
|
||||||
if str(init_path.parents) not in sys.path:
|
if str(init_path.parents) not in sys.path:
|
||||||
sys.path.append(str(init_path.parents))
|
sys.path.append(str(init_path.parents))
|
||||||
importlib.import_module(f'plugins.{name}.{name}.__init__')
|
importlib.import_module(f'{plugin_parent}.{name}.{name}.__init__')
|
||||||
|
|
||||||
for sub_plugin in plugin.iterdir():
|
for sub_plugin in plugin.iterdir():
|
||||||
if sub_plugin.is_dir():
|
if sub_plugin.is_dir():
|
||||||
@ -141,9 +128,9 @@ class GsServer:
|
|||||||
if str(plugin_path.parents) not in sys.path:
|
if str(plugin_path.parents) not in sys.path:
|
||||||
sys.path.append(str(plugin_path.parents))
|
sys.path.append(str(plugin_path.parents))
|
||||||
if nest:
|
if nest:
|
||||||
_p = f'plugins.{name}.{name}.{sub_plugin.name}'
|
_p = f'{plugin_parent}.{name}.{name}.{sub_plugin.name}'
|
||||||
else:
|
else:
|
||||||
_p = f'plugins.{name}.{sub_plugin.name}'
|
_p = f'{plugin_parent}.{name}.{sub_plugin.name}'
|
||||||
importlib.import_module(f'{_p}')
|
importlib.import_module(f'{_p}')
|
||||||
|
|
||||||
async def connect(self, websocket: WebSocket, bot_id: str) -> _Bot:
|
async def connect(self, websocket: WebSocket, bot_id: str) -> _Bot:
|
||||||
|
@ -172,7 +172,10 @@ class SV:
|
|||||||
file = stack[-2].filename
|
file = stack[-2].filename
|
||||||
path = Path(file)
|
path = Path(file)
|
||||||
parts = path.parts
|
parts = path.parts
|
||||||
|
if 'plugins' in parts:
|
||||||
i = parts.index('plugins')
|
i = parts.index('plugins')
|
||||||
|
else:
|
||||||
|
i = parts.index('buildin_plugins')
|
||||||
self.self_plugin_name = plugins_name = parts[i + 1]
|
self.self_plugin_name = plugins_name = parts[i + 1]
|
||||||
|
|
||||||
# 初始化
|
# 初始化
|
||||||
|