refactor: 优化代码格式,提升可读性
This commit is contained in:
1 parent
a84836a6c7
commit
3fa03b780b
5 files changed
+146
-45
No files matched your search
@@ -2731,10 +2731,17 @@ class underlying_operations:
|
||||
|
||||
raise PermissionError("sendevent 需要 root 权限且实现复杂,暂不支持完整实现")
|
||||
|
||||
def click(self, device_id, x=500, y=500):
|
||||
"""点击坐标位置"""
|
||||
def click(self, device_id, x=500, y=500, log: bool = True):
|
||||
"""点击坐标位置
|
||||
|
||||
参数:
|
||||
device_id: 设备ID
|
||||
x, y: 屏幕坐标
|
||||
log: 是否打印底层日志(默认为 True)。在需要安静点击的场景(如养号)传 False。
|
||||
"""
|
||||
try:
|
||||
print(f"[Underlying] click: device_id={device_id} coord=({x},{y})")
|
||||
if log:
|
||||
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))
|
||||
|
||||
+4
-4
@@ -41,9 +41,9 @@
|
||||
"fudai_disable_task_recognition": true,
|
||||
"yanghao_recommend_duration_seconds": 180,
|
||||
"yanghao_recommend_interval_seconds": 600,
|
||||
"yanghao_like_prob": 0.3,
|
||||
"yanghao_fav_prob": 0.2,
|
||||
"yanghao_comment_prob": 0.5,
|
||||
"yanghao_like_prob": 1.0,
|
||||
"yanghao_fav_prob": 1.0,
|
||||
"yanghao_comment_prob": 1.0,
|
||||
"yanghao_icon_roi_size": 240,
|
||||
"yanghao_icon_match_threshold": 0.77,
|
||||
"yanghao_step_screenshot": true,
|
||||
@@ -213,7 +213,7 @@
|
||||
"fansclub_auto_join_wait_seconds": 5.0,
|
||||
"fansclub_manual_wait_seconds": 3.0,
|
||||
"enable_streaming_screenshot": false,
|
||||
"yanghao_only": false,
|
||||
"yanghao_only": true,
|
||||
"record_room_title_mapping_enabled": true,
|
||||
"high_value_fudai_poll_before_seconds": 10.0,
|
||||
"high_value_room_revisit_min_interval_seconds": 300,
|
||||
|
||||
@@ -263,12 +263,13 @@ class LoggingWrapper:
|
||||
):
|
||||
key_cn = key_map.get(str(k), k)
|
||||
if isinstance(v, float):
|
||||
if "seconds" in k or "elapsed" in k:
|
||||
# 优先检测毫秒字段(例如 elapsed_ms、total_elapsed_ms),避免被 "elapsed" 关键字误判为秒
|
||||
if "ms" in k:
|
||||
v_str = f"{v:.0f}ms"
|
||||
elif "seconds" in k or "elapsed" in k:
|
||||
v_str = f"{v:.1f}s"
|
||||
elif "yuan" in k:
|
||||
v_str = f"{v:.0f}元"
|
||||
elif "ms" in k:
|
||||
v_str = f"{v:.0f}ms"
|
||||
elif "分数" in k or "置信度" in k or "比例" in k or "阈值" in k:
|
||||
v_str = f"{v:.3f}"
|
||||
else:
|
||||
@@ -433,6 +434,40 @@ class LoggingWrapper:
|
||||
) as f:
|
||||
f.write(action_log_line + "\n")
|
||||
f.flush()
|
||||
# 同步调用行为日志模块以获得结构化记录
|
||||
try:
|
||||
if LOGGING_MODULES_AVAILABLE and _action_logger:
|
||||
# 提取耗时(统一为秒传入 ActionLogger)
|
||||
elapsed_seconds = None
|
||||
try:
|
||||
if "elapsed_ms" in fields:
|
||||
elapsed_seconds = float(fields.get("elapsed_ms", 0)) / 1000.0
|
||||
elif "total_ms" in fields:
|
||||
elapsed_seconds = float(fields.get("total_ms", 0)) / 1000.0
|
||||
elif "elapsed_seconds" in fields:
|
||||
elapsed_seconds = float(fields.get("elapsed_seconds", 0))
|
||||
elif "seconds" in fields:
|
||||
elapsed_seconds = float(fields.get("seconds", 0))
|
||||
except Exception:
|
||||
elapsed_seconds = None
|
||||
|
||||
# 构建额外字段(保留分数、价值、位置信息)
|
||||
extra = {}
|
||||
for k in ("score", "value_yuan", "room_pos", "fudai_x", "rid"):
|
||||
if k in fields:
|
||||
extra[k] = fields.get(k)
|
||||
|
||||
try:
|
||||
op_name = tag if tag else "操作"
|
||||
details = msg if msg else None
|
||||
if elapsed_seconds is not None:
|
||||
_action_logger.log_operation(op_name, details or "", elapsed=elapsed_seconds, **extra)
|
||||
else:
|
||||
_action_logger.log_operation(op_name, details or "", **extra)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -14,7 +14,12 @@ 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)
|
||||
# 使用底层 click 时不打印底层日志,以避免养号动作产生多余的聚焦/日志噪音
|
||||
try:
|
||||
analyser.operation.click(analyser.device_id, sx, sy, log=False)
|
||||
except TypeError:
|
||||
# 向后兼容:如果底层 click 还没有 log 参数,回退到旧调用
|
||||
analyser.operation.click(analyser.device_id, sx, sy)
|
||||
|
||||
|
||||
def _do_comment(analyser) -> None:
|
||||
@@ -25,14 +30,14 @@ def _do_comment(analyser) -> None:
|
||||
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)
|
||||
analyser.operation.delay(1.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)
|
||||
analyser.operation.delay(1.0)
|
||||
|
||||
# 步骤3: 输入评论文本
|
||||
comment_texts = getattr(analyser, "yanghao_comment_texts", []) or []
|
||||
@@ -48,19 +53,19 @@ def _do_comment(analyser) -> None:
|
||||
)
|
||||
)
|
||||
print(f"[养号][评论] paste_text_at -> ok={ok_input} scaled_coord=({ix},{iy})")
|
||||
analyser.operation.delay(2.0)
|
||||
analyser.operation.delay(1.0)
|
||||
|
||||
# 步骤4: 发送评论
|
||||
ok_send = bool(analyser.operation.confirm_from_keyboard(analyser.device_id))
|
||||
print(f"[养号][评论] Step4: 发送评论 -> ok={ok_send}")
|
||||
analyser.operation.delay(2.0)
|
||||
analyser.operation.delay(1.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)
|
||||
analyser.operation.delay(1.0)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[养号] 评论操作失败: {e}")
|
||||
@@ -280,14 +285,14 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
try:
|
||||
if not action_detected:
|
||||
consecutive_miss += 1
|
||||
print(f"[养号] 连续未检测到模板次数={consecutive_miss}/{miss_recover_threshold}")
|
||||
print(
|
||||
f"[养号] 连续未检测到模板次数={consecutive_miss}/{miss_recover_threshold}"
|
||||
)
|
||||
else:
|
||||
consecutive_miss = 0
|
||||
|
||||
if consecutive_miss >= miss_recover_threshold:
|
||||
print(
|
||||
"[养号] 连续多次未检测到模板,尝试按一次返回键进行自救"
|
||||
)
|
||||
print("[养号] 连续多次未检测到模板,尝试按一次返回键进行自救")
|
||||
try:
|
||||
analyser.operation.keyevent(analyser.device_id, 4)
|
||||
analyser.operation.delay(1.0)
|
||||
@@ -308,7 +313,8 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
last_desktop_check_ts = now
|
||||
try:
|
||||
top_pkg = (
|
||||
analyser.operation.get_top_package(analyser.device_id) or ""
|
||||
analyser.operation.get_top_package(analyser.device_id)
|
||||
or ""
|
||||
)
|
||||
is_douyin_pkg = top_pkg and (
|
||||
"aweme" in top_pkg
|
||||
@@ -316,23 +322,61 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
or "com.ss.android.ugc" in top_pkg
|
||||
)
|
||||
if top_pkg and not is_douyin_pkg:
|
||||
print(f"[养号] 自救: 检测到不在抖音前台,前台包名={top_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)
|
||||
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)
|
||||
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)
|
||||
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.click(
|
||||
analyser.device_id, enter_x, enter_y
|
||||
)
|
||||
analyser.operation.delay(2.0)
|
||||
|
||||
print("[养号] 自救: 恢复操作完成")
|
||||
@@ -350,13 +394,13 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
and random.random()
|
||||
< float(getattr(analyser, "yanghao_like_prob", 0) or 0)
|
||||
):
|
||||
_scaled_click(
|
||||
analyser,
|
||||
int(getattr(analyser, "yanghao_like_icon_x", 0) or 0),
|
||||
int(getattr(analyser, "yanghao_like_icon_y", 0) or 0),
|
||||
)
|
||||
did_like = True
|
||||
analyser.operation.delay(2.0) # 延迟2秒
|
||||
_scaled_click(
|
||||
analyser,
|
||||
int(getattr(analyser, "yanghao_like_icon_x", 0) or 0),
|
||||
int(getattr(analyser, "yanghao_like_icon_y", 0) or 0),
|
||||
)
|
||||
did_like = True
|
||||
analyser.operation.delay(1.0) # 延迟1秒
|
||||
print(
|
||||
"[养号] 动作: 点爱心(prob={})".format(
|
||||
getattr(analyser, "yanghao_like_prob", 0)
|
||||
@@ -382,7 +426,7 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
int(getattr(analyser, "yanghao_fav_icon_y", 0) or 0),
|
||||
)
|
||||
did_fav = True
|
||||
analyser.operation.delay(2.0) # 延迟2秒
|
||||
analyser.operation.delay(1.0) # 延迟1秒
|
||||
print(
|
||||
"[养号] 动作: 点收藏(prob={})".format(
|
||||
getattr(analyser, "yanghao_fav_prob", 0)
|
||||
@@ -406,6 +450,11 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
and random.random()
|
||||
< float(getattr(analyser, "yanghao_comment_prob", 0) or 0)
|
||||
):
|
||||
# 确保在评论前已完成爱心和收藏的点击效果,短暂等待保证顺序
|
||||
try:
|
||||
analyser.operation.delay(0.5)
|
||||
except Exception:
|
||||
pass
|
||||
_do_comment(analyser)
|
||||
did_comment = True
|
||||
print(
|
||||
|
||||
+15
-5
@@ -398,7 +398,9 @@ def main(argv: list[str]) -> int:
|
||||
int(getattr(analyser, "yanghao_comment_input_y", 1900)),
|
||||
)
|
||||
ok_input = bool(
|
||||
analyser.operation.paste_text_at(device_id, ix, iy, msg, ensure_focus=False)
|
||||
analyser.operation.paste_text_at(
|
||||
device_id, ix, iy, msg, ensure_focus=False
|
||||
)
|
||||
)
|
||||
print("[TEST-COMMENT] input {}".format("OK" if ok_input else "FAIL"))
|
||||
analyser.operation.delay(1)
|
||||
@@ -542,13 +544,21 @@ def main(argv: list[str]) -> int:
|
||||
if getattr(args, "high_value_room_revisit_only_current_run", False):
|
||||
analyser.high_value_room_revisit_only_current_run = True
|
||||
if getattr(args, "high_value_room_revisit_min_interval_seconds", None) is not None:
|
||||
analyser.high_value_room_revisit_min_interval_seconds = args.high_value_room_revisit_min_interval_seconds
|
||||
analyser.high_value_room_revisit_min_interval_seconds = (
|
||||
args.high_value_room_revisit_min_interval_seconds
|
||||
)
|
||||
if getattr(args, "high_value_room_revisit_max_per_run", None) is not None:
|
||||
analyser.high_value_room_revisit_max_per_run = args.high_value_room_revisit_max_per_run
|
||||
analyser.high_value_room_revisit_max_per_run = (
|
||||
args.high_value_room_revisit_max_per_run
|
||||
)
|
||||
if getattr(args, "high_value_room_revisit_min_prize_value", None) is not None:
|
||||
analyser.high_value_room_revisit_min_prize_value = args.high_value_room_revisit_min_prize_value
|
||||
analyser.high_value_room_revisit_min_prize_value = (
|
||||
args.high_value_room_revisit_min_prize_value
|
||||
)
|
||||
if getattr(args, "high_value_room_revisit_max_age_days", None) is not None:
|
||||
analyser.high_value_room_revisit_max_age_days = args.high_value_room_revisit_max_age_days
|
||||
analyser.high_value_room_revisit_max_age_days = (
|
||||
args.high_value_room_revisit_max_age_days
|
||||
)
|
||||
# 预约回退校验开关(命令行优先)
|
||||
if getattr(args, "reservation_back_verify_enabled", False):
|
||||
analyser.reservation_back_verify_enabled = True
|
||||
|
||||
Reference in new issue
Block a user