feat: 新的背景图
fix: 命令冲突 docs: 添加了命令头和nickname冲突的解释
This commit is contained in:
@ -55,7 +55,6 @@ def init():
|
||||
exit(1)
|
||||
auto_migrate()
|
||||
# 在加载完成语言后再初始化日志
|
||||
init_log()
|
||||
nonebot.logger.info("Liteyuki is initializing...")
|
||||
|
||||
if not os.path.exists("data/liteyuki/liteyuki.json"):
|
||||
|
@ -4,7 +4,9 @@ import nonebot
|
||||
import yaml
|
||||
from pydantic import BaseModel
|
||||
|
||||
config = {} # 全局配置
|
||||
from liteyuki.utils.tools import random_hex_string
|
||||
|
||||
config = {} # 全局配置,确保加载后读取
|
||||
|
||||
|
||||
class BasicConfig(BaseModel):
|
||||
@ -12,7 +14,7 @@ class BasicConfig(BaseModel):
|
||||
port: int = 20216
|
||||
superusers: list[str] = []
|
||||
command_start: list[str] = ["/", ""]
|
||||
nickname: list[str] = ["liteyuki"]
|
||||
nickname: list[str] = [f"LiteyukiBot-{random_hex_string(6)}"]
|
||||
|
||||
|
||||
def load_from_yaml(file: str) -> dict:
|
||||
|
@ -46,6 +46,11 @@ logger = loguru.logger.bind()
|
||||
|
||||
|
||||
def init_log():
|
||||
"""
|
||||
在语言加载完成后执行
|
||||
Returns:
|
||||
|
||||
"""
|
||||
global logger
|
||||
|
||||
config = load_from_yaml("config.yml")
|
||||
|
@ -35,7 +35,8 @@ def load_resource_from_dir(path: str):
|
||||
with open(os.path.join(path, "metadata.yml"), "r", encoding="utf-8") as f:
|
||||
metadata = yaml.safe_load(f)
|
||||
else:
|
||||
metadata = ResourceMetadata()
|
||||
# 没有metadata.yml文件,不是一个资源包
|
||||
return
|
||||
metadata["path"] = path
|
||||
if os.path.exists(os.path.join(path, "lang")):
|
||||
from liteyuki.utils.language import load_from_dir
|
||||
@ -64,4 +65,4 @@ def get_files(path: str, abs_path: bool = False) -> list[str]:
|
||||
Returns: 文件绝对路径
|
||||
"""
|
||||
return [os.path.abspath(file) for file in _resource_data if file.startswith(path)] if abs_path else [
|
||||
file for file in _resource_data if file.startswith(path)]
|
||||
file for file in _resource_data if file.startswith(path)]
|
||||
|
@ -1,3 +1,4 @@
|
||||
import random
|
||||
from importlib.metadata import PackageNotFoundError, version
|
||||
|
||||
|
||||
@ -72,3 +73,27 @@ def check_for_package(package_name: str) -> bool:
|
||||
return True
|
||||
except PackageNotFoundError:
|
||||
return False
|
||||
|
||||
|
||||
def random_ascii_string(length: int) -> str:
|
||||
"""
|
||||
生成随机ASCII字符串
|
||||
Args:
|
||||
length:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return "".join([chr(random.randint(33, 126)) for _ in range(length)])
|
||||
|
||||
|
||||
def random_hex_string(length: int) -> str:
|
||||
"""
|
||||
生成随机十六进制字符串
|
||||
Args:
|
||||
length:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return "".join([random.choice("0123456789abcdef") for _ in range(length)])
|
||||
|
Reference in New Issue
Block a user