2021-05-23 21:24:20 +08:00
|
|
|
|
import os
|
2022-08-24 01:18:17 +08:00
|
|
|
|
import yaml
|
2022-01-06 13:49:25 +08:00
|
|
|
|
from loghelper import log
|
2021-05-23 21:24:20 +08:00
|
|
|
|
|
2022-04-26 15:59:28 +08:00
|
|
|
|
# 这个字段现在还没找好塞什么地方好,就先塞config这里了
|
|
|
|
|
|
serverless = False
|
2022-08-23 23:42:46 +08:00
|
|
|
|
# 提示需要更新config版本
|
|
|
|
|
|
update_config_need = False
|
2022-04-26 15:59:28 +08:00
|
|
|
|
|
2022-05-07 15:19:18 +08:00
|
|
|
|
config = {
|
2022-08-28 17:30:28 +08:00
|
|
|
|
'enable': True, 'version': 7,
|
2022-05-07 15:19:18 +08:00
|
|
|
|
'account': {
|
|
|
|
|
|
'cookie': '',
|
|
|
|
|
|
'login_ticket': '',
|
|
|
|
|
|
'stuid': '',
|
|
|
|
|
|
'stoken': ''
|
|
|
|
|
|
},
|
|
|
|
|
|
'mihoyobbs': {
|
|
|
|
|
|
'enable': True, 'checkin': True, 'checkin_multi': True, 'checkin_multi_list': [2, 5],
|
2022-08-23 23:42:46 +08:00
|
|
|
|
'read_posts': True, 'like_posts': True, 'cancel_like_posts': True, 'share_post': True
|
2022-05-07 15:19:18 +08:00
|
|
|
|
},
|
|
|
|
|
|
'games': {
|
|
|
|
|
|
'cn': {
|
|
|
|
|
|
'enable': True,
|
2022-08-23 23:42:46 +08:00
|
|
|
|
'useragent': 'Mozilla/5.0 (Linux; Android 12; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) '
|
|
|
|
|
|
'Version/4.0 Chrome/103.0.5060.129 Mobile Safari/537.36',
|
2022-05-07 15:19:18 +08:00
|
|
|
|
'genshin': {'auto_checkin': True, 'black_list': []},
|
|
|
|
|
|
'hokai2': {'auto_checkin': False, 'black_list': []},
|
|
|
|
|
|
'honkai3rd': {'auto_checkin': False, 'black_list': []},
|
|
|
|
|
|
'tears_of_themis': {'auto_checkin': False, 'black_list': []},
|
|
|
|
|
|
},
|
|
|
|
|
|
'os': {
|
|
|
|
|
|
'enable': False, 'cookie': '',
|
|
|
|
|
|
'genshin': {'auto_checkin': False, 'black_list': []}
|
|
|
|
|
|
}
|
2022-08-27 21:51:38 +08:00
|
|
|
|
},
|
2022-08-28 17:30:28 +08:00
|
|
|
|
'cloud_games': {
|
|
|
|
|
|
"genshin": {
|
|
|
|
|
|
'enable': False,
|
|
|
|
|
|
'token': ''
|
|
|
|
|
|
}
|
2022-05-07 15:19:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-12 22:09:11 +08:00
|
|
|
|
config_raw = {}
|
|
|
|
|
|
config_raw.update(config)
|
2022-05-07 15:19:18 +08:00
|
|
|
|
|
2021-05-24 16:16:52 +08:00
|
|
|
|
path = os.path.dirname(os.path.realpath(__file__)) + "/config"
|
2022-10-04 21:19:36 +08:00
|
|
|
|
if os.getenv("AutoMihoyoBBS_config_path") is not None:
|
2022-10-04 20:07:51 +08:00
|
|
|
|
path = os.getenv("AutoMihoyoBBS_config_path")
|
2022-08-23 23:42:46 +08:00
|
|
|
|
config_Path = f"{path}/config.yaml"
|
2022-10-04 21:19:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
2022-08-28 15:59:31 +08:00
|
|
|
|
def copy_config():
|
2022-10-12 22:09:11 +08:00
|
|
|
|
return config_raw
|
2022-04-26 15:49:55 +08:00
|
|
|
|
|
2022-10-04 21:19:36 +08:00
|
|
|
|
|
2022-08-28 17:30:28 +08:00
|
|
|
|
def config_v7_update(data: dict):
|
|
|
|
|
|
global update_config_need
|
|
|
|
|
|
update_config_need = True
|
|
|
|
|
|
data['version'] = 7
|
|
|
|
|
|
data['cloud_games'] = {"genshin": {'enable': False, 'token': ''}}
|
|
|
|
|
|
log.info("config已升级到: 7")
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-28 15:59:31 +08:00
|
|
|
|
def load_config(p_path=None):
|
2022-08-23 23:42:46 +08:00
|
|
|
|
global config
|
2022-08-28 15:59:31 +08:00
|
|
|
|
if not p_path:
|
2022-10-04 21:19:36 +08:00
|
|
|
|
p_path = config_Path
|
2022-08-28 15:59:31 +08:00
|
|
|
|
with open(p_path, "r", encoding='utf-8') as f:
|
2022-08-28 17:30:28 +08:00
|
|
|
|
data = yaml.load(f, Loader=yaml.FullLoader)
|
|
|
|
|
|
if data['version'] == 7:
|
|
|
|
|
|
config = data
|
|
|
|
|
|
else:
|
|
|
|
|
|
config = config_v7_update(data)
|
|
|
|
|
|
save_config()
|
2022-08-23 23:42:46 +08:00
|
|
|
|
log.info("Config加载完毕")
|
2022-08-28 15:59:31 +08:00
|
|
|
|
return config
|
2021-05-23 21:24:20 +08:00
|
|
|
|
|
2021-10-25 22:53:34 +08:00
|
|
|
|
|
2022-10-04 21:19:36 +08:00
|
|
|
|
def save_config(p_path=None, p_config=None):
|
2022-04-26 16:15:47 +08:00
|
|
|
|
global serverless
|
2022-04-28 22:28:16 +08:00
|
|
|
|
if serverless:
|
2022-04-26 15:59:28 +08:00
|
|
|
|
log.info("云函数执行,无法保存")
|
|
|
|
|
|
return None
|
2022-08-28 15:59:31 +08:00
|
|
|
|
if not p_path:
|
2022-10-04 21:19:36 +08:00
|
|
|
|
p_path = config_Path
|
|
|
|
|
|
p_config = config
|
2022-08-28 15:59:31 +08:00
|
|
|
|
with open(p_path, "w+") as f:
|
2022-04-26 16:15:47 +08:00
|
|
|
|
try:
|
|
|
|
|
|
f.seek(0)
|
|
|
|
|
|
f.truncate()
|
2022-08-28 15:59:31 +08:00
|
|
|
|
f.write(yaml.dump(p_config, Dumper=yaml.Dumper, sort_keys=False))
|
2022-04-26 16:15:47 +08:00
|
|
|
|
f.flush()
|
|
|
|
|
|
except OSError:
|
|
|
|
|
|
serverless = True
|
|
|
|
|
|
log.info("Cookie保存失败")
|
|
|
|
|
|
exit(-1)
|
|
|
|
|
|
else:
|
|
|
|
|
|
log.info("Config保存完毕")
|
2021-05-23 21:24:20 +08:00
|
|
|
|
|
2021-10-25 22:53:34 +08:00
|
|
|
|
|
2022-01-06 13:49:25 +08:00
|
|
|
|
def clear_cookies():
|
2022-04-30 09:00:07 +08:00
|
|
|
|
global config
|
2022-04-26 16:15:47 +08:00
|
|
|
|
global serverless
|
2022-04-28 22:28:16 +08:00
|
|
|
|
if serverless:
|
2022-04-26 15:59:28 +08:00
|
|
|
|
log.info("云函数执行,无法保存")
|
|
|
|
|
|
return None
|
2021-10-25 22:53:34 +08:00
|
|
|
|
with open(config_Path, "r+") as f:
|
2022-04-30 09:00:07 +08:00
|
|
|
|
config["enable"] = False
|
|
|
|
|
|
config["account"]["login_ticket"] = ""
|
|
|
|
|
|
config["account"]["stuid"] = ""
|
|
|
|
|
|
config["account"]["stoken"] = ""
|
|
|
|
|
|
config["account"]["cookie"] = "CookieError"
|
2022-04-26 16:15:47 +08:00
|
|
|
|
try:
|
|
|
|
|
|
f.seek(0)
|
|
|
|
|
|
f.truncate()
|
2022-08-24 07:44:04 +08:00
|
|
|
|
f.write(yaml.dump(config, Dumper=yaml.Dumper, sort_keys=False))
|
2022-04-26 16:15:47 +08:00
|
|
|
|
f.flush()
|
|
|
|
|
|
except OSError:
|
|
|
|
|
|
serverless = True
|
|
|
|
|
|
log.info("Cookie删除失败")
|
|
|
|
|
|
else:
|
|
|
|
|
|
log.info("Cookie删除完毕")
|
2022-08-23 23:42:46 +08:00
|
|
|
|
|
2022-05-09 11:29:35 +08:00
|
|
|
|
|
2022-08-28 17:30:28 +08:00
|
|
|
|
def clear_cookie_cloudgame():
|
|
|
|
|
|
global config
|
|
|
|
|
|
global serverless
|
|
|
|
|
|
if serverless:
|
|
|
|
|
|
log.info("云函数执行,无法保存")
|
|
|
|
|
|
return None
|
|
|
|
|
|
config['cloud_games']['genshin']["enable"] = False
|
|
|
|
|
|
config['cloud_games']['genshin']['token'] = ""
|
|
|
|
|
|
log.info("云原神Cookie删除完毕")
|
|
|
|
|
|
save_config()
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-09 11:29:35 +08:00
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
# 初始化配置文件
|
|
|
|
|
|
# try:
|
|
|
|
|
|
# account_cookie = config['account']['cookie']
|
|
|
|
|
|
# config = load_config()
|
|
|
|
|
|
# config['account']['cookie'] = account_cookie
|
|
|
|
|
|
# except OSError:
|
|
|
|
|
|
# pass
|
|
|
|
|
|
# save_config()
|
2022-08-23 23:42:46 +08:00
|
|
|
|
# update_config()
|
2022-08-28 17:30:28 +08:00
|
|
|
|
load_config()
|
2022-08-23 23:42:46 +08:00
|
|
|
|
pass
|