Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -43,8 +43,10 @@ install(extra_lines=3)
|
|||||||
# 配置主程序日志格式
|
# 配置主程序日志格式
|
||||||
logger = get_logger("config")
|
logger = get_logger("config")
|
||||||
|
|
||||||
CONFIG_DIR = "config"
|
# 获取当前文件所在目录的父目录的父目录(即MaiBot项目根目录)
|
||||||
TEMPLATE_DIR = "template"
|
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||||
|
CONFIG_DIR = os.path.join(PROJECT_ROOT, "config")
|
||||||
|
TEMPLATE_DIR = os.path.join(PROJECT_ROOT, "template")
|
||||||
|
|
||||||
# 考虑到,实际上配置文件中的mai_version是不会自动更新的,所以采用硬编码
|
# 考虑到,实际上配置文件中的mai_version是不会自动更新的,所以采用硬编码
|
||||||
# 对该字段的更新,请严格参照语义化版本规范:https://semver.org/lang/zh-CN/
|
# 对该字段的更新,请严格参照语义化版本规范:https://semver.org/lang/zh-CN/
|
||||||
@@ -53,12 +55,12 @@ MMC_VERSION = "0.8.0-snapshot.1"
|
|||||||
|
|
||||||
def update_config():
|
def update_config():
|
||||||
# 获取根目录路径
|
# 获取根目录路径
|
||||||
old_config_dir = f"{CONFIG_DIR}/old"
|
old_config_dir = os.path.join(CONFIG_DIR, "old")
|
||||||
|
|
||||||
# 定义文件路径
|
# 定义文件路径
|
||||||
template_path = f"{TEMPLATE_DIR}/bot_config_template.toml"
|
template_path = os.path.join(TEMPLATE_DIR, "bot_config_template.toml")
|
||||||
old_config_path = f"{CONFIG_DIR}/bot_config.toml"
|
old_config_path = os.path.join(CONFIG_DIR, "bot_config.toml")
|
||||||
new_config_path = f"{CONFIG_DIR}/bot_config.toml"
|
new_config_path = os.path.join(CONFIG_DIR, "bot_config.toml")
|
||||||
|
|
||||||
# 检查配置文件是否存在
|
# 检查配置文件是否存在
|
||||||
if not os.path.exists(old_config_path):
|
if not os.path.exists(old_config_path):
|
||||||
@@ -88,11 +90,9 @@ def update_config():
|
|||||||
logger.info("已有配置文件未检测到版本号,可能是旧版本。将进行更新")
|
logger.info("已有配置文件未检测到版本号,可能是旧版本。将进行更新")
|
||||||
|
|
||||||
# 创建old目录(如果不存在)
|
# 创建old目录(如果不存在)
|
||||||
os.makedirs(old_config_dir, exist_ok=True)
|
os.makedirs(old_config_dir, exist_ok=True) # 生成带时间戳的新文件名
|
||||||
|
|
||||||
# 生成带时间戳的新文件名
|
|
||||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
old_backup_path = f"{old_config_dir}/bot_config_{timestamp}.toml"
|
old_backup_path = os.path.join(old_config_dir, f"bot_config_{timestamp}.toml")
|
||||||
|
|
||||||
# 移动旧配置文件到old目录
|
# 移动旧配置文件到old目录
|
||||||
shutil.move(old_config_path, old_backup_path)
|
shutil.move(old_config_path, old_backup_path)
|
||||||
@@ -198,5 +198,5 @@ logger.info(f"MaiCore当前版本: {MMC_VERSION}")
|
|||||||
update_config()
|
update_config()
|
||||||
|
|
||||||
logger.info("正在品鉴配置文件...")
|
logger.info("正在品鉴配置文件...")
|
||||||
global_config = load_config(config_path=f"{CONFIG_DIR}/bot_config.toml")
|
global_config = load_config(config_path=os.path.join(CONFIG_DIR, "bot_config.toml"))
|
||||||
logger.info("非常的新鲜,非常的美味!")
|
logger.info("非常的新鲜,非常的美味!")
|
||||||
|
|||||||
Reference in New Issue
Block a user