✨ 新增安全模式启动
This commit is contained in:
@ -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.")
|
||||
|
@ -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]
|
||||
|
||||
|
Reference in New Issue
Block a user