20250911-初步功能已完成
This commit is contained in:
@@ -322,9 +322,9 @@ class ScriptManager():
|
||||
ControlUtils.clickBack(session)
|
||||
time.sleep(2)
|
||||
|
||||
print("循环条件1", not event.is_set())
|
||||
print("循环条件2", len(anchorList) > 0)
|
||||
print("总循环条件", not event.is_set() and len(anchorList) > 0)
|
||||
LogManager.method_info(f"循环条件1:{not event.is_set()}", "关注打招呼", udid)
|
||||
LogManager.method_info(f"循环条件2:{len(anchorList) > 0}", "关注打招呼", udid)
|
||||
LogManager.method_info(f"循环条件3:{not event.is_set() and len(anchorList) > 0}", "关注打招呼", udid)
|
||||
|
||||
# 循环条件。1、 循环关闭 2、 数据处理完毕
|
||||
while not event.is_set():
|
||||
@@ -359,7 +359,7 @@ class ScriptManager():
|
||||
input.clear_text()
|
||||
time.sleep(1)
|
||||
# 输入主播id
|
||||
input.set_text(aid + "\n")
|
||||
input.set_text(f"{aid or '暂无数据'}\n")
|
||||
|
||||
# 定位 "关注" 按钮 通过关注按钮的位置点击主播首页
|
||||
|
||||
@@ -488,11 +488,12 @@ class ScriptManager():
|
||||
chatInput.click()
|
||||
time.sleep(2)
|
||||
# 发送消息
|
||||
chatInput.set_text(msg + "\n")
|
||||
chatInput.set_text(f"{msg or '暂无数据'}\n")
|
||||
|
||||
# input.set_text(f"{aid or '暂无数据'}\n")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
else:
|
||||
print("无法发送信息")
|
||||
LogManager.method_info(f"给主播{aid} 发送消息失败", "关注打招呼", udid)
|
||||
@@ -568,17 +569,17 @@ class ScriptManager():
|
||||
time.sleep(3)
|
||||
|
||||
while not event.is_set():
|
||||
# try:
|
||||
try:
|
||||
# 调用检测消息的方法
|
||||
self.monitorMessages(session, udid)
|
||||
# except Exception as e:
|
||||
# LogManager.method_error(f"监控消息 出现异常: {e},重新启动监控直播", "检测消息", udid)
|
||||
# # 出现异常时,稍等再重启 TikTok 并重试
|
||||
# ControlUtils.closeTikTok(session, udid)
|
||||
# time.sleep(2)
|
||||
# ControlUtils.openTikTok(session, udid)
|
||||
# time.sleep(3)
|
||||
# continue # 重新进入 while 循环,调用 monitorMessages
|
||||
self.monitorMessages(session, udid)
|
||||
except Exception as e:
|
||||
LogManager.method_error(f"监控消息 出现异常: {e},重新启动监控直播", "检测消息", udid)
|
||||
# 出现异常时,稍等再重启 TikTok 并重试
|
||||
ControlUtils.closeTikTok(session, udid)
|
||||
time.sleep(2)
|
||||
ControlUtils.openTikTok(session, udid)
|
||||
time.sleep(3)
|
||||
continue # 重新进入 while 循环,调用 monitorMessages
|
||||
|
||||
# 检查未读消息并回复
|
||||
def monitorMessages(self, session, udid):
|
||||
@@ -740,14 +741,14 @@ class ScriptManager():
|
||||
}]
|
||||
print(last_data)
|
||||
|
||||
|
||||
LogManager.method_info(f"主播最后发送的数据:{last_data}", "检测消息", udid)
|
||||
JsonUtils.append_json_items(last_data, "log/last_message.json")
|
||||
sel = session.xpath("//TextView")
|
||||
|
||||
if anchor_name not in anchorWithSession:
|
||||
# 如果是第一次发消息(没有sessionId的情况)
|
||||
response = Requester.chatToAi({"msg": last_msg_text})
|
||||
|
||||
response = Requester.chatToAi({"query": last_msg_text})
|
||||
aiResult = response['result']
|
||||
sessionId = response['session_id']
|
||||
|
||||
@@ -757,20 +758,21 @@ class ScriptManager():
|
||||
sel.click() # 聚焦
|
||||
time.sleep(1)
|
||||
sel.clear_text()
|
||||
sel.set_text(aiResult + "\n")
|
||||
sel.set_text(f"{aiResult or '暂无数据'}\n")
|
||||
|
||||
else:
|
||||
LogManager.method_error("找不到输入框,重启", "检测消息", udid)
|
||||
raise Exception("找不到输入框,重启")
|
||||
else:
|
||||
# 如果不是第一次发消息(证明存储的有sessionId)
|
||||
sessionId = anchorWithSession[anchor_name]
|
||||
response = Requester.chatToAi({"msg": last_msg_text, "sid": sessionId})
|
||||
response = Requester.chatToAi({"query": last_msg_text, "conversation_id": sessionId})
|
||||
aiResult = response['result']
|
||||
if sel.exists:
|
||||
sel.click() # 聚焦
|
||||
time.sleep(1)
|
||||
sel.clear_text()
|
||||
sel.set_text(aiResult + "\n")
|
||||
sel.set_text(f"{aiResult or '暂无数据'}\n")
|
||||
|
||||
LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid)
|
||||
time.sleep(1)
|
||||
|
||||
Reference in New Issue
Block a user