diff --git a/genshin.py b/genshin.py index b480fb6..6b9ab40 100644 --- a/genshin.py +++ b/genshin.py @@ -68,6 +68,7 @@ class Genshin: # 签到 def sign_account(self): + return_data = "原神:" if len(self.acc_List) != 0: for i in self.acc_List: log.info(f"正在为旅行者{i[0]}进行签到...") @@ -95,5 +96,11 @@ class Genshin: else: log.warning("账号签到失败!") print(req.text) + if is_data["is_sign"] or data["retcode"] == 0 or data["retcode"] == -5003: + return_data += f"\n旅行者:{i[0]}已连续签到{sign_days}天,今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}" + else: + return_data += f"\n旅行者:{i[0]},本次签到失败" else: log.warning("账号没有绑定任何原神账号!") + return_data += "\n并没有绑定任何原神账号" + return return_data diff --git a/honkai3rd.py b/honkai3rd.py index 7cd944e..43687f2 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -8,7 +8,7 @@ from loghelper import log from error import CookieError -class honkai3rd: +class Honkai3rd: def __init__(self) -> None: self.headers = { 'Accept': 'application/json, text/plain, */*', @@ -27,70 +27,81 @@ class honkai3rd: "Cookie": config.mihoyobbs_Cookies, 'x-rpc-device_id': tools.get_device_id() } - self.acc_List = self.Getacc_list() + self.acc_List = self.get_account_list() + self.sign_day = 0 # 获取绑定的账号列表 - def Getacc_list(self) -> list: + def get_account_list(self) -> list: log.info("正在获取米哈游账号绑定的崩坏3账号列表...") - temp_List = [] + 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 Errror") + 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 + 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) -> dict: + def get_today_item(self, raw_data: list): # 用range进行循环,当status等于0的时候上一个就是今天签到的dict for i in range(len(raw_data)): if raw_data[i]["status"] == 0: + self.sign_day = i - 1 return raw_data[i - 1] + self.sign_day = i if raw_data[i]["status"] == 1: return raw_data[i] if i == int(len(raw_data) - 1) and raw_data[i]["status"] != 0: return raw_data[i] # 判断签到 - def Is_sign(self, region: str, uid: str, nickname: str): + def is_sign(self, region: str, uid: str): 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) exit(1) - today_Item = self.Get_today_item(data["data"]["sign"]["list"]) - if today_Item["status"] == 1: + today_item = self.get_today_item(data["data"]["sign"]["list"]) + if today_item["status"] == 1: return True else: - log.info(f"舰长{nickname}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(today_Item)}") return False # 签到 - def Sign_acc(self): + def sign_account(self): + return_data = "崩坏3:" if len(self.acc_List) != 0: for i in self.acc_List: log.info(f"正在为舰长{i[0]}进行签到...") time.sleep(random.randint(2, 8)) - is_data = self.Is_sign(region=i[2], uid=i[1], nickname=i[0]) + is_data = self.is_sign(region=i[2], uid=i[1]) if is_data: time.sleep(random.randint(2, 8)) req = http.post(url=setting.honkai3rd_SignUrl, headers=self.headers, json={'act_id': setting.honkai3rd_Act_id, 'region': i[2], 'uid': i[1]}) data = req.json() if data["retcode"] == 0: - today_Item = self.Get_today_item(data["data"]["list"]) - log.info(f"舰长{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(today_Item)}") + today_item = self.get_today_item(data["data"]["list"]) + log.info(f"舰长{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(today_item)}") elif data["retcode"] == -5003: # 崩坏3应为奖励列表和签到信息在一起了,加上上面已经可以进行了一次判断,所以这里旧不重复再次执行判断来获取内容了 log.info(f"舰长{i[0]}今天已经签到过了~") else: log.warning("账号签到失败!") print(req.text) + else: + log.info(f"舰长{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(today_item)}") + if is_data["is_sign"] or data["retcode"] == 0 or data["retcode"] == -5003: + return_data += f"\n舰长:{i[0]}已连续签到{self.sign_day}天,今天获得的奖励是{tools.get_item(today_item)}" + else: + return_data += f"\n舰长:{i[0]},本次签到失败" else: log.warning("账号没有绑定任何崩坏3账号!") + return_data += "\n并没有绑定任何崩坏3账号" + return return_data diff --git a/main.py b/main.py index 7129f52..a39c4b0 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ from error import CookieError def main(): # 初始化,加载配置 + return_data = "米游社:" config.load_config() if config.enable_Config: # 检测参数是否齐全,如果缺少就进行登入操作 @@ -23,12 +24,6 @@ def main(): time.sleep(random.randint(2, 8)) # 获取要使用的BBS列表,#判断是否开启bbs_Signin_multi if config.mihoyobbs["bbs_Signin_multi"]: - # 速度快,但是无法设置主社区,主社区默认为第一个 - ''' - for i in setting.mihoyobbs_List: - if int(i["id"]) in config.mihoyobbs["bbs_Signin_multi_list"]: - setting.mihoyobbs_List_Use.append(i) - ''' # 用这里的方案可以实现当让id在第一个的时候为主社区 for i in config.mihoyobbs["bbs_Signin_multi_list"]: for i2 in setting.mihoyobbs_List: @@ -44,7 +39,9 @@ def main(): bbs = mihoyobbs.mihoyobbs() if bbs.Task_do["bbs_Sign"] and bbs.Task_do["bbs_Read_posts"] and bbs.Task_do["bbs_Like_posts"] and \ bbs.Task_do["bbs_Share"]: - log.info(f"今天已经全部完成了!一共获得{mihoyobbs.Today_have_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币") + bbs_message = f"今天已经全部完成了!一共获得{mihoyobbs.Today_have_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币" + return_data += "\n" + bbs_message + log.info(bbs_message) else: if config.mihoyobbs["bbs_Signin"]: bbs.signing() @@ -55,37 +52,42 @@ def main(): if config.mihoyobbs["bbs_Share"]: bbs.share_post() bbs.Get_taskslist() - log.info( - f"今天已经获得{mihoyobbs.Today_have_getcoins}个米游币,还能获得{mihoyobbs.Today_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币") + bbs_message = f"今天已经获得{mihoyobbs.Today_have_getcoins}个米游币,"\ + f"还能获得{mihoyobbs.Today_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币" + return_data += "\n" + bbs_message + log.info(bbs_message) time.sleep(random.randint(2, 8)) else: + return_data += "\n" + "米游社功能未启用!" log.info("米游社功能未启用!") # 原神签到 if config.genshin_Auto_sign: log.info("正在进行原神签到") genshin_help = genshin.Genshin() - genshin_help.sign_account() + return_data += "\n" + genshin_help.sign_account() time.sleep(random.randint(2, 8)) else: + return_data += "\n" + "原神签到功能未启用!" log.info("原神签到功能未启用!") # 崩坏3签到 if config.honkai3rd_Auto_sign: log.info("正在进行崩坏3签到") - honkai3rd_help = honkai3rd.honkai3rd() - honkai3rd_help.Sign_acc() + honkai3rd_help = honkai3rd.Honkai3rd() + return_data += "\n" + honkai3rd_help.sign_account() else: + return_data += "\n" + "崩坏3签到功能未启用!" log.info("崩坏3签到功能未启用!") - return 0 + return 0, return_data else: log.warning("Config未启用!") - return 1 + return 1, "Config未启用!" if __name__ == "__main__": try: - status_code = main() + status_code, message = main() except CookieError: status_code = 0 log.error("账号Cookie有问题!") - push.push(status_code, "脚本已执行") + push.push(status_code, message) pass