diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index 61474e52c..0c8345f81 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -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() diff --git a/util/cmd_config.py b/util/cmd_config.py index 0312505ee..03d81c43c 100644 --- a/util/cmd_config.py +++ b/util/cmd_config.py @@ -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() \ No newline at end of file