diff --git a/.idea/misc.xml b/.idea/misc.xml index 20aef6e..a37b124 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/Module/DeviceInfo.py b/Module/DeviceInfo.py index bbadad2..bdc9906 100644 --- a/Module/DeviceInfo.py +++ b/Module/DeviceInfo.py @@ -116,6 +116,45 @@ class DeviceInfo: self._iproxy_path = self._find_iproxy() LogManager.info("DeviceInfo 初始化完成", udid="system") print("[Init] DeviceInfo 初始化完成") + # 延迟执行删除设备方法 + threading.Thread(target=self.readdDevice).start() + + # 清空所有设备 + def readdDevice(self): + print("开始自动删除设备") + second = 0 + while True: + second += 1 + if second == 3555: + with self._lock: + # 先拍一张快照,避免“边遍历边修改” + udids = list(self._models.keys()) + for udid in udids: + print(f"[Remove] 正在移除设备 {udid}") + # 以 udid 为主键,逐个 pop + model = self._models.pop(udid, None) + proc = self._iproxy.pop(udid, None) + self._port_by_udid.pop(udid, None) + self._first_seen.pop(udid, None) + self._last_seen.pop(udid, None) + # 安全结束进程 + self._kill(proc) + # 组一个“下线通知”的占位模型 + if model is None: + model = DeviceModel( + deviceId=udid, screenPort=-1, width=0, height=0, scale=0.0, type=2 + ) + # 标记为“已移除/离线” + model.type = 2 + model.ready = False + model.screenPort = -1 + # 通知上层 + self._manager_send(model) + print(f"[Remove] 已移除设备 {udid}") + second = 0 + print(f"[Remove] 设备移除完成,总数: {len(udids)}") + time.sleep(1) + def listen(self): LogManager.method_info("进入主循环", "listen", udid="system") diff --git a/Module/__pycache__/DeviceInfo.cpython-312.pyc b/Module/__pycache__/DeviceInfo.cpython-312.pyc index b58179f..7d2a348 100644 Binary files a/Module/__pycache__/DeviceInfo.cpython-312.pyc and b/Module/__pycache__/DeviceInfo.cpython-312.pyc differ diff --git a/Module/__pycache__/Main.cpython-312.pyc b/Module/__pycache__/Main.cpython-312.pyc index 5ebac55..497bbf9 100644 Binary files a/Module/__pycache__/Main.cpython-312.pyc and b/Module/__pycache__/Main.cpython-312.pyc differ diff --git a/Utils/__pycache__/LogManager.cpython-312.pyc b/Utils/__pycache__/LogManager.cpython-312.pyc index c0a6424..4b44dc5 100644 Binary files a/Utils/__pycache__/LogManager.cpython-312.pyc and b/Utils/__pycache__/LogManager.cpython-312.pyc differ diff --git a/script/ScriptManager.py b/script/ScriptManager.py index 1aa3fdb..4e3daf0 100644 --- a/script/ScriptManager.py +++ b/script/ScriptManager.py @@ -52,7 +52,6 @@ class ScriptManager(): self.initialized = True # 标记已初始化 - # ========= 评论逻辑 ========= def comment_flow(self, filePath, session, udid, recomend_cx, recomend_cy): """评论一条龙:点评论框->输入->发送->返回""" @@ -80,6 +79,8 @@ class ScriptManager(): coord2 = OCRUtils.find_template(str(self.comment_add_dir), filePath) + click_count = False + if coord2: # 二判命中 LogManager.method_info(f"方案1", "养号", udid) cx2, cy2 = coord2[0] @@ -88,6 +89,8 @@ class ScriptManager(): session.send_keys(f"{single_comment}\n") time.sleep(2) LogManager.method_info("评论成功", "养号", udid) + click_count = True + else: time.sleep(1) LogManager.method_info(f"方案2", "养号", udid) @@ -101,13 +104,19 @@ class ScriptManager(): session.send_keys(f"{single_comment}\n") time.sleep(2) LogManager.method_info("评论成功", "养号", udid) + click_count = True # 点返回/取消按钮:优先用推荐按钮坐标,没有就兜底 100,100 tap_x = int(recomend_cx) if recomend_cx else 100 tap_y = int(recomend_cy) if recomend_cy else 100 - session.tap(tap_x, tap_y) - time.sleep(1) - session.tap(tap_x, tap_y) + if click_count: + print("点击一次") + session.tap(tap_x, tap_y) + else: + print("点击两次") + session.tap(tap_x, tap_y) + time.sleep(1) + session.tap(tap_x, tap_y) # 养号 def growAccount(self, udid, isComment, event, is_monitoring=False): @@ -223,6 +232,7 @@ class ScriptManager(): if isComment and random.random() > 0.70: self.comment_flow(filePath, session, udid, recomend_cx, recomend_cy) + event.wait(timeout=2) videoTime = random.randint(15, 30) for _ in range(videoTime): @@ -455,6 +465,8 @@ class ScriptManager(): for i in range(count): LogManager.method_info(f"返回上一步", "关注打招呼", udid) session.appium_settings({"snapshotMaxDepth": 15}) + source = session.source() + LogManager.method_info(f"返回按钮的节点:{source}","返回节点", udid) ControlUtils.clickBack(session) event.wait(timeout=2) @@ -543,7 +555,7 @@ class ScriptManager(): session.appium_settings({"snapshotMaxDepth": 15}) continue - event.wait(timeout=2) + event.wait(timeout=5) # 找到并点击第一个视频 cellClickResult, workCount = ControlUtils.clickFirstVideoFromDetailPage(session) @@ -599,6 +611,7 @@ class ScriptManager(): # 使用OCR进行评论 if isComment: self.comment_flow(filePath, session, udid, 100, 100) + event.wait(timeout=2) if count != 0: ControlUtils.swipe_up(udid) @@ -645,23 +658,32 @@ class ScriptManager(): print("找到输入框了, 准备发送一条打招呼消息") LogManager.method_info("找到输入框了, 准备发送一条打招呼消息", "关注打招呼", udid) - print("打招呼的数据", ev.prologueList) # LogManager.method_info(f"传递的打招呼的数据:{ev.prologueList}", "关注打招呼", udid) # 取出国家进行对应国家语言代码 anchorCountry_code = CountryLanguageMapper.get_language_code(anchorCountry) - print(anchorCountry_code) - print("存储的是:",ev.prologueList) + + LogManager.method_info(f"获取的语言代码是:{ev.prologueList}","关注打招呼",udid) + + LogManager.method_info(f"存储的打招呼语句是:{ev.prologueList}","关注打招呼",udid) + # 判断对应的语言代码是否在传入的字典中 if anchorCountry_code in ev.prologueList: + + LogManager.method_info(f"在存储的字典中 打招呼语句是:{ev.prologueList}", "关注打招呼", udid) + # 进行原本的进行传入 privateMessageList = ev.prologueList[anchorCountry_code] + + needTranslate = False else: + + LogManager.method_info(f"不在存储的字典中 打招呼语句是:{ev.prologueList}", "关注打招呼", udid) # 需要翻译 privateMessageList = ev.prologueList['yolo'] needTranslate = True # 使用yolo必须翻译 @@ -1315,6 +1337,7 @@ class ScriptManager(): sel = session.xpath("//TextView") if anchor_name not in anchorWithSession: + print("没有记忆") # 如果是第一次发消息(没有sessionId的情况) LogManager.method_info(f"第一次发消息:{anchor_name},没有记忆 开始请求ai", "检测消息", udid) @@ -1328,15 +1351,14 @@ class ScriptManager(): if last_out: text = last_out - - if sel.exists: sel.click() # 聚焦 event.wait(timeout=1) sel.clear_text() - LogManager.method_info(f"发送的消息,检测不到对方发送的消息,不走ai:{text or '暂无数据'}", "检测消息", - udid) + LogManager.method_info( + f"发送的消息,检测不到对方发送的消息,不走ai:{text or '暂无数据'}", "检测消息", + udid) sel.set_text(f"{text or '暂无数据'}\n") else: @@ -1352,42 +1374,59 @@ class ScriptManager(): sel.click() # 聚焦 event.wait(timeout=1) sel.clear_text() - LogManager.method_info(f"发送的消息,检测到对方发送的消息,进行走ai(没记忆):{aiResult or '暂无数据'}", "检测消息", - udid) + LogManager.method_info( + f"发送的消息,检测到对方发送的消息,进行走ai(没记忆):{aiResult or '暂无数据'}", + "检测消息", + udid) sel.set_text(f"{aiResult or '暂无数据'}\n") else: LogManager.method_error("找不到输入框,重启", "检测消息", udid) raise Exception("找不到输入框,重启") else: + print("有记忆") + LogManager.method_info(f"不是一次发消息:{anchor_name},有记忆", "检测消息", udid) # 如果不是第一次发消息(证明存储的有sessionId) sessionId = anchorWithSession[anchor_name] - # TODO: user后续添加,暂时写死 + if last_in is None: + last_in = "ok" + if sel.exists: + sel.click() # 聚焦 + event.wait(timeout=1) + sel.clear_text() + LogManager.method_info( + f"发送的消息,检测到对方发送的消息,进行走ai(有记忆):{last_in or '暂无数据'}", + "检测消息", + udid) + sel.set_text(f"{last_in or '暂无数据'}\n") + else: - LogManager.method_info(f"向ai发送的参数: 文本为:{last_in}", "检测消息", udid) + # TODO: user后续添加,暂时写死 - aiResult, sessionId = Requester.chatToAi( - {"query": last_in, "conversation_id": sessionId, "user": "1"}) + LogManager.method_info(f"向ai发送的参数: 文本为:{last_in}", "检测消息", udid) - if sel.exists: - sel.click() # 聚焦 - event.wait(timeout=1) - sel.clear_text() - LogManager.method_info( - f"发送的消息,检测到对方发送的消息,进行走ai(有记忆):{aiResult or '暂无数据'}", - "检测消息", - udid) - sel.set_text(f"{aiResult or '暂无数据'}\n") + aiResult, sessionId = Requester.chatToAi( + {"query": last_in, "conversation_id": sessionId, "user": "1"}) - LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid) - event.wait(timeout=1) - # 返回 - ControlUtils.clickBack(session) + if sel.exists: + sel.click() # 聚焦 + event.wait(timeout=1) + sel.clear_text() + LogManager.method_info( + f"发送的消息,检测到对方发送的消息,进行走ai(有记忆):{aiResult or '暂无数据'}", + "检测消息", + udid) + sel.set_text(f"{aiResult or '暂无数据'}\n") - # 重新回到收件箱页面后,强制刷新节点 - session.appium_settings({"snapshotMaxDepth": 25}) - event.wait(timeout=1) + LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid) + event.wait(timeout=1) + # 返回 + ControlUtils.clickBack(session) + + # 重新回到收件箱页面后,强制刷新节点 + session.appium_settings({"snapshotMaxDepth": 25}) + event.wait(timeout=1) try: # 如果 2 秒内找不到,会抛异常 diff --git a/script/__pycache__/ScriptManager.cpython-312.pyc b/script/__pycache__/ScriptManager.cpython-312.pyc index c3277f6..5fe13b3 100644 Binary files a/script/__pycache__/ScriptManager.cpython-312.pyc and b/script/__pycache__/ScriptManager.cpython-312.pyc differ