diff --git a/tasks/tv_raffle_handler.py b/tasks/tv_raffle_handler.py index 2d15726..5e94e26 100644 --- a/tasks/tv_raffle_handler.py +++ b/tasks/tv_raffle_handler.py @@ -1,6 +1,7 @@ import bili_statistics from reqs.tv_raffle_handler import TvRaffleHandlerReq from tasks.utils import UtilsTask +import utils class TvRaffleHandlerTask: @@ -12,11 +13,13 @@ def target(step): return TvRaffleHandlerTask.join if step == 2: return TvRaffleHandlerTask.notice + if step == 3: + return TvRaffleHandlerTask.join_v4 return None # 这是superuser做的,做完之后就broadcast @staticmethod - async def check(user, real_roomid): + async def check_v4(user, real_roomid): if not await UtilsTask.is_normal_room(user, real_roomid): return json_response = await user.req_s(TvRaffleHandlerReq.check, user, real_roomid) @@ -30,8 +33,7 @@ async def check(user, real_roomid): # 处理一些重复 if not bili_statistics.is_raffleid_duplicate(raffle_id): print('本次获取到的抽奖id为', raffle_id) - next_step_setting = (1, (0, max_wait), -2, real_roomid, raffle_id, raffle_type) - # next_step_setting = (1, (j['time_wait'], max_wait), -2, real_roomid, raffle_id, raffle_type) + next_step_setting = (3, (j['time_wait'], max_wait), -2, real_roomid, raffle_id, raffle_type) next_step_settings.append(next_step_setting) bili_statistics.add2raffle_ids(raffle_id) @@ -56,9 +58,32 @@ async def join_v4(user, real_roomid, raffleid, raffle_type): else: user.warn(f'TV {json_rsp}') return None + + @staticmethod + async def check(user, real_roomid): + if not await UtilsTask.is_normal_room(user, real_roomid): + return + json_response = await user.req_s(TvRaffleHandlerReq.check, user, real_roomid) + # print(json_response['data']['list']) + checklen = json_response['data']['list'] + next_step_settings = [] + for j in checklen: + print(j) + raffle_id = j['raffleId'] + raffle_type = j['type'] + max_wait = j['time'] - 10 + raffle_end_time = j['time'] + utils.curr_time() + # 处理一些重复 + if not bili_statistics.is_raffleid_duplicate(raffle_id): + print('本次获取到的抽奖id为', raffle_id) + next_step_setting = (1, (0, max_wait), -2, real_roomid, raffle_id, raffle_type, raffle_end_time) + next_step_settings.append(next_step_setting) + bili_statistics.add2raffle_ids(raffle_id) + + return next_step_settings @staticmethod - async def join(user, real_roomid, raffleid, raffle_type): + async def join(user, real_roomid, raffleid, raffle_type, raffle_end_time): # print('参与', raffleid) # await UtilsTask.enter_room(user, real_roomid) json_response2 = await user.req_s(TvRaffleHandlerReq.join, user, real_roomid, raffleid) @@ -69,7 +94,8 @@ async def join(user, real_roomid, raffleid, raffle_type): # -500繁忙 code = json_response2['code'] if not code: - return (2, (170, 190), user.id, raffleid, real_roomid), + sleeptime = raffle_end_time - utils.curr_time() + 5 # 小于0,call_later自动置0 + return (2, (sleeptime, sleeptime+90), user.id, raffleid, real_roomid), elif code == -500: print('# -500繁忙,稍后重试') return () @@ -88,8 +114,11 @@ async def notice(user, raffleid, real_roomid): # {'code': 0, 'msg': '正在抽奖中..', 'message': '正在抽奖中..', 'data': {'gift_id': '-1', 'gift_name': '', 'gift_num': 0, 'gift_from': '', 'gift_type': 0, 'gift_content': '', 'status': 3}} if json_response['data']['gift_id'] == '-1': print([f'json_response'], True) + user.warn(f'{json_response}') return elif json_response['data']['gift_id'] != '-1': data = json_response['data'] user.info([f'# 房间{real_roomid:^9}小电视抽奖结果: {data["gift_name"]}X{data["gift_num"]}'], True) bili_statistics.add2results(data['gift_name'], user.id, data['gift_num']) + else: + user.warn(f'{json_response}')