feat: 添加检测动作后停留时间设置,支持随机范围
This commit is contained in:
1 parent
540c30f90c
commit
a48e4004da
3 files changed
+121
-45
No files matched your search
@@ -225,6 +225,7 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
int(getattr(analyser, "yanghao_like_icon_x", 0) or 0),
|
||||
int(getattr(analyser, "yanghao_like_icon_y", 0) or 0),
|
||||
)
|
||||
analyser.operation.delay(2.0) # 延迟2秒
|
||||
print(
|
||||
"[养号] 动作: 点爱心(prob={})".format(
|
||||
getattr(analyser, "yanghao_like_prob", 0)
|
||||
@@ -248,6 +249,7 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
int(getattr(analyser, "yanghao_fav_icon_x", 0) or 0),
|
||||
int(getattr(analyser, "yanghao_fav_icon_y", 0) or 0),
|
||||
)
|
||||
analyser.operation.delay(2.0) # 延迟2秒
|
||||
print(
|
||||
"[养号] 动作: 点收藏(prob={})".format(
|
||||
getattr(analyser, "yanghao_fav_prob", 0)
|
||||
@@ -260,6 +262,22 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
else:
|
||||
print("[养号] 动作: 跳过点收藏(未检测到图标)")
|
||||
|
||||
# 根据概率评论
|
||||
if float(
|
||||
getattr(analyser, "yanghao_comment_prob", 0) or 0
|
||||
) > 0 and random.random() < float(
|
||||
getattr(analyser, "yanghao_comment_prob", 0) or 0
|
||||
):
|
||||
_do_comment()
|
||||
print(
|
||||
"[养号] 动作: 评论(prob={})".format(
|
||||
getattr(analyser, "yanghao_comment_prob", 0)
|
||||
)
|
||||
)
|
||||
else:
|
||||
prob = getattr(analyser, "yanghao_comment_prob", 0)
|
||||
print("[养号] 动作: 跳过评论(prob={prob})")
|
||||
|
||||
# 如果检测到爱心或收藏任意一个,则随机停留5-30s
|
||||
if action_detected:
|
||||
dwell_min = float(
|
||||
@@ -297,13 +315,12 @@ def yanghao_idle(analyser, total_seconds: int) -> None:
|
||||
if now - last_desktop_check_ts >= check_interval:
|
||||
last_desktop_check_ts = now
|
||||
try:
|
||||
# 桌面检测与恢复逻辑待实现(保留占位)
|
||||
# if yanghao_check_and_recover_from_desktop(analyser):
|
||||
# print("[养号] 检测到在桌面,已尝试恢复")
|
||||
# analyser.operation.delay(1)
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
# 桌面检测与恢复逻辑
|
||||
if _yanghao_check_and_recover_from_desktop(analyser):
|
||||
print("[养号] 检测到不在抖音前台,已尝试恢复")
|
||||
analyser.operation.delay(1)
|
||||
except Exception as e:
|
||||
print(f"[养号] 桌面检测异常: {e}")
|
||||
|
||||
# 分段等待(避免一次 sleep 太久,看起来更自然)
|
||||
remaining = int(total_seconds - (time.time() - start_ts))
|
||||
@@ -349,6 +366,56 @@ def yanghao_idle(analyser, total_seconds: 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() -> 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:
|
||||
try:
|
||||
mn = float(min_s)
|
||||
|
||||
+38
-34
@@ -19,36 +19,30 @@ init(autoreset=True)
|
||||
# 定义颜色映射(根据日志标签分配颜色)
|
||||
COLOR_MAP = {
|
||||
# 流程相关
|
||||
'流程': Fore.CYAN,
|
||||
'阶段': Fore.BLUE,
|
||||
|
||||
"流程": Fore.CYAN,
|
||||
"阶段": Fore.BLUE,
|
||||
# 参与相关
|
||||
'参与': Fore.GREEN,
|
||||
'预约': Fore.YELLOW,
|
||||
|
||||
"参与": Fore.GREEN,
|
||||
"预约": Fore.YELLOW,
|
||||
# 识别相关
|
||||
'识别': Fore.MAGENTA,
|
||||
'OCR': Fore.RED,
|
||||
'截图': Fore.LIGHTRED_EX,
|
||||
|
||||
"识别": Fore.MAGENTA,
|
||||
"OCR": Fore.RED,
|
||||
"截图": Fore.LIGHTRED_EX,
|
||||
# 福袋查找相关
|
||||
'福袋查找': Fore.LIGHTBLUE_EX,
|
||||
|
||||
"福袋查找": Fore.LIGHTBLUE_EX,
|
||||
# 错误和警告
|
||||
'错误': Fore.RED + Style.BRIGHT,
|
||||
'警告': Fore.YELLOW + Style.BRIGHT,
|
||||
'异常': Fore.RED + Back.YELLOW,
|
||||
|
||||
"错误": Fore.RED + Style.BRIGHT,
|
||||
"警告": Fore.YELLOW + Style.BRIGHT,
|
||||
"异常": Fore.RED + Back.YELLOW,
|
||||
# 统计相关
|
||||
'统计': Fore.LIGHTCYAN_EX,
|
||||
'效率': Fore.LIGHTGREEN_EX,
|
||||
|
||||
"统计": Fore.LIGHTCYAN_EX,
|
||||
"效率": Fore.LIGHTGREEN_EX,
|
||||
# 默认颜色
|
||||
'default': Fore.WHITE,
|
||||
"default": Fore.WHITE,
|
||||
}
|
||||
|
||||
# 正则表达式匹配日志行格式
|
||||
LOG_PATTERN = re.compile(r'^\[([^\]]+)\]\s*\[([^\]]+)\]\s*(.*)$')
|
||||
LOG_PATTERN = re.compile(r"^\[([^\]]+)\]\s*\[([^\]]+)\]\s*(.*)$")
|
||||
|
||||
|
||||
def get_color_for_tag(tag):
|
||||
@@ -59,10 +53,10 @@ def get_color_for_tag(tag):
|
||||
return COLOR_MAP[tag]
|
||||
|
||||
for key in COLOR_MAP:
|
||||
if key != 'default' and tag.startswith(key):
|
||||
if key != "default" and tag.startswith(key):
|
||||
return COLOR_MAP[key]
|
||||
|
||||
return COLOR_MAP['default']
|
||||
return COLOR_MAP["default"]
|
||||
|
||||
|
||||
def colorize_log_line(line):
|
||||
@@ -74,7 +68,7 @@ def colorize_log_line(line):
|
||||
color = get_color_for_tag(tag)
|
||||
|
||||
# 如果主标签为默认颜色,尝试从 message 中提取第一个方括号子标签再匹配一次
|
||||
if color == COLOR_MAP['default']:
|
||||
if color == COLOR_MAP["default"]:
|
||||
inner_bracket = re.search(r"\[([^\]]+)\]", message)
|
||||
if inner_bracket:
|
||||
inner_tag = inner_bracket.group(1).strip()
|
||||
@@ -85,6 +79,7 @@ def colorize_log_line(line):
|
||||
# 非标准格式的行,使用默认颜色
|
||||
return f"{Fore.LIGHTBLACK_EX}{line}{Style.RESET_ALL}"
|
||||
|
||||
|
||||
def filter_and_colorize_log(log_file_path, filter_keyword=None, max_lines=50):
|
||||
"""
|
||||
读取日志文件,筛选并彩色化输出
|
||||
@@ -104,7 +99,7 @@ def filter_and_colorize_log(log_file_path, filter_keyword=None, max_lines=50):
|
||||
print(f"{Fore.CYAN}过滤关键字: {filter_keyword}{Style.RESET_ALL}")
|
||||
|
||||
try:
|
||||
with open(log_path, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
with open(log_path, "r", encoding="utf-8", errors="ignore") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
total_lines = len(lines)
|
||||
@@ -134,33 +129,41 @@ def filter_and_colorize_log(log_file_path, filter_keyword=None, max_lines=50):
|
||||
break
|
||||
|
||||
if max_lines is not None and len(filtered_lines) > max_lines:
|
||||
print(f"\n{Fore.YELLOW}... 还有 {len(filtered_lines) - max_lines} 行未显示 (使用 --all 参数查看全部){Style.RESET_ALL}")
|
||||
print(
|
||||
f"\n{Fore.YELLOW}... 还有 {len(filtered_lines) - max_lines} 行未显示 (使用 --all 参数查看全部){Style.RESET_ALL}"
|
||||
)
|
||||
|
||||
print()
|
||||
print(f"{Fore.YELLOW}{'='*80}{Style.RESET_ALL}")
|
||||
print(f"{Fore.GREEN}显示完成 (显示 {displayed_count}/{len(filtered_lines)} 行){Style.RESET_ALL}")
|
||||
print(
|
||||
f"{Fore.GREEN}显示完成 (显示 {displayed_count}/{len(filtered_lines)} 行){Style.RESET_ALL}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"{Fore.RED}错误: 读取文件时出错: {e}{Style.RESET_ALL}")
|
||||
|
||||
|
||||
def show_color_legend():
|
||||
"""显示颜色图例"""
|
||||
print(f"{Fore.CYAN}日志颜色图例:{Style.RESET_ALL}")
|
||||
print(f"{Fore.CYAN}{'='*40}{Style.RESET_ALL}")
|
||||
for tag, color in COLOR_MAP.items():
|
||||
if tag != 'default':
|
||||
if tag != "default":
|
||||
print(f"{color}[{tag}]{Style.RESET_ALL} - {tag}相关日志")
|
||||
print(f"{Fore.LIGHTBLACK_EX}[默认]{Style.RESET_ALL} - 其他日志")
|
||||
print()
|
||||
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='彩色日志查看器')
|
||||
parser.add_argument('log_file', help='日志文件路径')
|
||||
parser.add_argument('filter_keyword', nargs='?', help='过滤关键字(可选)')
|
||||
parser.add_argument('--lines', type=int, default=50, help='最大显示行数(默认50)')
|
||||
parser.add_argument('--all', action='store_true', help='显示所有行(忽略--lines限制)')
|
||||
parser = argparse.ArgumentParser(description="彩色日志查看器")
|
||||
parser.add_argument("log_file", help="日志文件路径")
|
||||
parser.add_argument("filter_keyword", nargs="?", help="过滤关键字(可选)")
|
||||
parser.add_argument("--lines", type=int, default=50, help="最大显示行数(默认50)")
|
||||
parser.add_argument(
|
||||
"--all", action="store_true", help="显示所有行(忽略--lines限制)"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -176,5 +179,6 @@ def main():
|
||||
show_color_legend()
|
||||
filter_and_colorize_log(log_file, filter_keyword, max_lines)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
+9
-4
@@ -518,12 +518,17 @@
|
||||
|
||||
<div class="row grid2">
|
||||
<div>
|
||||
<label class="label">图标 ROI 大小(px)</label>
|
||||
<input id="yanghao_icon_roi_size" class="input" data-key="yanghao_icon_roi_size" data-type="int" type="number" min="80" max="600" step="10" />
|
||||
<label class="label">检测动作后停留(秒)</label>
|
||||
<div class="inline2">
|
||||
<input id="yanghao_dwell_on_action_min_seconds" class="input" data-key="yanghao_dwell_on_action_min_seconds" data-type="float" type="number" min="0" max="120" step="1" value="5" />
|
||||
<span>~</span>
|
||||
<input id="yanghao_dwell_on_action_max_seconds" class="input" data-key="yanghao_dwell_on_action_max_seconds" data-type="float" type="number" min="0" max="120" step="1" value="30" />
|
||||
</div>
|
||||
<div class="hint">随机范围</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">匹配阈�?/label>
|
||||
<input id="yanghao_icon_match_threshold" class="input" data-key="yanghao_icon_match_threshold" data-type="float" type="number" min="0" max="1" step="0.01" />
|
||||
<label class="label">图标 ROI 大小(px)</label>
|
||||
<input id="yanghao_icon_roi_size" class="input" data-key="yanghao_icon_roi_size" data-type="int" type="number" min="80" max="600" step="10" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user