diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index ed9d584..7fad227 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -574,71 +574,12 @@ class fudai_analyse: detail, skip, skip_reason = result step3_start = time.time() # 兼容后续 step3_elapsed 日志 - # 检查是否是优惠券弹窗、观看任务或识别错误:根据 _last_fudai_detail_status 分发到对应处理 + # 步骤3 + 步骤4:状态分发 + 验证 + 参与决策 from douyin.core.fudai_modules.fudai_detail_helpers import ( - dispatch_last_fudai_detail_status, + step3_step4_coordinator, ) - if dispatch_last_fudai_detail_status(self, start_time): - return - - # 如果成功读取,重置失败计数 - try: - self._fudai_detail_consecutive_failures = 0 - except Exception: - pass - - # 额外验证 + 兜底检查(验证失败或无效详情则早返回) - from douyin.core.fudai_modules.fudai_detail_helpers import ( - validate_detail_or_skip, - ) - - if validate_detail_or_skip(self, detail, start_time): - return - - # 记录参与前的状态 - attend_before_ts = getattr(self, "_last_successful_attend_ts", 0.0) or 0.0 - - # 记录当前福袋的 future_ts,供 attend_choujiang 使用 - from douyin.core.fudai_modules.fudai_detail_helpers import ( - extract_future_ts_from_detail, - ) - - extract_future_ts_from_detail(self, detail) - - # 重置详情关闭标志 - try: - self._detail_closed_by_attend = False - except Exception: - pass - - # 步骤3结束计时 - step3_elapsed = (time.time() - step3_start) * 1000 - self._log_kv("详情处理", "步骤3[筛选检查]-完成", 总耗时毫秒=step3_elapsed) - - # 步骤4:参与决策 - step4_start = time.time() - # 执行参与决策 - if detail is None: - from douyin.core.fudai_modules.fudai_detail_helpers import ( - handle_detail_none_in_step4, - ) - - handle_detail_none_in_step4(self, start_time) - return - join_result = douyin_fudai_core.basic_join_decision( - self, detail, (skip, skip_reason) - ) - - # 检查是否参与成功:如果 _last_successful_attend_ts 刚刚更新,说明参与成功 - if join_result: - from douyin.core.fudai_modules.fudai_detail_helpers import ( - handle_attend_success_post_processing, - ) - - handle_attend_success_post_processing( - self, detail, start_time, step4_start, attend_before_ts - ) + step3_step4_coordinator(self, detail, skip, skip_reason, start_time, step3_start) def _handle_live_room_has_or_not_fudai(self) -> None: """在直播间:寻找福袋图标;有则点开详情,无则交给 flow_control 决定"继续找/切换/养号".""" diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 59f1dec..a1c33c6 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -273,6 +273,61 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N ) +def step3_step4_coordinator( + analyser, detail, skip: bool, skip_reason: str, start_time: float, step3_start: float +) -> None: + """_handle_in_fudai_detail 步骤3 + 步骤4 协调: + + - dispatch_last_fudai_detail_status:分发"优惠券弹窗 / 观看任务 / 验证失败"等状态 + - 重置失败计数 + - validate_detail_or_skip:额外验证 + 兜底检查 + - extract_future_ts_from_detail:提取倒计时 future_ts + - 步骤3 完成日志 + - 步骤4:basic_join_decision → handle_attend_success_post_processing + + 无返回值;调用方 return 即可。 + """ + from douyin.fudai import douyin_fudai_core + + if dispatch_last_fudai_detail_status(analyser, start_time): + return + + try: + analyser._fudai_detail_consecutive_failures = 0 + except Exception: + pass + + if validate_detail_or_skip(analyser, detail, start_time): + return + + attend_before_ts = getattr(analyser, "_last_successful_attend_ts", 0.0) or 0.0 + + extract_future_ts_from_detail(analyser, detail) + + try: + analyser._detail_closed_by_attend = False + except Exception: + pass + + step3_elapsed = (time.time() - step3_start) * 1000 + analyser._log_kv("详情处理", "步骤3[筛选检查]-完成", 总耗时毫秒=step3_elapsed) + + # 步骤4:参与决策 + step4_start = time.time() + if detail is None: + handle_detail_none_in_step4(analyser, start_time) + return + + join_result = douyin_fudai_core.basic_join_decision( + analyser, detail, (skip, skip_reason) + ) + + if join_result: + handle_attend_success_post_processing( + analyser, detail, start_time, step4_start, attend_before_ts + ) + + def run_reservation_check_block(analyser, start_time: float) -> bool: """run_once_basic 步骤 0.1:完整的预约检查块。