fix: 修复未期望的QQ群BOT启动和文件BOM的问题

This commit is contained in:
Soulter
2023-11-25 20:09:21 +08:00
parent 5a57526aab
commit 311178189f
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -372,7 +372,7 @@ def initBot(cfg, prov):
global qq_bot, qqbot_loop
qqbot_loop = asyncio.new_event_loop()
if cc.get("qqbot_appid", None) is not None and cc.get("qqbot_secret", None) is not None:
if cc.get("qqbot_appid", '') != '' and cc.get("qqbot_secret", '') != '':
gu.log("- 启用QQ群机器人 -", gu.LEVEL_INFO)
thread_inst = threading.Thread(target=run_qqbot, args=(qqbot_loop, qq_bot,), daemon=False)
thread_inst.start()
+7 -7
View File
@@ -5,7 +5,7 @@ cpath = "cmd_config.json"
def check_exist():
if not os.path.exists(cpath):
with open(cpath, "w", encoding="utf-8") as f:
with open(cpath, "w", encoding="utf-8-sig") as f:
json.dump({}, f, indent=4, ensure_ascii=False)
f.flush()
@@ -14,7 +14,7 @@ class CmdConfig():
@staticmethod
def get(key, default=None):
check_exist()
with open(cpath, "r", encoding="utf-8") as f:
with open(cpath, "r", encoding="utf-8-sig") as f:
d = json.load(f)
if key in d:
return d[key]
@@ -24,16 +24,16 @@ class CmdConfig():
@staticmethod
def get_all():
check_exist()
with open(cpath, "r", encoding="utf-8") as f:
with open(cpath, "r", encoding="utf-8-sig") as f:
return json.load(f)
@staticmethod
def put(key, value):
check_exist()
with open(cpath, "r", encoding="utf-8") as f:
with open(cpath, "r", encoding="utf-8-sig") as f:
d = json.load(f)
d[key] = value
with open(cpath, "w", encoding="utf-8") as f:
with open(cpath, "w", encoding="utf-8-sig") as f:
json.dump(d, f, indent=4, ensure_ascii=False)
f.flush()
@@ -41,7 +41,7 @@ class CmdConfig():
def init_attributes(keys: list, init_val = ""):
check_exist()
conf_str = ''
with open(cpath, "r", encoding="utf-8") as f:
with open(cpath, "r", encoding="utf-8-sig") as f:
conf_str = f.read()
if conf_str.startswith(u'/ufeff'):
conf_str = conf_str.encode('utf8')[3:].decode('utf8')
@@ -52,6 +52,6 @@ class CmdConfig():
d[k] = init_val
_tag = True
if _tag:
with open(cpath, "w", encoding="utf-8") as f:
with open(cpath, "w", encoding="utf-8-sig") as f:
json.dump(d, f, indent=4, ensure_ascii=False)
f.flush()