From b5d7943af0e3ac480478b2fd091a7d7fdd054777 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 11:10:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20run=5Fonce=5Fbas?= =?UTF-8?q?ic=20=E4=B8=AD"FUDai=5FRESULT"=E5=88=86=E6=94=AF=E5=88=B0=20han?= =?UTF-8?q?dle=5Flottery=5Fresult=5Fstage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将抽奖结果弹窗处理独立块(约 30 行)抽到 fudai_detail_helpers.handle_lottery_result_stage。逻辑: - 清除 _waiting_for_lottery_result / _current_attending_reservation_fudai - OCR 识别开奖结果文本 - 命中则 _handle_lottery_result_by_ocr;未命中则返回键 + 切下个直播间 - 写完成日志 douyin_fudai.py: 3092 → 3071 行 (-21) fudai_detail_helpers.py: 535 → 572 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 29 ++------------- .../fudai_modules/fudai_detail_helpers.py | 37 +++++++++++++++++++ 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index e31adec..446d5a9 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1761,32 +1761,11 @@ class fudai_analyse: douyin_live_room.reflash_zhibo(self) elif stage == "FUDai_RESULT": # 抽奖结果弹窗:处理开奖结果(使用OCR识别,不使用阶段诊断) - # 清除等待开奖标志 - self._waiting_for_lottery_result = False - self._current_attending_reservation_fudai = False - - self._log_kv("开奖结果", "检测到抽奖结果弹窗,使用OCR识别处理") - # 直接OCR识别并处理 - lottery_ocr_start = time.time() - result = self._check_lottery_result_by_ocr() - if result: - self._handle_lottery_result_by_ocr(result) - else: - # OCR识别失败,使用返回键关闭 - try: - self.operation.click_back(self.device_id) - self.operation.delay(0.5) - self.swipe_up_to_next_live() - except Exception: - pass - lottery_ocr_elapsed = time.time() - lottery_ocr_start - self._log_kv("开奖结果", f"OCR处理完成,耗时: {lottery_ocr_elapsed:.3f}s") - elapsed = time.time() - start_time - self._log_kv( - "流程", - "run_once_basic完成(处理开奖结果)", - elapsed_seconds=round(elapsed, 2), + from douyin.core.fudai_modules.fudai_detail_helpers import ( + handle_lottery_result_stage, ) + + handle_lottery_result_stage(self, start_time) return elif stage in ("LIVE_CLOSED",): # 直播结束:下滑/切下一个 diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 6d3d899..b66cebb 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,43 @@ def log_screenshot_failed( pass +def handle_lottery_result_stage(analyser, start_time: float) -> None: + """run_once_basic stage == "FUDai_RESULT" 分支: + + - 清除等待开奖标志 + - OCR 识别开奖结果文本 + - 命中则交给 _handle_lottery_result_by_ocr 处理;未命中则按返回键 + 切换下一个直播间 + - 写完成日志 + + 调用方应在调用后立即 return。 + """ + # 清除等待开奖标志 + analyser._waiting_for_lottery_result = False + analyser._current_attending_reservation_fudai = False + + analyser._log_kv("开奖结果", "检测到抽奖结果弹窗,使用OCR识别处理") + lottery_ocr_start = time.time() + result = analyser._check_lottery_result_by_ocr() + if result: + analyser._handle_lottery_result_by_ocr(result) + else: + # OCR识别失败,使用返回键关闭 + try: + analyser.operation.click_back(analyser.device_id) + analyser.operation.delay(0.5) + analyser.swipe_up_to_next_live() + except Exception: + pass + lottery_ocr_elapsed = time.time() - lottery_ocr_start + analyser._log_kv("开奖结果", f"OCR处理完成,耗时: {lottery_ocr_elapsed:.3f}s") + elapsed = time.time() - start_time + analyser._log_kv( + "流程", + "run_once_basic完成(处理开奖结果)", + elapsed_seconds=round(elapsed, 2), + ) + + def handle_recommend_page(analyser) -> None: """run_once_basic stage == "RECOMMEND_PAGE" 分支: