MihoyoBBSTools/honkai3rd.py

90 lines
4.4 KiB
Python
Raw Normal View History

import time
import tools
import config
import random
import setting
from request import http
2022-01-06 05:49:25 +00:00
from loghelper import log
2022-08-01 13:30:04 +00:00
from error import CookieError
from account import get_account_list
2021-10-25 14:53:34 +00:00
2022-01-30 03:58:31 +00:00
class Honkai3rd:
def __init__(self) -> None:
2022-08-19 00:54:54 +00:00
self.headers = {}
self.headers.update(setting.headers)
2022-08-05 04:25:10 +00:00
self.headers['DS'] = tools.get_ds(web=True)
2022-08-01 13:30:04 +00:00
self.headers['Referer'] = 'https://webstatic.mihoyo.com/bbs/event/signin/bh3/index.html?bbs_auth_required' \
f'=true&act_id={setting.honkai3rd_Act_id}&bbs_presentation_style=fullscreen' \
'&utm_source=bbs&utm_medium=mys&utm_campaign=icon'
2022-04-28 06:29:18 +00:00
self.headers['Cookie'] = config.config["account"]["cookie"]
self.headers['x-rpc-device_id'] = tools.get_device_id()
2022-08-23 15:48:58 +00:00
self.headers['User-Agent'] = f'{config.config["games"]["cn"]["useragent"]} miHoYoBBS/{setting.mihoyobbs_Version}'
2022-05-01 02:33:20 +00:00
self.account_list = get_account_list("bh3_cn", self.headers)
2022-01-30 03:58:31 +00:00
self.sign_day = 0
2022-08-01 13:30:04 +00:00
if len(self.account_list) != 0:
self.checkin_rewards = self.get_checkin_rewards()
2022-08-01 13:30:04 +00:00
def get_checkin_rewards(self) -> list:
log.info("正在获取签到奖励列表...")
req = http.get(setting.honkai3rd_checkin_rewards, headers=self.headers)
data = req.json()
if data["retcode"] != 0:
log.warning("获取签到奖励列表失败")
print(req.text)
return data["data"]["awards"]
# 判断签到
def is_sign(self, region: str, uid: str) -> dict:
req = http.get(setting.honkai3rd_Is_signurl.format(setting.honkai3rd_Act_id, region, uid), headers=self.headers)
data = req.json()
if data["retcode"] != 0:
log.warning("获取账号签到信息失败!")
print(req.text)
config.config["games"]["cn"]["honkai3rd"]["auto_checkin"] = False
config.save_config()
raise CookieError("BBS Cookie Errror")
return data["data"]
2021-10-25 14:53:34 +00:00
# 签到
2022-04-30 01:00:07 +00:00
def sign_account(self) -> str:
return_data = "崩坏3: "
2022-08-01 13:30:04 +00:00
if len(self.account_list) != 0:
2022-05-01 02:33:20 +00:00
for i in self.account_list:
2022-04-28 07:08:27 +00:00
if i[1] in config.config["games"]["cn"]["honkai3rd"]["black_list"]:
continue
2022-08-01 13:30:04 +00:00
log.info(f"正在为舰长: {i[0]}进行签到哦...")
time.sleep(random.randint(2, 8))
is_data = self.is_sign(region=i[2], uid=i[1])
# if not is_data["is_sub"]: # 这个字段不知道干啥的,就先塞这里了
if False: # 算了先改成false
log.warning(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次")
2022-02-01 16:59:27 +00:00
else:
2022-08-01 13:30:04 +00:00
sign_days = is_data["total_sign_day"] - 1
ok = True
if is_data["is_sign"]:
log.info(f"舰长:{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}")
sign_days += 1
else:
2022-08-01 13:30:04 +00:00
time.sleep(random.randint(2, 8))
req = http.post(url=setting.honkai3rd_Sign_url, headers=self.headers,
json={'act_id': setting.honkai3rd_Act_id, 'region': i[2], 'uid': i[1]})
data = req.json()
if data["retcode"] == 0:
log.info(f"舰长:{i[0]}签到成功~\r\n今天获得的奖励是"
f"{tools.get_item(self.checkin_rewards[0 if sign_days == 0 else sign_days + 1])}")
sign_days += 2
elif data["retcode"] == -5003:
log.info(f"舰长:{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}")
else:
log.warning("账号签到失败!")
ok = False
if ok:
return_data += f"\n{i[0]}已连续签到{sign_days}\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days - 1])}"
else:
return_data += f"\n{i[0]},本次签到失败"
else:
log.warning("账号没有绑定任何崩坏3账号")
return_data += "\n并没有绑定任何崩坏3账号"
2022-01-30 03:58:31 +00:00
return return_data