feat: 添加养号模式下的桌面检测和自救恢复功能;优化评论操作和定时触发逻辑
This commit is contained in:
1 parent
4d805474db
commit
d36b73d3df
4 files changed
+261
-75
No files matched your search
@@ -2731,6 +2731,10 @@ class underlying_operations:
|
|||||||
|
|
||||||
def click(self, device_id, x=500, y=500):
|
def click(self, device_id, x=500, y=500):
|
||||||
"""点击坐标位置"""
|
"""点击坐标位置"""
|
||||||
|
try:
|
||||||
|
print(f"[Underlying] click: device_id={device_id} coord=({x},{y})")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
os.system("{} -s {} shell input tap {} {}".format(self._adb(), device_id, x, y))
|
os.system("{} -s {} shell input tap {} {}".format(self._adb(), device_id, x, y))
|
||||||
|
|
||||||
def long_press(
|
def long_press(
|
||||||
@@ -3093,9 +3097,17 @@ class underlying_operations:
|
|||||||
|
|
||||||
# 先确保输入框获得焦点
|
# 先确保输入框获得焦点
|
||||||
try:
|
try:
|
||||||
|
try:
|
||||||
|
print(f"[Underlying] paste_text_at: clicking to focus device_id={device_id} coord=({x},{y})")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
self.click(device_id, int(x), int(y))
|
self.click(device_id, int(x), int(y))
|
||||||
time_module.sleep(0.2)
|
time_module.sleep(0.2)
|
||||||
# 有些输入框第一次点不进,补一次轻点
|
# 有些输入框第一次点不进,补一次轻点
|
||||||
|
try:
|
||||||
|
print(f"[Underlying] paste_text_at: clicking again to ensure focus device_id={device_id} coord=({x},{y})")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
self.click(device_id, int(x), int(y))
|
self.click(device_id, int(x), int(y))
|
||||||
time_module.sleep(0.15)
|
time_module.sleep(0.15)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -3104,19 +3116,50 @@ class underlying_operations:
|
|||||||
# 0) 优先:ADBKeyboard(如果已安装/可用)
|
# 0) 优先:ADBKeyboard(如果已安装/可用)
|
||||||
# 说明:这一步不依赖剪贴板/粘贴菜单,通常对中文更稳定
|
# 说明:这一步不依赖剪贴板/粘贴菜单,通常对中文更稳定
|
||||||
try:
|
try:
|
||||||
if self.input_text_adbkeyboard(device_id, t, restore_prev=False):
|
ok_adbkb = False
|
||||||
|
try:
|
||||||
|
ok_adbkb = bool(self.input_text_adbkeyboard(device_id, t, restore_prev=False))
|
||||||
|
except Exception:
|
||||||
|
ok_adbkb = False
|
||||||
|
try:
|
||||||
|
print(f"[Underlying] paste_text_at: input_text_adbkeyboard -> {ok_adbkb}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if ok_adbkb:
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 1) 优先:剪贴板 + 粘贴键
|
# 1) 优先:剪贴板 + 粘贴键
|
||||||
if self.set_clipboard_text(device_id, t):
|
ok_clip = False
|
||||||
|
try:
|
||||||
|
ok_clip = bool(self.set_clipboard_text(device_id, t))
|
||||||
|
except Exception:
|
||||||
|
ok_clip = False
|
||||||
|
try:
|
||||||
|
print(f"[Underlying] paste_text_at: set_clipboard_text -> {ok_clip}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if ok_clip:
|
||||||
# 给系统一点时间刷新剪贴板
|
# 给系统一点时间刷新剪贴板
|
||||||
time_module.sleep(0.15)
|
time_module.sleep(0.15)
|
||||||
if self.paste_from_clipboard(device_id):
|
ok_paste = False
|
||||||
|
try:
|
||||||
|
ok_paste = bool(self.paste_from_clipboard(device_id))
|
||||||
|
except Exception:
|
||||||
|
ok_paste = False
|
||||||
|
try:
|
||||||
|
print(f"[Underlying] paste_text_at: paste_from_clipboard -> {ok_paste}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if ok_paste:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# 2) 兜底:adb input text(中文可能不稳定)
|
# 2) 兜底:adb input text(中文可能不稳定)
|
||||||
|
try:
|
||||||
|
print(f"[Underlying] paste_text_at: falling back to input_text for device_id={device_id}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return self.input_text(device_id, t)
|
return self.input_text(device_id, t)
|
||||||
|
|
||||||
def _uiautomator_dump(self, device_id: str, local_path: str) -> bool:
|
def _uiautomator_dump(self, device_id: str, local_path: str) -> bool:
|
||||||
|
|||||||
+8
-8
@@ -11,7 +11,7 @@
|
|||||||
"reset_after_swipes_action": "back",
|
"reset_after_swipes_action": "back",
|
||||||
"auto_join_fansclub": true,
|
"auto_join_fansclub": true,
|
||||||
"fansclub_fail_action": "switch",
|
"fansclub_fail_action": "switch",
|
||||||
"high_value_fudai_enabled": true,
|
"high_value_fudai_enabled": false,
|
||||||
"high_value_fudai_threshold_yuan": 500.0,
|
"high_value_fudai_threshold_yuan": 500.0,
|
||||||
"high_value_fudai_join_ahead_seconds": 100,
|
"high_value_fudai_join_ahead_seconds": 100,
|
||||||
"high_value_fudai_max_swipe_back": 50,
|
"high_value_fudai_max_swipe_back": 50,
|
||||||
@@ -39,11 +39,11 @@
|
|||||||
"fudai_detail_save_debug_images": true,
|
"fudai_detail_save_debug_images": true,
|
||||||
"fudai_disable_content_recognition": true,
|
"fudai_disable_content_recognition": true,
|
||||||
"fudai_disable_task_recognition": true,
|
"fudai_disable_task_recognition": true,
|
||||||
"yanghao_recommend_duration_seconds": 300,
|
"yanghao_recommend_duration_seconds": 60,
|
||||||
"yanghao_recommend_interval_seconds": 600,
|
"yanghao_recommend_interval_seconds": 60,
|
||||||
"yanghao_like_prob": 1.0,
|
"yanghao_like_prob": 0.3,
|
||||||
"yanghao_fav_prob": 1.0,
|
"yanghao_fav_prob": 0.2,
|
||||||
"yanghao_comment_prob": 1.0,
|
"yanghao_comment_prob": 0.5,
|
||||||
"yanghao_icon_roi_size": 240,
|
"yanghao_icon_roi_size": 240,
|
||||||
"yanghao_icon_match_threshold": 0.77,
|
"yanghao_icon_match_threshold": 0.77,
|
||||||
"yanghao_step_screenshot": true,
|
"yanghao_step_screenshot": true,
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
"yanghao_comment_btn_x": 988,
|
"yanghao_comment_btn_x": 988,
|
||||||
"yanghao_comment_btn_y": 1410,
|
"yanghao_comment_btn_y": 1410,
|
||||||
"yanghao_dwell_on_action_min_seconds": 5.0,
|
"yanghao_dwell_on_action_min_seconds": 5.0,
|
||||||
"yanghao_dwell_on_action_max_seconds": 30.0,
|
"yanghao_dwell_on_action_max_seconds": 20.0,
|
||||||
"yanghao_comment_input_x": 0,
|
"yanghao_comment_input_x": 0,
|
||||||
"yanghao_comment_input_y": 0,
|
"yanghao_comment_input_y": 0,
|
||||||
"yanghao_comment_send_x": 0,
|
"yanghao_comment_send_x": 0,
|
||||||
@@ -213,7 +213,7 @@
|
|||||||
"fansclub_auto_join_wait_seconds": 5.0,
|
"fansclub_auto_join_wait_seconds": 5.0,
|
||||||
"fansclub_manual_wait_seconds": 3.0,
|
"fansclub_manual_wait_seconds": 3.0,
|
||||||
"enable_streaming_screenshot": false,
|
"enable_streaming_screenshot": false,
|
||||||
"yanghao_only": true,
|
"yanghao_only": false,
|
||||||
"record_room_title_mapping_enabled": true,
|
"record_room_title_mapping_enabled": true,
|
||||||
"high_value_fudai_poll_before_seconds": 10.0,
|
"high_value_fudai_poll_before_seconds": 10.0,
|
||||||
"high_value_room_revisit_min_interval_seconds": 300,
|
"high_value_room_revisit_min_interval_seconds": 300,
|
||||||
|
|||||||
@@ -258,6 +258,9 @@ class fudai_analyse:
|
|||||||
self.yanghao_fav_roi_offset_x: int = 0
|
self.yanghao_fav_roi_offset_x: int = 0
|
||||||
self.yanghao_fav_roi_offset_y: int = 0
|
self.yanghao_fav_roi_offset_y: int = 0
|
||||||
# 评论相关默认坐标与文案列表
|
# 评论相关默认坐标与文案列表
|
||||||
|
# 最近一次触发推荐页养号的时间戳(用于定时触发)
|
||||||
|
self._last_yanghao_ts: float = 0.0
|
||||||
|
|
||||||
self.yanghao_comment_btn_x: int = 0
|
self.yanghao_comment_btn_x: int = 0
|
||||||
self.yanghao_comment_btn_y: int = 0
|
self.yanghao_comment_btn_y: int = 0
|
||||||
self.yanghao_comment_input_x: int = 0
|
self.yanghao_comment_input_x: int = 0
|
||||||
@@ -424,6 +427,14 @@ class fudai_analyse:
|
|||||||
def _yanghao_recommend_flow(self, seconds: int) -> None:
|
def _yanghao_recommend_flow(self, seconds: int) -> None:
|
||||||
"""封装调用 douyin.other.douyin_yanghao.yanghao_recommend_flow。"""
|
"""封装调用 douyin.other.douyin_yanghao.yanghao_recommend_flow。"""
|
||||||
try:
|
try:
|
||||||
|
# Respect global enable switch so callers that invoke this
|
||||||
|
# method directly cannot bypass the main on/off setting.
|
||||||
|
if not bool(getattr(self, "yanghao_enabled", True)):
|
||||||
|
try:
|
||||||
|
self._log_kv("养号", "_yanghao_recommend_flow skipped - yanghao_enabled=0")
|
||||||
|
except Exception:
|
||||||
|
print("[养号] _yanghao_recommend_flow skipped - yanghao_enabled=0")
|
||||||
|
return
|
||||||
from douyin.other import douyin_yanghao
|
from douyin.other import douyin_yanghao
|
||||||
|
|
||||||
douyin_yanghao.yanghao_recommend_flow(self, int(seconds or 0))
|
douyin_yanghao.yanghao_recommend_flow(self, int(seconds or 0))
|
||||||
@@ -462,6 +473,62 @@ class fudai_analyse:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return 60
|
return 60
|
||||||
|
|
||||||
|
def _maybe_run_yanghao_during_run(self) -> None:
|
||||||
|
"""If configured, trigger recommendation-page yanghao at configured intervals.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
# ========== 兼容旧入口:主循环 ==========
|
# ========== 兼容旧入口:主循环 ==========
|
||||||
def fudai_choujiang(
|
def fudai_choujiang(
|
||||||
self,
|
self,
|
||||||
@@ -1061,6 +1128,11 @@ class fudai_analyse:
|
|||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
self._log_kv("流程", "run_once_basic开始", start_timestamp=start_time)
|
self._log_kv("流程", "run_once_basic开始", start_timestamp=start_time)
|
||||||
|
# 在主循环开始时检查是否需要定时触发推荐页养号
|
||||||
|
try:
|
||||||
|
self._maybe_run_yanghao_during_run()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# 直接参与标志已移除,相关旧逻辑已清理,继续按正常流程执行
|
# 直接参与标志已移除,相关旧逻辑已清理,继续按正常流程执行
|
||||||
# 0. 如果正在等待开奖:不在此期间检查并抢占其他预约,避免放弃当前正在参加的直播间
|
# 0. 如果正在等待开奖:不在此期间检查并抢占其他预约,避免放弃当前正在参加的直播间
|
||||||
|
|||||||
+135
-64
@@ -11,6 +11,59 @@ cv2: Any = _cv2
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def _scaled_click(analyser, base_x: int, base_y: int) -> None:
|
||||||
|
"""模块级点击封装:根据基准坐标缩放并点击(兼容原嵌套实现)。"""
|
||||||
|
sx, sy = analyser._scale_from_base(int(base_x), int(base_y))
|
||||||
|
analyser.operation.click(analyser.device_id, sx, sy)
|
||||||
|
|
||||||
|
|
||||||
|
def _do_comment(analyser) -> None:
|
||||||
|
"""模块级评论操作:点击评论按钮 -> 输入框 -> 输入文本 -> 发送 -> 关闭"""
|
||||||
|
try:
|
||||||
|
# 步骤1: 点击评论按钮
|
||||||
|
btn_x = int(getattr(analyser, "yanghao_comment_btn_x", 540) or 540)
|
||||||
|
btn_y = int(getattr(analyser, "yanghao_comment_btn_y", 2000) or 2000)
|
||||||
|
print(f"[养号][评论] Step1: 点击评论按钮 coord=({btn_x},{btn_y})")
|
||||||
|
_scaled_click(analyser, btn_x, btn_y)
|
||||||
|
analyser.operation.delay(2.0)
|
||||||
|
|
||||||
|
# 步骤2: 点击输入框
|
||||||
|
input_x = int(getattr(analyser, "yanghao_comment_input_x", 144) or 144)
|
||||||
|
input_y = int(getattr(analyser, "yanghao_comment_input_y", 2179) or 2179)
|
||||||
|
print(f"[养号][评论] Step2: 点击输入框 coord=({input_x},{input_y})")
|
||||||
|
_scaled_click(analyser, input_x, input_y)
|
||||||
|
analyser.operation.delay(2.0)
|
||||||
|
|
||||||
|
# 步骤3: 输入评论文本
|
||||||
|
comment_texts = getattr(analyser, "yanghao_comment_texts", []) or []
|
||||||
|
if not comment_texts:
|
||||||
|
comment_texts = ["加油", "不错", "很好看"]
|
||||||
|
selected_text = random.choice(comment_texts)
|
||||||
|
print(f"[养号][评论] Step3: 选择文本 -> {selected_text}")
|
||||||
|
|
||||||
|
ix, iy = analyser._scale_from_base(input_x, input_y)
|
||||||
|
ok_input = bool(
|
||||||
|
analyser.operation.paste_text_at(analyser.device_id, ix, iy, selected_text)
|
||||||
|
)
|
||||||
|
print(f"[养号][评论] paste_text_at -> ok={ok_input} scaled_coord=({ix},{iy})")
|
||||||
|
analyser.operation.delay(2.0)
|
||||||
|
|
||||||
|
# 步骤4: 发送评论
|
||||||
|
ok_send = bool(analyser.operation.confirm_from_keyboard(analyser.device_id))
|
||||||
|
print(f"[养号][评论] Step4: 发送评论 -> ok={ok_send}")
|
||||||
|
analyser.operation.delay(2.0)
|
||||||
|
|
||||||
|
# 步骤5: 关闭评论窗口
|
||||||
|
close_x = int(getattr(analyser, "yanghao_comment_close_x", 900) or 900)
|
||||||
|
close_y = int(getattr(analyser, "yanghao_comment_close_y", 300) or 300)
|
||||||
|
print(f"[养号][评论] Step5: 关闭评论窗口 coord=({close_x},{close_y})")
|
||||||
|
_scaled_click(analyser, close_x, close_y)
|
||||||
|
analyser.operation.delay(2.0)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[养号] 评论操作失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
def yanghao_idle(analyser, total_seconds: int) -> None:
|
def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||||
"""养号等待。
|
"""养号等待。
|
||||||
|
|
||||||
@@ -66,10 +119,6 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _scaled_click(base_x: int, base_y: int) -> None:
|
|
||||||
sx, sy = analyser._scale_from_base(int(base_x), int(base_y))
|
|
||||||
analyser.operation.click(analyser.device_id, sx, sy)
|
|
||||||
|
|
||||||
def _human_delay(min_s: float = 0.4, max_s: float = 1.2) -> None:
|
def _human_delay(min_s: float = 0.4, max_s: float = 1.2) -> None:
|
||||||
try:
|
try:
|
||||||
mn = float(min_s)
|
mn = float(min_s)
|
||||||
@@ -213,6 +262,9 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
|||||||
|
|
||||||
# 检查是否检测到爱心或收藏任意一个
|
# 检查是否检测到爱心或收藏任意一个
|
||||||
action_detected = like_ok or fav_ok
|
action_detected = like_ok or fav_ok
|
||||||
|
# 跟踪是否实际触发了 点爱心/点收藏 动作(只有在对应概率命中并执行点击时为 True)
|
||||||
|
did_like = False
|
||||||
|
did_fav = False
|
||||||
|
|
||||||
# 根据概率点击爱心
|
# 根据概率点击爱心
|
||||||
if (
|
if (
|
||||||
@@ -222,9 +274,11 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
|||||||
< float(getattr(analyser, "yanghao_like_prob", 0) or 0)
|
< float(getattr(analyser, "yanghao_like_prob", 0) or 0)
|
||||||
):
|
):
|
||||||
_scaled_click(
|
_scaled_click(
|
||||||
|
analyser,
|
||||||
int(getattr(analyser, "yanghao_like_icon_x", 0) or 0),
|
int(getattr(analyser, "yanghao_like_icon_x", 0) or 0),
|
||||||
int(getattr(analyser, "yanghao_like_icon_y", 0) or 0),
|
int(getattr(analyser, "yanghao_like_icon_y", 0) or 0),
|
||||||
)
|
)
|
||||||
|
did_like = True
|
||||||
analyser.operation.delay(2.0) # 延迟2秒
|
analyser.operation.delay(2.0) # 延迟2秒
|
||||||
print(
|
print(
|
||||||
"[养号] 动作: 点爱心(prob={})".format(
|
"[养号] 动作: 点爱心(prob={})".format(
|
||||||
@@ -246,9 +300,11 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
|||||||
< float(getattr(analyser, "yanghao_fav_prob", 0) or 0)
|
< float(getattr(analyser, "yanghao_fav_prob", 0) or 0)
|
||||||
):
|
):
|
||||||
_scaled_click(
|
_scaled_click(
|
||||||
|
analyser,
|
||||||
int(getattr(analyser, "yanghao_fav_icon_x", 0) or 0),
|
int(getattr(analyser, "yanghao_fav_icon_x", 0) or 0),
|
||||||
int(getattr(analyser, "yanghao_fav_icon_y", 0) or 0),
|
int(getattr(analyser, "yanghao_fav_icon_y", 0) or 0),
|
||||||
)
|
)
|
||||||
|
did_fav = True
|
||||||
analyser.operation.delay(2.0) # 延迟2秒
|
analyser.operation.delay(2.0) # 延迟2秒
|
||||||
print(
|
print(
|
||||||
"[养号] 动作: 点收藏(prob={})".format(
|
"[养号] 动作: 点收藏(prob={})".format(
|
||||||
@@ -263,12 +319,16 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
|||||||
print("[养号] 动作: 跳过点收藏(未检测到图标)")
|
print("[养号] 动作: 跳过点收藏(未检测到图标)")
|
||||||
|
|
||||||
# 根据概率评论
|
# 根据概率评论
|
||||||
if float(
|
# 仅在爱心和收藏都实际触发(都被点击)时才考虑评论
|
||||||
|
# 记录评论是否实际执行
|
||||||
|
did_comment = False
|
||||||
|
if did_like and did_fav and float(
|
||||||
getattr(analyser, "yanghao_comment_prob", 0) or 0
|
getattr(analyser, "yanghao_comment_prob", 0) or 0
|
||||||
) > 0 and random.random() < float(
|
) > 0 and random.random() < float(
|
||||||
getattr(analyser, "yanghao_comment_prob", 0) or 0
|
getattr(analyser, "yanghao_comment_prob", 0) or 0
|
||||||
):
|
):
|
||||||
_do_comment()
|
_do_comment(analyser)
|
||||||
|
did_comment = True
|
||||||
print(
|
print(
|
||||||
"[养号] 动作: 评论(prob={})".format(
|
"[养号] 动作: 评论(prob={})".format(
|
||||||
getattr(analyser, "yanghao_comment_prob", 0)
|
getattr(analyser, "yanghao_comment_prob", 0)
|
||||||
@@ -276,10 +336,13 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
prob = getattr(analyser, "yanghao_comment_prob", 0)
|
prob = getattr(analyser, "yanghao_comment_prob", 0)
|
||||||
print("[养号] 动作: 跳过评论(prob={prob})")
|
if not (did_like and did_fav):
|
||||||
|
print("[养号] 动作: 跳过评论(爱心/收藏未同时触发)")
|
||||||
|
else:
|
||||||
|
print("[养号] 动作: 跳过评论(prob={prob})")
|
||||||
|
|
||||||
# 如果检测到爱心或收藏任意一个,则随机停留5-30s
|
# 只有在实际执行了任意动作(爱心/收藏/评论)时才停留;仅检测到图标但未执行任何动作则直接跳过
|
||||||
if action_detected:
|
if did_like or did_fav or did_comment:
|
||||||
dwell_min = float(
|
dwell_min = float(
|
||||||
getattr(analyser, "yanghao_dwell_on_action_min_seconds", 5) or 5
|
getattr(analyser, "yanghao_dwell_on_action_min_seconds", 5) or 5
|
||||||
)
|
)
|
||||||
@@ -304,6 +367,57 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
|||||||
start_ts = time.time()
|
start_ts = time.time()
|
||||||
last_desktop_check_ts = 0.0
|
last_desktop_check_ts = 0.0
|
||||||
|
|
||||||
|
def _yanghao_check_and_recover_from_desktop(analyser) -> bool:
|
||||||
|
"""养号模式下的桌面检测和自救恢复(提前定义以供循环使用)。"""
|
||||||
|
try:
|
||||||
|
# 获取前台包名
|
||||||
|
top_pkg = analyser.operation.get_top_package(analyser.device_id) or ""
|
||||||
|
|
||||||
|
# 检查是否在抖音前台
|
||||||
|
is_douyin_pkg = top_pkg and (
|
||||||
|
"aweme" in top_pkg
|
||||||
|
or "douyin" in top_pkg
|
||||||
|
or "com.ss.android.ugc" in top_pkg
|
||||||
|
)
|
||||||
|
|
||||||
|
if top_pkg and not is_douyin_pkg:
|
||||||
|
print(f"[养号] 自救: 检测到不在抖音前台,前台包名={top_pkg}")
|
||||||
|
|
||||||
|
# 执行自救操作
|
||||||
|
try:
|
||||||
|
# 点击桌面图标
|
||||||
|
desktop_x = int(getattr(analyser, "desktop_icon_x", 153) or 153)
|
||||||
|
desktop_y = int(getattr(analyser, "desktop_icon_y", 260) or 260)
|
||||||
|
analyser.operation.click(analyser.device_id, desktop_x, desktop_y)
|
||||||
|
analyser.operation.delay(2)
|
||||||
|
|
||||||
|
# 点击直播按钮(备用坐标)
|
||||||
|
fallback_x = int(getattr(analyser, "yanghao_fallback_live_x", 540) or 540)
|
||||||
|
fallback_y = int(getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000)
|
||||||
|
analyser.operation.click(analyser.device_id, fallback_x, fallback_y)
|
||||||
|
analyser.operation.delay(1.5)
|
||||||
|
|
||||||
|
# 点击进入直播间(备用坐标)
|
||||||
|
enter_x = int(getattr(analyser, "yanghao_fallback_enter_live_x", 540) or 540)
|
||||||
|
enter_y = int(getattr(analyser, "yanghao_fallback_enter_live_y", 1200) or 1200)
|
||||||
|
analyser.operation.click(analyser.device_id, enter_x, enter_y)
|
||||||
|
analyser.operation.delay(0.6)
|
||||||
|
analyser.operation.click(analyser.device_id, enter_x, enter_y)
|
||||||
|
analyser.operation.delay(2.0)
|
||||||
|
|
||||||
|
print("[养号] 自救: 恢复操作完成")
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[养号] 自救: 恢复操作失败: {e}")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[养号] 自救: 桌面检测异常: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
elapsed = now - start_ts
|
elapsed = now - start_ts
|
||||||
@@ -362,59 +476,7 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
|||||||
)
|
)
|
||||||
_step_shot("after_swipe")
|
_step_shot("after_swipe")
|
||||||
|
|
||||||
def _scaled_click(base_x: int, base_y: int) -> None:
|
# 使用模块级 `_scaled_click(analyser, ...)` 和 `_do_comment(analyser)` 实现
|
||||||
sx, sy = analyser._scale_from_base(int(base_x), int(base_y))
|
|
||||||
analyser.operation.click(analyser.device_id, sx, sy)
|
|
||||||
|
|
||||||
def _do_comment() -> None:
|
|
||||||
"""执行评论操作:点击评论按钮 -> 输入框 -> 输入文本 -> 发送 -> 关闭"""
|
|
||||||
try:
|
|
||||||
# 步骤1: 点击评论按钮
|
|
||||||
_scaled_click(
|
|
||||||
int(getattr(analyser, "yanghao_comment_btn_x", 540) or 540),
|
|
||||||
int(getattr(analyser, "yanghao_comment_btn_y", 2000) or 2000),
|
|
||||||
)
|
|
||||||
analyser.operation.delay(2.0) # 延迟2秒
|
|
||||||
|
|
||||||
# 步骤2: 点击输入框
|
|
||||||
_scaled_click(
|
|
||||||
int(getattr(analyser, "yanghao_comment_input_x", 540) or 540),
|
|
||||||
int(getattr(analyser, "yanghao_comment_input_y", 1900) or 1900),
|
|
||||||
)
|
|
||||||
analyser.operation.delay(2.0) # 延迟2秒
|
|
||||||
|
|
||||||
# 步骤3: 输入评论文本
|
|
||||||
comment_texts = getattr(analyser, "yanghao_comment_texts", []) or []
|
|
||||||
if not comment_texts:
|
|
||||||
comment_texts = ["加油", "不错", "很好看"]
|
|
||||||
selected_text = random.choice(comment_texts)
|
|
||||||
|
|
||||||
ix, iy = analyser._scale_from_base(
|
|
||||||
int(getattr(analyser, "yanghao_comment_input_x", 540) or 540),
|
|
||||||
int(getattr(analyser, "yanghao_comment_input_y", 1900) or 1900),
|
|
||||||
)
|
|
||||||
ok_input = bool(
|
|
||||||
analyser.operation.paste_text_at(
|
|
||||||
analyser.device_id, ix, iy, selected_text
|
|
||||||
)
|
|
||||||
)
|
|
||||||
analyser.operation.delay(2.0) # 延迟2秒
|
|
||||||
|
|
||||||
# 步骤4: 发送评论
|
|
||||||
ok_send = bool(
|
|
||||||
analyser.operation.confirm_from_keyboard(analyser.device_id)
|
|
||||||
)
|
|
||||||
analyser.operation.delay(2.0) # 延迟2秒
|
|
||||||
|
|
||||||
# 步骤5: 关闭评论窗口
|
|
||||||
_scaled_click(
|
|
||||||
int(getattr(analyser, "yanghao_comment_close_x", 900) or 900),
|
|
||||||
int(getattr(analyser, "yanghao_comment_close_y", 300) or 300),
|
|
||||||
)
|
|
||||||
analyser.operation.delay(2.0) # 延迟2秒
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[养号] 评论操作失败: {e}")
|
|
||||||
|
|
||||||
def _human_delay(min_s: float = 0.4, max_s: float = 1.2) -> None:
|
def _human_delay(min_s: float = 0.4, max_s: float = 1.2) -> None:
|
||||||
try:
|
try:
|
||||||
@@ -593,20 +655,29 @@ def yanghao_recommend_flow(analyser, total_seconds: int) -> None:
|
|||||||
每一步操作间隔1秒,确保界面稳定。
|
每一步操作间隔1秒,确保界面稳定。
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# 输出设备分辨率与调试行(兼容原始日志格式)
|
||||||
|
try:
|
||||||
|
resx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
|
||||||
|
resy = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400)
|
||||||
|
except Exception:
|
||||||
|
resx, resy = 1080, 2400
|
||||||
|
print(f"设备分辨率为:{resx}*{resy}")
|
||||||
|
print(f"[YANGHAO-ONLY] device_id={analyser.device_id} res={resx}x{resy}")
|
||||||
print("[养号] 开始推荐页养号流程")
|
print("[养号] 开始推荐页养号流程")
|
||||||
|
|
||||||
# 步骤1: 发送系统返回键退出当前直播间
|
# 步骤1: 发送系统返回键退出当前直播间
|
||||||
print("[养号] 步骤1: 发送系统返回键退出直播间")
|
print("[养号] 步骤1: 发送系统返回键退出直播间")
|
||||||
analyser.operation.keyevent(analyser.device_id, 4) # KEYCODE_BACK = 4
|
analyser.operation.keyevent(analyser.device_id, 4) # KEYCODE_BACK = 4
|
||||||
analyser.operation.delay(1.0)
|
analyser.operation.delay(3.0)
|
||||||
|
|
||||||
# 步骤2: 再次发送返回键确保退出
|
# 步骤2: 再次发送返回键确保退出
|
||||||
print("[养号] 步骤2: 再次发送返回键")
|
print("[养号] 步骤2: 再次发送返回键")
|
||||||
analyser.operation.keyevent(analyser.device_id, 4) # KEYCODE_BACK = 4
|
analyser.operation.keyevent(analyser.device_id, 4) # KEYCODE_BACK = 4
|
||||||
analyser.operation.delay(1.0)
|
analyser.operation.delay(3.0)
|
||||||
|
|
||||||
# 步骤3: 在推荐页执行养号
|
# 步骤3: 在推荐页执行养号
|
||||||
print(f"[养号] 步骤3: 在推荐页养号 {total_seconds} 秒")
|
print(f"[养号] 步骤3: 在推荐页养号 {total_seconds} 秒")
|
||||||
|
analyser.operation.delay(3.0)
|
||||||
yanghao_idle(analyser, total_seconds)
|
yanghao_idle(analyser, total_seconds)
|
||||||
|
|
||||||
print("[养号] 推荐页养号流程完成")
|
print("[养号] 推荐页养号流程完成")
|
||||||
|
|||||||
Reference in new issue
Block a user