feat: Add configuration items to support custom data directories and facilitate the storage of itchat.pkl

This commit is contained in:
李超
2023-04-09 11:59:31 +08:00
parent 720de9d73f
commit 29fbf69945
2 changed files with 15 additions and 6 deletions

View File

@@ -18,7 +18,7 @@ from lib import itchat
from lib.itchat.content import *
from bridge.reply import *
from bridge.context import *
from config import conf
from config import conf, get_data_path
from common.time_check import time_checker
from common.expired_dict import ExpiredDict
from plugins import *
@@ -97,13 +97,14 @@ class WechatChannel(ChatChannel):
itchat.instance.receivingRetryCount = 600 # 修改断线超时时间
# login by scan QRCode
hotReload = conf().get('hot_reload', False)
status_path = os.path.join(get_data_path(), "itchat.pkl")
try:
itchat.auto_login(enableCmdQR=2, hotReload=hotReload, qrCallback=qrCallback)
itchat.auto_login(enableCmdQR=2, hotReload=hotReload, statusStorageDir=status_path, qrCallback=qrCallback)
except Exception as e:
if hotReload:
logger.error("Hot reload failed, try to login without hot reload")
itchat.logout()
os.remove("itchat.pkl")
os.remove(status_path)
itchat.auto_login(enableCmdQR=2, hotReload=hotReload, qrCallback=qrCallback)
else:
raise e