mirror of
https://github.com/TDSCDMAA/AutoMihoyoBBS.git
synced 2026-06-10 14:12:31 +08:00
崩坏2挖坑&优化重复代码&修改变量名
This commit is contained in:
parent
accb15cb1a
commit
1e1f3459a5
44
account.py
Normal file
44
account.py
Normal file
@ -0,0 +1,44 @@
|
||||
import config
|
||||
import setting
|
||||
from request import http
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
|
||||
|
||||
def game_id2name(game_id: str) -> str:
|
||||
try:
|
||||
return setting.game_id2name[game_id]
|
||||
except NameError:
|
||||
return game_id
|
||||
|
||||
|
||||
def stop_module(game_id: str) -> None:
|
||||
if game_id == "bh2_cn":
|
||||
# config.honkai2rd_Auto_sign = False
|
||||
# 崩坏2功能敬请期待
|
||||
pass
|
||||
elif game_id == "bh3_cn":
|
||||
config.honkai3rd_Auto_sign = False
|
||||
elif game_id == "nxx_cn":
|
||||
# 未定好像没米游社签到
|
||||
pass
|
||||
elif game_id == "hk4e_cn":
|
||||
config.genshin_Auto_sign = False
|
||||
else:
|
||||
raise NameError
|
||||
config.save_config()
|
||||
|
||||
|
||||
def get_account_list(game_id: str, headers: dict) -> list:
|
||||
log.info(f"正在获取米哈游账号绑定的{game_id2name(game_id)}账号列表...")
|
||||
temp_list = []
|
||||
req = http.get(setting.account_Info_url + game_id, headers=headers)
|
||||
data = req.json()
|
||||
if data["retcode"] != 0:
|
||||
log.warning(f"获取{game_id2name(game_id)}账号列表失败!")
|
||||
stop_module(game_id)
|
||||
raise CookieError("BBS Cookie Error")
|
||||
for i in data["data"]["list"]:
|
||||
temp_list.append([i["nickname"], i["game_uid"], i["region"]])
|
||||
log.info(f"已获取到{len(temp_list)}个{game_id2name(game_id)}账号信息")
|
||||
return temp_list
|
||||
12
config.py
12
config.py
@ -22,7 +22,7 @@ mihoyobbs = {
|
||||
# 1是崩坏3 2是原神 3是崩坏2 4是未定事件簿 5是大别墅
|
||||
# 可以通过设置讨论区的id位置来设置主讨论区,[5,1]就是大别墅为主社区
|
||||
# 看帖子 点赞 分享帖子都是使用主社区获取到的列表
|
||||
"bbs_Signin_multi_list": [2, 5],
|
||||
"bbs_Signin_multi_list": [],
|
||||
# 浏览3个帖子
|
||||
"bbs_Read_posts": True,
|
||||
# 完成5次点赞
|
||||
@ -57,14 +57,7 @@ def load_config():
|
||||
mihoyobbs_Stuid = data["mihoyobbs_Stuid"]
|
||||
mihoyobbs_Stoken = data["mihoyobbs_Stoken"]
|
||||
mihoyobbs_Cookies = data["mihoyobbs_Cookies"]
|
||||
mihoyobbs["bbs_Global"] = data["mihoyobbs"]["bbs_Global"]
|
||||
mihoyobbs["bbs_Signin"] = data["mihoyobbs"]["bbs_Signin"]
|
||||
mihoyobbs["bbs_Signin_multi"] = data["mihoyobbs"]["bbs_Signin_multi"]
|
||||
mihoyobbs["bbs_Signin_multi_list"] = data["mihoyobbs"]["bbs_Signin_multi_list"]
|
||||
mihoyobbs["bbs_Read_posts"] = data["mihoyobbs"]["bbs_Read_posts"]
|
||||
mihoyobbs["bbs_Like_posts"] = data["mihoyobbs"]["bbs_Like_posts"]
|
||||
mihoyobbs["bbs_Unlike"] = data["mihoyobbs"]["bbs_Unlike"]
|
||||
mihoyobbs["bbs_Share"] = data["mihoyobbs"]["bbs_Share"]
|
||||
mihoyobbs = data["mihoyobbs"]
|
||||
genshin_Auto_sign = data["genshin_Auto_sign"]
|
||||
honkai3rd_Auto_sign = data["honkai3rd_Auto_sign"]
|
||||
f.close()
|
||||
@ -101,3 +94,4 @@ def clear_cookies():
|
||||
f.flush()
|
||||
f.close()
|
||||
log.info("Cookie删除完毕")
|
||||
|
||||
|
||||
27
genshin.py
27
genshin.py
@ -6,6 +6,7 @@ import setting
|
||||
from request import http
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
from account import get_account_list
|
||||
|
||||
|
||||
class Genshin:
|
||||
@ -15,35 +16,21 @@ class Genshin:
|
||||
'DS': tools.get_ds(web=True, web_old=True),
|
||||
'Origin': 'https://webstatic.mihoyo.com',
|
||||
'x-rpc-app_version': setting.mihoyobbs_Version_old,
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0',
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0',
|
||||
'x-rpc-client_type': setting.mihoyobbs_Client_type_web,
|
||||
'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id=e202009291139501&utm_source=bbs&utm_medium=mys&utm_campaign=icon',
|
||||
'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id'
|
||||
f'={setting.genshin_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept-Language': 'zh-CN,en-US;q=0.8',
|
||||
'X-Requested-With': 'com.mihoyo.hyperion',
|
||||
"Cookie": config.mihoyobbs_Cookies,
|
||||
'x-rpc-device_id': tools.get_device_id()
|
||||
}
|
||||
self.acc_List = self.get_account_list()
|
||||
self.acc_List = get_account_list("hk4e_cn", self.headers)
|
||||
if len(self.acc_List) != 0:
|
||||
self.sign_Give = self.get_signgive()
|
||||
|
||||
# 获取绑定的账号列表
|
||||
def get_account_list(self) -> list:
|
||||
log.info("正在获取米哈游账号绑定原神账号列表...")
|
||||
temp_list = []
|
||||
req = http.get(setting.genshin_Account_info_url, headers=self.headers)
|
||||
data = req.json()
|
||||
if data["retcode"] != 0:
|
||||
log.warning("获取账号列表失败!")
|
||||
config.genshin_Auto_sign = False
|
||||
config.save_config()
|
||||
raise CookieError("BBS Cookie Errror")
|
||||
for i in data["data"]["list"]:
|
||||
temp_list.append([i["nickname"], i["game_uid"], i["region"]])
|
||||
log.info(f"已获取到{len(temp_list)}个原神账号信息")
|
||||
return temp_list
|
||||
|
||||
# 获取已经签到奖励列表
|
||||
def get_signgive(self) -> list:
|
||||
log.info("正在获取签到奖励列表...")
|
||||
@ -68,7 +55,7 @@ class Genshin:
|
||||
|
||||
# 签到
|
||||
def sign_account(self):
|
||||
return_data = "原神:"
|
||||
return_data = "原神: "
|
||||
if len(self.acc_List) != 0:
|
||||
for i in self.acc_List:
|
||||
log.info(f"正在为旅行者{i[0]}进行签到...")
|
||||
|
||||
32
honkai2.py
Normal file
32
honkai2.py
Normal file
@ -0,0 +1,32 @@
|
||||
import time
|
||||
import tools
|
||||
import config
|
||||
import random
|
||||
import setting
|
||||
from request import http
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
from account import get_account_list
|
||||
|
||||
|
||||
class Honkai2:
|
||||
def __init__(self) -> None:
|
||||
self.headers = {
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'DS': tools.get_ds(web=True, web_old=True),
|
||||
'Origin': 'https://webstatic.mihoyo.com',
|
||||
'x-rpc-app_version': setting.mihoyobbs_Version_old,
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0',
|
||||
'x-rpc-client_type': setting.mihoyobbs_Client_type_web,
|
||||
'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin/bh2/index.html?bbs_auth_required=true&'
|
||||
f'act_id={setting.honkai2_Act_id}&bbs_presentation_style=fullscreen&utm_source=bbs&'
|
||||
'utm_medium=mys&utm_campaign=icon',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept-Language': 'zh-CN,en-US;q=0.8',
|
||||
'X-Requested-With': 'com.mihoyo.hyperion',
|
||||
"Cookie": config.mihoyobbs_Cookies,
|
||||
'x-rpc-device_id': tools.get_device_id()
|
||||
}
|
||||
self.acc_List = get_account_list("bh2_cn", self.headers)
|
||||
self.sign_day = 0
|
||||
25
honkai3rd.py
25
honkai3rd.py
@ -5,7 +5,7 @@ import random
|
||||
import setting
|
||||
from request import http
|
||||
from loghelper import log
|
||||
from error import CookieError
|
||||
from account import get_account_list
|
||||
|
||||
|
||||
class Honkai3rd:
|
||||
@ -27,25 +27,9 @@ class Honkai3rd:
|
||||
"Cookie": config.mihoyobbs_Cookies,
|
||||
'x-rpc-device_id': tools.get_device_id()
|
||||
}
|
||||
self.acc_List = self.get_account_list()
|
||||
self.acc_List = get_account_list("bh3_cn", self.headers)
|
||||
self.sign_day = 0
|
||||
|
||||
# 获取绑定的账号列表
|
||||
def get_account_list(self) -> list:
|
||||
log.info("正在获取米哈游账号绑定的崩坏3账号列表...")
|
||||
temp_list = []
|
||||
req = http.get(setting.honkai3rd_Account_info_url, headers=self.headers)
|
||||
data = req.json()
|
||||
if data["retcode"] != 0:
|
||||
log.warning("获取账号列表失败!")
|
||||
config.honkai3rd_Auto_sign = False
|
||||
config.save_config()
|
||||
raise CookieError("BBS Cookie Error")
|
||||
for i in data["data"]["list"]:
|
||||
temp_list.append([i["nickname"], i["game_uid"], i["region"]])
|
||||
log.info(f"已获取到{len(temp_list)}个崩坏3账号信息")
|
||||
return temp_list
|
||||
|
||||
# 获取今天已经签到了的dict
|
||||
def get_today_item(self, raw_data: list):
|
||||
# 用range进行循环,当status等于0的时候上一个就是今天签到的dict
|
||||
@ -61,14 +45,15 @@ class Honkai3rd:
|
||||
|
||||
# 签到
|
||||
def sign_account(self):
|
||||
return_data = "崩坏3:"
|
||||
return_data = "崩坏3: "
|
||||
if len(self.acc_List) == 0:
|
||||
log.warning("账号没有绑定任何崩坏3账号!")
|
||||
return_data += "\n并没有绑定任何崩坏3账号"
|
||||
else:
|
||||
for i in self.acc_List:
|
||||
log.info(f"正在为舰长 {i[0]} 进行签到...")
|
||||
req = http.get(setting.honkai3rd_Is_signurl.format(setting.honkai3rd_Act_id, i[2], i[1]), headers=self.headers)
|
||||
req = http.get(setting.honkai3rd_Is_signurl.format(setting.honkai3rd_Act_id, i[2], i[1]),
|
||||
headers=self.headers)
|
||||
data = req.json()
|
||||
re_message = ""
|
||||
if data["retcode"] != 0:
|
||||
|
||||
4
login.py
4
login.py
@ -18,10 +18,10 @@ def login():
|
||||
config.mihoyobbs_Login_ticket = i.split("=")[1]
|
||||
break
|
||||
# 这里获取Stuid,但是实际是可以直接拿cookie里面的Uid
|
||||
data = request.get(url=setting.bbs_Cookieurl.format(config.mihoyobbs_Login_ticket))
|
||||
data = request.get(url=setting.bbs_Cookie_url.format(config.mihoyobbs_Login_ticket))
|
||||
if "成功" in data["data"]["msg"]:
|
||||
config.mihoyobbs_Stuid = str(data["data"]["cookie_info"]["account_id"])
|
||||
data = request.get(url=setting.bbs_Cookieurl2.format(config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid))
|
||||
data = request.get(url=setting.bbs_Cookie_url2.format(config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid))
|
||||
config.mihoyobbs_Stoken = data["data"]["list"][0]["token"]
|
||||
log.info("登录成功!")
|
||||
log.info("正在保存Config!")
|
||||
|
||||
14
mihoyobbs.py
14
mihoyobbs.py
@ -50,7 +50,7 @@ class mihoyobbs:
|
||||
global Today_have_getcoins
|
||||
global Have_coins
|
||||
log.info("正在获取任务列表")
|
||||
req = http.get(url=setting.bbs_Taskslist, headers=self.headers)
|
||||
req = http.get(url=setting.bbs_Tasks_list, headers=self.headers)
|
||||
data = req.json()
|
||||
if "err" in data["message"] or data["retcode"] == -100:
|
||||
log.error("获取任务列表失败,你的cookie可能已过期,请重新设置cookie。")
|
||||
@ -101,7 +101,7 @@ class mihoyobbs:
|
||||
def get_list(self) -> list:
|
||||
temp_list = []
|
||||
log.info("正在获取帖子列表......")
|
||||
req = http.get(url=setting.bbs_Listurl.format(setting.mihoyobbs_List_Use[0]["forumId"]), headers=self.headers)
|
||||
req = http.get(url=setting.bbs_List_url.format(setting.mihoyobbs_List_Use[0]["forumId"]), headers=self.headers)
|
||||
data = req.json()
|
||||
for n in range(5):
|
||||
temp_list.append([data["data"]["list"][n]["post"]["post_id"], data["data"]["list"][n]["post"]["subject"]])
|
||||
@ -115,7 +115,7 @@ class mihoyobbs:
|
||||
else:
|
||||
log.info("正在签到......")
|
||||
for i in setting.mihoyobbs_List_Use:
|
||||
req = http.post(url=setting.bbs_Signurl.format(i["id"]), data={}, headers=self.headers)
|
||||
req = http.post(url=setting.bbs_Sign_url.format(i["id"]), data={}, headers=self.headers)
|
||||
data = req.json()
|
||||
if "err" not in data["message"]:
|
||||
log.info(str(i["name"] + data["message"]))
|
||||
@ -132,7 +132,7 @@ class mihoyobbs:
|
||||
else:
|
||||
log.info("正在看帖......")
|
||||
for i in range(self.Task_do["bbs_Read_posts_num"]):
|
||||
req = http.get(url=setting.bbs_Detailurl.format(self.postsList[i][0]), headers=self.headers)
|
||||
req = http.get(url=setting.bbs_Detail_url.format(self.postsList[i][0]), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
log.debug("看帖:{} 成功".format(self.postsList[i][1]))
|
||||
@ -145,7 +145,7 @@ class mihoyobbs:
|
||||
else:
|
||||
log.info("正在点赞......")
|
||||
for i in range(self.Task_do["bbs_Like_posts_num"]):
|
||||
req = http.post(url=setting.bbs_Likeurl, headers=self.headers,
|
||||
req = http.post(url=setting.bbs_Like_url, headers=self.headers,
|
||||
json={"post_id": self.postsList[i][0], "is_cancel": False})
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
@ -153,7 +153,7 @@ class mihoyobbs:
|
||||
# 判断取消点赞是否打开
|
||||
if config.mihoyobbs["bbs_Unlike"]:
|
||||
time.sleep(random.randint(2, 8))
|
||||
req = http.post(url=setting.bbs_Likeurl, headers=self.headers,
|
||||
req = http.post(url=setting.bbs_Like_url, headers=self.headers,
|
||||
json={"post_id": self.postsList[i][0], "is_cancel": True})
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
@ -168,7 +168,7 @@ class mihoyobbs:
|
||||
else:
|
||||
log.info("正在执行分享任务......")
|
||||
for i in range(3):
|
||||
req = http.get(url=setting.bbs_Shareurl.format(self.postsList[0][0]), headers=self.headers)
|
||||
req = http.get(url=setting.bbs_Share_url.format(self.postsList[0][0]), headers=self.headers)
|
||||
data = req.json()
|
||||
if data["message"] == "OK":
|
||||
log.debug("分享:{} 成功".format(self.postsList[0][1]))
|
||||
|
||||
53
setting.py
53
setting.py
@ -41,28 +41,45 @@ mihoyobbs_List = [{
|
||||
"url": "https://bbs.mihoyo.com/sr/"
|
||||
}]
|
||||
|
||||
game_id2name = {
|
||||
"bh2_cn": "崩坏2",
|
||||
"bh3_cn": "崩坏3",
|
||||
"nxx_cn": "未定事件簿",
|
||||
"hk4e_cn": "原神",
|
||||
}
|
||||
# Config Load之后run里面进行列表的选择
|
||||
mihoyobbs_List_Use = []
|
||||
|
||||
# 米游社的API列表
|
||||
bbs_Cookieurl = "https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?login_ticket={}"
|
||||
bbs_Cookieurl2 = "https://api-takumi.mihoyo.com/auth/api/getMultiTokenByLoginTicket?login_ticket={}&token_types=3&uid={}"
|
||||
bbs_Taskslist = "https://bbs-api.mihoyo.com/apihub/sapi/getUserMissionsState" # 获取任务列表
|
||||
bbs_Signurl = "https://bbs-api.mihoyo.com/apihub/sapi/signIn?gids={}" # post
|
||||
bbs_Listurl = "https://bbs-api.mihoyo.com/post/api/getForumPostList?forum_id={}&is_good=false&is_hot=false&page_size=20&sort_type=1"
|
||||
bbs_Detailurl = "https://bbs-api.mihoyo.com/post/api/getPostFull?post_id={}"
|
||||
bbs_Shareurl = "https://bbs-api.mihoyo.com/apihub/api/getShareConf?entity_id={}&entity_type=1"
|
||||
bbs_Likeurl = "https://bbs-api.mihoyo.com/apihub/sapi/upvotePost" # post json
|
||||
# 通用设置
|
||||
bbs_Api = "https://bbs-api.mihoyo.com"
|
||||
web_Api = "https://api-takumi.mihoyo.com"
|
||||
account_Info_url = web_Api + "/binding/api/getUserGameRolesByCookie?game_biz="
|
||||
|
||||
# 原神自动签到相关的设置
|
||||
genshin_Act_id = "e202009291139501"
|
||||
genshin_Account_info_url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn"
|
||||
genshin_Signlisturl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/home?act_id={}"
|
||||
genshin_Is_signurl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}"
|
||||
genshin_Signurl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign"
|
||||
# 米游社的API列表
|
||||
bbs_Cookie_url = "https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?login_ticket={}"
|
||||
bbs_Cookie_url2 = web_Api + "/auth/api/getMultiTokenByLoginTicket?login_ticket={}&token_types=3&uid={}"
|
||||
bbs_Tasks_list = bbs_Api + "/apihub/sapi/getUserMissionsState" # 获取任务列表
|
||||
bbs_Sign_url = bbs_Api + "/apihub/sapi/signIn?gids={}" # post
|
||||
bbs_List_url = bbs_Api + "/post/api/getForumPostList?forum_id={}&is_good=false&is_hot=false&page_size=20&sort_type=1"
|
||||
bbs_Detail_url = bbs_Api + "/post/api/getPostFull?post_id={}"
|
||||
bbs_Share_url = bbs_Api + "/apihub/api/getShareConf?entity_id={}&entity_type=1"
|
||||
bbs_Like_url = bbs_Api + "/apihub/sapi/upvotePost" # post json
|
||||
|
||||
# 崩坏2自动签到相关的相关设置
|
||||
honkai2_Act_id = "e202203291431091"
|
||||
honkai2_Account_info_url = account_Info_url + "bh2_cn" # 废弃字段,之后可能会删除
|
||||
honkai2_Is_signurl = web_Api + "/event/luna/info?lang=zh-cn&act_id={}®ion={}&uid={}"
|
||||
honkai2_Sign_url = web_Api + "/event/luna/sign"
|
||||
|
||||
# 崩坏3自动签到相关的设置
|
||||
honkai3rd_Act_id = "ea20211026151532"
|
||||
honkai3rd_Account_info_url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=bh3_cn"
|
||||
honkai3rd_Is_signurl = "https://api-takumi.mihoyo.com/common/eutheniav2/index?act_id={}®ion={}&uid={}"
|
||||
honkai3rd_SignUrl = "https://api-takumi.mihoyo.com/common/eutheniav2/sign"
|
||||
honkai3rd_Account_info_url = account_Info_url + "bh3_cn" # 废弃字段,之后可能会删除
|
||||
honkai3rd_Is_signurl = web_Api + "/common/eutheniav2/index?act_id={}®ion={}&uid={}"
|
||||
honkai3rd_SignUrl = web_Api + "/common/eutheniav2/sign"
|
||||
|
||||
# 原神自动签到相关的设置
|
||||
genshin_Act_id = "e202009291139501"
|
||||
genshin_Account_info_url = account_Info_url + "hk4e_cn" # 废弃字段,之后可能会删除
|
||||
genshin_Signlisturl = web_Api + "/event/bbs_sign_reward/home?act_id={}"
|
||||
genshin_Is_signurl = web_Api + "/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}"
|
||||
genshin_Signurl = web_Api + "/event/bbs_sign_reward/sign"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user