fix: 修复配置文件没有有效迁移的问题

This commit is contained in:
Soulter
2024-05-25 20:59:37 +08:00
parent 4d36ffcb08
commit e8773cea7f
4 changed files with 30 additions and 25 deletions
+1 -5
View File
@@ -54,8 +54,6 @@ baidu_judge = None
# CLI
PLATFORM_CLI = 'cli'
init_astrbot_config_items()
# 全局对象
_global_object: GlobalObject = None
@@ -75,9 +73,7 @@ def init():
global frequency_count, frequency_time
global _global_object
# 迁移旧配置
gu.try_migrate_config()
# 使用新配置
init_astrbot_config_items()
cfg = cc.get_all()
_event_loop = asyncio.new_event_loop()
+3 -4
View File
@@ -5,6 +5,7 @@ import warnings
import traceback
import threading
from logging import Formatter, Logger
from util.cmd_config import CmdConfig, try_migrate_config
warnings.filterwarnings("ignore")
abs_path = os.path.dirname(os.path.realpath(sys.argv[0])) + '/'
@@ -77,9 +78,9 @@ def check_env():
exit()
if __name__ == "__main__":
update_dept()
# 设置代理
from util.cmd_config import CmdConfig
try_migrate_config()
cc = CmdConfig()
http_proxy = cc.get("http_proxy")
https_proxy = cc.get("https_proxy")
@@ -88,8 +89,6 @@ if __name__ == "__main__":
if https_proxy:
os.environ['HTTPS_PROXY'] = https_proxy
os.environ['NO_PROXY'] = 'https://api.sgroup.qq.com'
update_dept()
from SparkleLogging.utils.core import LogManager
logger = LogManager.GetLogger(
+26
View File
@@ -1,5 +1,6 @@
import os
import json
import yaml
from typing import Union
cpath = "data/cmd_config.json"
@@ -117,3 +118,28 @@ def init_astrbot_config_items():
cc.init_attributes("https_proxy", "")
cc.init_attributes("dashboard_username", "")
cc.init_attributes("dashboard_password", "")
def try_migrate_config():
'''
将 cmd_config.json 迁移至 data/cmd_config.json
'''
print("try migrate configs")
if os.path.exists("cmd_config.json"):
with open("cmd_config.json", "r", encoding="utf-8-sig") as f:
data = json.load(f)
with open("data/cmd_config.json", "w", encoding="utf-8-sig") as f:
json.dump(data, f, indent=2, ensure_ascii=False)
try:
os.remove("cmd_config.json")
except Exception as e:
pass
if not os.path.exists("cmd_config.json") and not os.path.exists("data/cmd_config.json"):
# 从 configs/config.yaml 上拿数据
configs_pth = os.path.abspath(os.path.join(os.path.abspath(__file__), "../../configs/config.yaml"))
with open(configs_pth, encoding='utf-8') as f:
data = yaml.load(f, Loader=yaml.Loader)
print(data)
with open("data/cmd_config.json", "w", encoding="utf-8-sig") as f:
json.dump(data, f, indent=2, ensure_ascii=False)
-16
View File
@@ -15,7 +15,6 @@ from PIL import Image, ImageDraw, ImageFont
from type.types import GlobalObject
from SparkleLogging.utils.core import LogManager
from logging import Logger
from collections import defaultdict
logger: Logger = LogManager.GetLogger(log_name='astrbot-core')
@@ -423,21 +422,6 @@ def create_markdown_image(text: str):
raise e
def try_migrate_config():
'''
将 cmd_config.json 迁移至 data/cmd_config.json
'''
if os.path.exists("cmd_config.json"):
with open("cmd_config.json", "r", encoding="utf-8-sig") as f:
data = json.load(f)
with open("data/cmd_config.json", "w", encoding="utf-8-sig") as f:
json.dump(data, f, indent=2, ensure_ascii=False)
try:
os.remove("cmd_config.json")
except Exception as e:
pass
def get_local_ip_addresses():
ip = ''
try: