🚑 mys签到出现验证码时进行重试

This commit is contained in:
CMHopeSunshine 2022-08-12 11:55:49 +08:00
parent db2aee32a3
commit c27a4d9c36
2 changed files with 37 additions and 28 deletions

View File

@ -497,12 +497,16 @@ async def mys_sign_handler(event: MessageEvent, msg: Message = CommandArg()):
else: else:
sign_day = sign_info['data']['total_sign_day'] sign_day = sign_info['data']['total_sign_day']
sign_action = await sign(uid) sign_action = await sign(uid)
if isinstance(sign_action, str): for _ in range(5):
await mys_sign.finish(sign_action, at_sender=True) if isinstance(sign_action, dict):
else: if sign_action['data']['success'] == 0:
await mys_sign.finish( await mys_sign.finish(
f'签到成功,获得的奖励为:\n{sign_list["data"]["awards"][sign_day]["name"]} * {sign_list["data"]["awards"][sign_day]["cnt"]}', f'签到成功,获得的奖励为:\n{sign_list["data"]["awards"][sign_day]["name"]} * {sign_list["data"]["awards"][sign_day]["cnt"]}',
at_sender=True) at_sender=True)
else:
await sleep(random.randint(3, 6))
else:
await mys_sign.finish(sign_action, at_sender=True)
@mys_sign_auto.handle() @mys_sign_auto.handle()
@ -660,24 +664,31 @@ async def auto_sign():
sign_list = await get_sign_list() sign_list = await get_sign_list()
for user_id, uid, remind_id in data: for user_id, uid, remind_id in data:
await sleep(random.randint(20, 35)) await sleep(random.randint(20, 35))
sign_result = await sign(uid) for _ in range(5):
if not isinstance(sign_result, str): sign_result = await sign(uid)
await sleep(1) if isinstance(sign_result, dict):
sign_info = await get_sign_info(uid) # success为0则说明没有出现验证码不为0则有验证码等待5-10秒再重试重试最多5次
sign_day = sign_info['data']['total_sign_day'] - 1 if sign_result['data']['success'] == 0:
if remind_id.startswith('q'): await sleep(1)
await get_bot().send_private_msg(user_id=remind_id[1:], sign_info = await get_sign_info(uid)
message=f'你的uid{uid}自动签到成功!签到奖励为{sign_list["data"]["awards"][sign_day]["name"]}*{sign_list["data"]["awards"][sign_day]["cnt"]}') sign_day = sign_info['data']['total_sign_day'] - 1
if remind_id.startswith('q'):
await get_bot().send_private_msg(user_id=remind_id[1:],
message=f'你的uid{uid}自动签到成功!签到奖励为{sign_list["data"]["awards"][sign_day]["name"]}*{sign_list["data"]["awards"][sign_day]["cnt"]}')
else:
ann[remind_id]['成功'].append(
f'.UID{uid}-{sign_list["data"]["awards"][sign_day]["name"]}*{sign_list["data"]["awards"][sign_day]["cnt"]}')
break
else:
await sleep(random.randint(5, 10))
else: else:
ann[remind_id]['成功'].append( await delete_auto_sign(user_id, uid)
f'.UID{uid}-{sign_list["data"]["awards"][sign_day]["name"]}*{sign_list["data"]["awards"][sign_day]["cnt"]}') if remind_id.startswith('q'):
else: await get_bot().send_private_msg(user_id=remind_id[1:],
await delete_auto_sign(user_id, uid) message=f'你的uid{uid}签到失败请重新绑定cookie再开启自动签到')
if remind_id.startswith('q'): else:
await get_bot().send_private_msg(user_id=remind_id[1:], ann[remind_id]['失败'].append(f'.UID{uid}')
message=f'你的uid{uid}签到失败请重新绑定cookie再开启自动签到') break
else:
ann[remind_id]['失败'].append(f'.UID{uid}')
for group_id, content in ann.items(): for group_id, content in ann.items():
group_str = '米游社自动签到结果:\n' group_str = '米游社自动签到结果:\n'
for type, ann_list in content.items(): for type, ann_list in content.items():

View File

@ -1,8 +1,8 @@
import datetime import datetime
import re import re
from asyncio import sleep
from littlepaimon_utils import aiorequests from littlepaimon_utils import aiorequests
from nonebot import logger
from ..utils.auth_util import get_headers, get_sign_headers, get_use_cookie, get_own_cookie, check_retcode from ..utils.auth_util import get_headers, get_sign_headers, get_use_cookie, get_own_cookie, check_retcode
from ..utils.db_util import get_private_cookie, update_cookie_cache, update_private_cookie from ..utils.db_util import get_private_cookie, update_cookie_cache, update_private_cookie
@ -223,10 +223,8 @@ async def sign(uid):
'region': server_id 'region': server_id
} }
resp = await aiorequests.post(url=url, headers=headers, json=json_data) resp = await aiorequests.post(url=url, headers=headers, json=json_data)
try: data = resp.json()
data = resp.json() logger.info(f'---UID{uid}的签到状态码为{data["retcode"]},结果为{data["message"]}---')
except:
return resp.read()
if await check_retcode(data, cookie, uid): if await check_retcode(data, cookie, uid):
return data return data
else: else: