1
0
forked from bot/app

feat: 状态卡片模糊半径更改

This commit is contained in:
2024-04-11 13:15:29 +08:00
parent 79451ac24f
commit d37442bc9d
9 changed files with 151 additions and 95 deletions

View File

@ -4,6 +4,8 @@ import nonebot
import yaml
from pydantic import BaseModel
from liteyuki.utils.data_manager import StoredConfig, common_db
from liteyuki.utils.ly_typing import T_Bot
from liteyuki.utils.tools import random_hex_string
config = {} # 全局配置,确保加载后读取
@ -34,6 +36,28 @@ def load_from_yaml(file: str) -> dict:
return conf
def get_config(key: str, bot: T_Bot = None, default=None):
"""获取配置项优先级bot > config > db > yaml"""
if bot is None:
bot_config = {}
else:
bot_config = bot.config.dict()
if key in bot_config:
return bot_config[key]
elif key in config:
return config[key]
elif key in common_db.first(StoredConfig(), default=StoredConfig()).config:
return common_db.first(StoredConfig(), default=StoredConfig()).config[key]
elif key in load_from_yaml("config.yml"):
return load_from_yaml("config.yml")[key]
else:
return default
def init_conf(conf: dict) -> dict:
if "" not in conf.get("command_start", []):
conf["alconna_use_command_start"] = True

View File

@ -47,15 +47,19 @@ def load_resource_from_dir(path: str):
_loaded_resource_packs.insert(0, ResourceMetadata(**metadata))
def get_path(path: str, abs_path: bool = False, default: Any = None) -> str | Any:
def get_path(path: str, abs_path: bool = False, default: Any = None, debug: bool=False) -> str | Any:
"""
获取资源包中的文件
Args:
debug: 启用调试,每次都会先重载资源
abs_path: 是否返回绝对路径
default: 默认
path: 文件相对路径
Returns: 文件绝对路径
"""
if debug:
nonebot.logger.debug("Enable resource debug, Reloading resources")
load_resources()
resource_relative_path = os.path.join(temp_resource_root, path)
if os.path.exists(resource_relative_path):
return os.path.abspath(resource_relative_path) if abs_path else resource_relative_path