diff --git a/docs/deployment/config.md b/docs/deployment/config.md index d109413..0a1d983 100644 --- a/docs/deployment/config.md +++ b/docs/deployment/config.md @@ -21,6 +21,7 @@ superusers: [ "1919810" ] # 超级用户列表 ``` ## **其他配置** + 以下为默认值,如需自定义请手动添加 ```yaml @@ -30,16 +31,9 @@ log_level: "INFO" # 日志等级 log_icon: true # 是否显示日志等级图标(某些控制台字体不可用) auto_report: true # 是否自动上报问题给轻雪服务器 auto_update: true # 是否自动更新轻雪,每天4点检查更新 -fake_device_info: # 用于保护设备隐私 - cpu: - brand: AMD - cores: 16 # 物理核心数 - logical_cores: 32 # 逻辑核心数 - frequency: 3600 # CPU主频:MHz - mem: - total: 32768000000 # 内存总数:字节 alconna_use_command_start: false # alconna是否使用默认指令前缀,默认false alconna_auto_completion: false # alconna是否自动补全指令,默认false,建议开启 +safe_mode: false # 安全模式,开启后将不会加载任何第三方插件 # 其他Nonebot插件的配置项 custom_config_1: "custom_value1" diff --git a/docs/deployment/fandq.md b/docs/deployment/fandq.md index 9f48b7d..4ef6d64 100644 --- a/docs/deployment/fandq.md +++ b/docs/deployment/fandq.md @@ -28,8 +28,11 @@ tag: 你需要使用Onebot标准的实现端来连接到轻雪并将消息上报给轻雪,下面已经列出一些推荐的实现端 - `Playwright`安装失败 - 输入`playwright install`安装浏览器 +- 有的插件安装后报错无法启动 + - 请先查阅插件文档,确认插件必要配置项完好后,仍然出现问题,请联系插件作者或在安全模式`safe_mode: true`下启动轻雪,在安全模式下你可以使用`npm uninstall`卸载问题插件 - 其他问题 - - 加入QQ群[775840726](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=SzmDYbfR6jY94o9KFNon7AwelRyI6M_u&authKey=ygeBdEmdFNyCWuNR4w0M1M8%2B5oDg7k%2FDfN0tzBkYcnbB%2FGHNnlVEnCIGbdftsnn7&noverify=0&group_code=775840726) + - + 加入QQ群[775840726](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=SzmDYbfR6jY94o9KFNon7AwelRyI6M_u&authKey=ygeBdEmdFNyCWuNR4w0M1M8%2B5oDg7k%2FDfN0tzBkYcnbB%2FGHNnlVEnCIGbdftsnn7&noverify=0&group_code=775840726) ## **推荐方案(QQ)** diff --git a/liteyuki/liteyuki_main/loader.py b/liteyuki/liteyuki_main/loader.py index 9f19f7c..2333ce8 100644 --- a/liteyuki/liteyuki_main/loader.py +++ b/liteyuki/liteyuki_main/loader.py @@ -1,6 +1,7 @@ import nonebot.plugin from liteyuki.utils import init_log +from liteyuki.utils.base.config import get_config from liteyuki.utils.base.data_manager import InstalledPlugin, plugin_db from liteyuki.utils.base.resource import load_resources from liteyuki.utils.message.tools import check_for_package @@ -9,13 +10,17 @@ load_resources() init_log() nonebot.plugin.load_plugins("liteyuki/plugins") -nonebot.plugin.load_plugins("plugins") # 从数据库读取已安装的插件 -installed_plugins: list[InstalledPlugin] = plugin_db.all(InstalledPlugin()) -if installed_plugins: - for installed_plugin in installed_plugins: - if not check_for_package(installed_plugin.module_name): - nonebot.logger.error(f"{installed_plugin.module_name} not installed, but in loading database. please run `npm fixup` in chat to reinstall it.") - else: - nonebot.load_plugin(installed_plugin.module_name) +if not get_config("safe_mode", False): + # 安全模式下,不加载插件 + nonebot.plugin.load_plugins("plugins") + installed_plugins: list[InstalledPlugin] = plugin_db.all(InstalledPlugin()) + if installed_plugins: + for installed_plugin in installed_plugins: + if not check_for_package(installed_plugin.module_name): + nonebot.logger.error(f"{installed_plugin.module_name} not installed, but in loading database. please run `npm fixup` in chat to reinstall it.") + else: + nonebot.load_plugin(installed_plugin.module_name) +else: + nonebot.logger.info("Safe mode is on, no plugin loaded.") diff --git a/liteyuki/utils/base/config.py b/liteyuki/utils/base/config.py index bc83306..943909f 100644 --- a/liteyuki/utils/base/config.py +++ b/liteyuki/utils/base/config.py @@ -36,12 +36,18 @@ def load_from_yaml(file: str) -> dict: return conf -def get_config(key: str, *, bot: T_Bot = None, default=None): +def get_config(key: str, default=None): """获取配置项,优先级:bot > config > db > yaml""" + try: + bot = nonebot.get_bot() + except: + bot = None + if bot is None: bot_config = {} else: bot_config = bot.config.dict() + if key in bot_config: return bot_config[key]