diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index dc2bda0..7d5729e 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -312,62 +312,12 @@ class fudai_analyse: return 60 def _maybe_run_yanghao_during_run(self) -> None: - """If configured, trigger recommendation-page yanghao at configured intervals. + """如果配置了,按间隔触发推荐页养号。""" + from douyin.core.fudai_modules.fudai_detail_helpers import ( + maybe_run_yanghao_during_run, + ) - This respects `yanghao_enabled` and will not trigger during lottery-result waiting. - """ - try: - interval = int(getattr(self, "yanghao_recommend_interval_seconds", 0) or 0) - if interval <= 0: - return - - # 不在等待开奖期间触发养号 - if getattr(self, "_waiting_for_lottery_result", False): - return - - # 如果正在处理预约或有未完成的预约队列,则跳过触发 - try: - if getattr(self, "_current_attending_reservation_fudai", False): - return - except Exception: - pass - - try: - reservations = getattr(self, "reservations", None) - if reservations and len(reservations) > 0: - # 有预约队列,等待预约完成 - return - except Exception: - pass - - try: - reservation_focus_until = float( - getattr(self, "reservation_focus_until_ts", 0.0) or 0.0 - ) - if reservation_focus_until > time.time(): - # 当前处于预约焦点期,跳过养号 - return - except Exception: - pass - - now = time.time() - last = float(getattr(self, "_last_yanghao_ts", 0.0) or 0.0) - if now - last < interval: - return - - try: - self._log_kv("养号", "定时触发推荐页养号", interval_seconds=interval) - except Exception: - pass - - self._last_yanghao_ts = now - seconds = int(getattr(self, "yanghao_recommend_duration_seconds", 60) or 60) - try: - self._yanghao_wait(seconds) - except Exception: - pass - except Exception: - pass + maybe_run_yanghao_during_run(self) # ========== 兼容旧入口:主循环 ========== def fudai_choujiang( diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 859fca5..34a02de 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -273,6 +273,67 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N ) +def maybe_run_yanghao_during_run(analyser) -> None: + """如果配置了 yanghao_recommend_interval_seconds,按间隔触发推荐页养号。 + + 跳过条件: + - interval <= 0 + - 正在等待开奖 + - 正在参与预约福袋 + - 有预约队列 + - 处于预约焦点期 + - 距上次触发不足 interval + """ + try: + interval = int(getattr(analyser, "yanghao_recommend_interval_seconds", 0) or 0) + if interval <= 0: + return + + if getattr(analyser, "_waiting_for_lottery_result", False): + return + + try: + if getattr(analyser, "_current_attending_reservation_fudai", False): + return + except Exception: + pass + + try: + reservations = getattr(analyser, "reservations", None) + if reservations and len(reservations) > 0: + return + except Exception: + pass + + try: + reservation_focus_until = float( + getattr(analyser, "reservation_focus_until_ts", 0.0) or 0.0 + ) + if reservation_focus_until > time.time(): + return + except Exception: + pass + + now = time.time() + last = float(getattr(analyser, "_last_yanghao_ts", 0.0) or 0.0) + if now - last < interval: + return + + try: + analyser._log_kv("养号", "定时触发推荐页养号", interval_seconds=interval) + except Exception: + pass + + analyser._last_yanghao_ts = now + seconds = int(getattr(analyser, "yanghao_recommend_duration_seconds", 60) or 60) + try: + analyser._yanghao_wait(seconds) + except Exception: + pass + except Exception: + pass + + def swipe_with_fallback(analyser, start_x: int, start_y: int, end_x: int, end_y: int, duration_ms: int = 300) -> None: """fudai_analyse.swipe 的实现:转发到底层 operation.swipe,失败时回退到 ADB direct。""" try: