diff --git a/worker/tasks/boss_recruit.py b/worker/tasks/boss_recruit.py index e903dbe..11526c7 100644 --- a/worker/tasks/boss_recruit.py +++ b/worker/tasks/boss_recruit.py @@ -168,11 +168,14 @@ class BossRecruitHandler(BaseTaskHandler): else: self.logger.info("[%s] 已有招呼记录,跳过", name) - # 询问微信号 - if not ctx["already_asked_wechat"]: + # 与本地自动化.py一致:没有联系方式时,发送询问并触发“换微信” + if not ctx["wechats"] and not ctx["phones"]: if self._send_message(tab, inp, ask_wechat): self.logger.info("[%s] 已询问微信号", name) - human_delay(1.5, 2.8) + human_delay(1.2, 2.2) + if self._try_exchange_wechat(tab): + self.logger.info("[%s] 已执行换微信", name) + human_delay(1.2, 2.2) # 收集微信号 human_delay(1.0, 2.0) @@ -255,6 +258,8 @@ class BossRecruitHandler(BaseTaskHandler): human_delay(0.15, 0.4) inp.input(message) human_delay(0.4, 0.9) + if self._click_send_button_like_script(tab): + return True if self._click_send_button(tab): return True inp.input("\n") @@ -263,6 +268,51 @@ class BossRecruitHandler(BaseTaskHandler): except Exception: return False + def _click_send_button_like_script(self, tab) -> bool: + """Use the same selector style as 自动化.py for the send button.""" + text_send = "\u53d1\u9001" + try: + btn = tab.ele(f"x://div[text()=\"{text_send}\"]", timeout=1) + if btn and safe_click(tab, btn): + return True + except Exception: + pass + try: + btn = tab.ele(f"x://span[text()=\"{text_send}\"]", timeout=1) + if btn and safe_click(tab, btn): + return True + except Exception: + pass + return False + + def _try_exchange_wechat(self, tab) -> bool: + """ + Click '换微信', then confirm the '确定与对方交换微信吗?' dialog. + """ + text_change = "\u6362\u5fae\u4fe1" + tip_cn = "\u786e\u5b9a\u4e0e\u5bf9\u65b9\u4ea4\u6362\u5fae\u4fe1\u5417\uff1f" + tip_en = "\u786e\u5b9a\u4e0e\u5bf9\u65b9\u4ea4\u6362\u5fae\u4fe1\u5417?" + + try: + human_delay(0.8, 1.6) + btn = tab.ele(f"x://span[text()=\"{text_change}\"]", timeout=1) + if not btn or not safe_click(tab, btn): + return False + + human_delay(0.8, 1.6) + confirm = tab.ele( + f"x://span[contains(text(),\"{tip_cn}\")]/../div[@class=\"btn-box\"]/span[contains(@class,\"boss-btn-primary\")]", + timeout=2, + ) + if not confirm: + confirm = tab.ele( + f"x://span[contains(text(),\"{tip_en}\")]/../div[@class=\"btn-box\"]/span[contains(@class,\"boss-btn-primary\")]", + timeout=2, + ) + return bool(confirm and safe_click(tab, confirm)) + except Exception: + return False + def _click_send_button(self, tab) -> bool: human_delay(0.2, 0.45) btn = find_element(tab, [