Skip to content

Commit

Permalink
feat: config更新到v12
Browse files Browse the repository at this point in the history
Signed-off-by: Womsxd <[email protected]>
  • Loading branch information
Womsxd committed Oct 10, 2024
1 parent cc216df commit 8f54582
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 42 deletions.
16 changes: 13 additions & 3 deletions cloud_genshin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@


class CloudGenshin:
def __init__(self) -> None:
def __init__(self, token) -> None:
self.headers = {
'Host': 'api-cloudgame.mihoyo.com',
'Accept': '*/*',
'Referer': 'https://app.mihoyo.com',
'x-rpc-combo_token': config.config['cloud_games']['genshin']['token'],
'x-rpc-combo_token': token,
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/99.0.4844.84 Safari/537.36',

}

def sign_account(self) -> str:
Expand All @@ -42,5 +42,15 @@ def sign_account(self) -> str:
return ret_msg


def run_task() -> str:
ret_msg = ""
cg_cn = config.config['cloud_games']['cn']
if cg_cn['genshin'] and cg_cn['genshin']['token'] == "":
return ""
cg_genshin = CloudGenshin(cg_cn['genshin']['token'])
ret_msg += cg_genshin.sign_account() + "\n\n"
return ret_msg


if __name__ == '__main__':
pass
63 changes: 36 additions & 27 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import collections
import os
import yaml
import setting
from copy import deepcopy

import tools
Expand All @@ -13,7 +12,7 @@
update_config_need = False

config = {
'enable': True, 'version': 11,
'enable': True, 'version': 12, "push": "",
'account': {'cookie': '', 'stuid': '', 'stoken': '', 'mid': ''},
'device': {'name': 'Xiaomi MI 6', 'model': 'Mi 6', 'id': ''},
'mihoyobbs': {
Expand Down Expand Up @@ -43,7 +42,14 @@
}
},
'cloud_games': {
"genshin": {'enable': False, 'token': ''}
"cn": {
"enable": False,
"genshin": {'enable': False, 'token': ""}
},
"os": {
"enable": False, 'lang': 'zh-cn',
"genshin": {'enable': False, 'token': ""}
}
},

'competition': {
Expand All @@ -66,24 +72,6 @@ def copy_config():
return config_raw


def config_v8_update(data: dict):
global update_config_need
update_config_need = True
returns = deepcopy(config)
returns["enable"] = data["enable"]
returns["account"].update(data["account"])
returns["mihoyobbs"].update(data["mihoyobbs"])
returns["cloud_games"].update(data["cloud_games"])
returns["games"]["os"].update(data["games"]["os"])
for i in data['games']['cn'].keys():
if i == "hokai2":
returns['games']['cn']['honkai2'].update(data['games']['cn']['hokai2'])
continue
returns['games']['cn'][i] = data['games']['cn'][i]
log.info("config已升级到: 8")
return returns


def config_v9_update(data: dict):
global update_config_need
update_config_need = True
Expand All @@ -97,7 +85,7 @@ def config_v9_update(data: dict):
return data


def config_v9_update_to_v11(data: dict):
def config_v9_update_to_v12(data: dict):
global update_config_need
update_config_need = True
base_config = deepcopy(config_raw)
Expand Down Expand Up @@ -127,8 +115,10 @@ def config_v9_update_to_v11(data: dict):
region_config[item] = {'checkin': item_data['auto_checkin'], 'black_list': item_data['black_list']}
else:
region_config[item] = item_data
base_config['cloud_games'] = deepcopy(data['cloud_games'])
log.info("config已升级到: 10")
base_config['cloud_games']['cn']['enable'] = data['cloud_games']['genshin']['enable']
base_config['cloud_games']['cn']['genshin']['enable'] = data['cloud_games']['genshin']['enable']
base_config['cloud_games']['cn']['genshin']['token'] = data['cloud_games']['genshin']['token']
log.info("config已升级到: 12")
return base_config


Expand All @@ -145,21 +135,40 @@ def config_v10_update(data: dict):
return data


def config_v11_update(data: dict):
global update_config_need
update_config_need = True
data['version'] = 12
new_config = {}
for key in data:
if key == "account":
new_config["push"] = ""
if key == "cloud_games":
new_config['cloud_games'] = deepcopy(config_raw['cloud_games'])
continue
new_config[key] = deepcopy(data[key])
new_config['cloud_games']['cn']['enable'] = data['cloud_games']['genshin']['enable']
new_config['cloud_games']['cn']['genshin']['enable'] = data['cloud_games']['genshin']['enable']
new_config['cloud_games']['cn']['genshin']['token'] = data['cloud_games']['genshin']['token']
log.info("config已升级到: 12")
return new_config


def load_config(p_path=None):
global config
if not p_path:
p_path = config_Path
with open(p_path, "r", encoding='utf-8') as f:
data = yaml.load(f, Loader=yaml.FullLoader)
if data['version'] != config_raw['version']:
if data['version'] == 7:
data = config_v8_update(data)
if data['version'] == 8:
data = config_v9_update(data)
if data['version'] == 9:
data = config_v9_update_to_v11(data)
data = config_v9_update_to_v12(data)
if data['version'] == 10:
data = config_v10_update(data)
if data['version'] == 11:
data = config_v11_update(data)
save_config(p_config=data)
# 去除cookie最末尾的空格
data["account"]["cookie"] = str(data["account"]["cookie"]).rstrip(' ')
Expand Down
24 changes: 17 additions & 7 deletions config/config.yaml.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#这里控制整个config文件是否启用
enable: true
#config的版本
version: 11
version: 12
# todo功能
push: ""
account:
#登入账号只需要修改cookie就行了
cookie: ""
Expand Down Expand Up @@ -91,13 +93,21 @@ games:
#云游戏专区
cloud_games:
# 控制整个云游戏的签到
enable: false
#云原神
genshin:
#开启签到
cn:
enable: false
#这里填入抓包获得的token
token: ""
#云原神
genshin:
#开启签到
enable: false
#这里填入抓包获得的token,支持多个
token: ""
# os还是todo功能
os:
lang: "zh-cn"
enable: false
genshin:
enable: false
token: ""
competition:
enable: false
genius_invokation:
Expand Down
7 changes: 2 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ def main():
if os_result != '':
return_data += "\n\n" + "海外版:" + os_result
# 云游戏
if config.config['cloud_games']['genshin']["enable"] \
and config.config['cloud_games']['genshin']['token'] != "":
if config.config['cloud_games']['cn']["enable"]:
log.info("正在进行云原神签到")
cloud_ys = cloud_genshin.CloudGenshin()
data = cloud_ys.sign_account()
return_data += "\n\n" + data
return_data += "\n\n" + cloud_genshin.run_task()
if config.config['competition']['enable']:
log.info("正在进行米游社竞赛活动签到")
competition_result = competition.run_task()
Expand Down

0 comments on commit 8f54582

Please sign in to comment.