解决问题:评论可能卡住问题,AI检测到消息不回复
This commit is contained in:
@@ -104,6 +104,52 @@ class ControlUtils(object):
|
||||
print(e)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def isClickBackEnabled(cls, session: Client):
|
||||
try:
|
||||
|
||||
back = session.xpath(
|
||||
# ① 常见中文文案
|
||||
"//*[@label='返回' or @label='返回上一屏幕']"
|
||||
" | "
|
||||
# ② 英文 / 内部 name / 图标 label 的按钮(仅限 Button,且可见)
|
||||
"//XCUIElementTypeButton[@visible='true' and ("
|
||||
"@name='Back' or @label='Back' or " # 英文
|
||||
"@name='返回' or @label='返回' or " # 中文
|
||||
"@label='返回上一屏幕' or " # 中文另一种
|
||||
"@name='returnButton' or"
|
||||
"@name='nav_bar_start_back' or " # 内部常见 name
|
||||
"(@name='TTKProfileNavBarBaseItemComponent' and @label='IconChevronLeftOffsetLTR')" # 你给的特例
|
||||
")]"
|
||||
)
|
||||
|
||||
if back.exists:
|
||||
return True
|
||||
elif session.xpath("//*[@name='nav_bar_start_back']").exists:
|
||||
back = session.xpath("//*[@name='nav_bar_start_back']")
|
||||
if back.exists:
|
||||
return True
|
||||
elif session.xpath(
|
||||
"//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]").exists:
|
||||
back = session.xpath(
|
||||
"//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]")
|
||||
if back.exists:
|
||||
return True
|
||||
elif session.xpath(
|
||||
"(//XCUIElementTypeOther[@y='20' and @height='44']//XCUIElementTypeButton[@visible='true'])[1]").exists:
|
||||
back = session.xpath(
|
||||
"(//XCUIElementTypeOther[@y='20' and @height='44']//XCUIElementTypeButton[@visible='true'])[1]")
|
||||
if back.exists:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
# 点赞
|
||||
@classmethod
|
||||
def clickLike(cls, session: Client, udid):
|
||||
|
||||
@@ -429,7 +429,7 @@ class ScriptManager():
|
||||
LogManager.method_info("外层 while 检测到停止,即将 break", "关注打招呼", udid)
|
||||
break
|
||||
print("任务终止")
|
||||
LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
|
||||
LogManager.method_error("greetNewFollowers任务终止", "关注打招呼", udid)
|
||||
|
||||
# 关注打招呼
|
||||
def greetNewFollowers(self, udid, needReply, isComment, needTranslate, event):
|
||||
@@ -461,8 +461,7 @@ 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)
|
||||
|
||||
@@ -628,12 +627,18 @@ class ScriptManager():
|
||||
self.comment_flow(filePath, session, udid, 100, 100)
|
||||
event.wait(timeout=2)
|
||||
|
||||
session.appium_settings({"snapshotMaxDepth": 12})
|
||||
|
||||
is_back_enabled = ControlUtils.isClickBackEnabled(session)
|
||||
if not is_back_enabled:
|
||||
print("返回失败")
|
||||
raise Exception("返回失败,出现问题")
|
||||
|
||||
if count != 0:
|
||||
ControlUtils.swipe_up(client)
|
||||
|
||||
# 右滑返回
|
||||
# client.swipe_right()
|
||||
session.appium_settings({"snapshotMaxDepth": 12})
|
||||
|
||||
back_btn = ControlUtils.clickBack(session)
|
||||
|
||||
@@ -1163,7 +1168,6 @@ class ScriptManager():
|
||||
'//XCUIElementTypeButton[.//XCUIElementTypeStaticText[@value="收件箱"]]'
|
||||
)
|
||||
|
||||
print("el", el)
|
||||
if not el.exists:
|
||||
LogManager.method_error(f"检测不到收件箱", "检测消息", udid)
|
||||
raise Exception("当前页面找不到收件箱,重启")
|
||||
@@ -1249,14 +1253,7 @@ class ScriptManager():
|
||||
user_text.tap()
|
||||
event.wait(timeout=3)
|
||||
|
||||
# xml = session.source()
|
||||
# msgs = AiUtils.extract_messages_from_xml(xml)
|
||||
#
|
||||
# # 检测出对方发的最后一条信息,
|
||||
#
|
||||
# # 获取了最后一条消息
|
||||
# last_msg = next((item['text'] for item in reversed(msgs) if item['type'] == 'msg'),
|
||||
# "")
|
||||
|
||||
|
||||
xml = session.source()
|
||||
time.sleep(1)
|
||||
@@ -1293,17 +1290,7 @@ class ScriptManager():
|
||||
|
||||
LogManager.method_info(f"检测到对方最后发送的消息:{last_in}", "检测消息", udid)
|
||||
LogManager.method_info(f"检测我发送的最后一条信息:{last_out}", "检测消息", udid)
|
||||
# 如果最后一条消息不是文字,随机取出一条当做最后一条消息,最后一条消息是last_msg_text
|
||||
|
||||
# isLanguage = AiUtils.is_language(last_msg)
|
||||
#
|
||||
# if isLanguage:
|
||||
# last_msg_text = last_msg
|
||||
# else:
|
||||
# LogManager.method_info(f"对方发送的消息不是语言,随机挑选作为最后一条进行回复:{last_msg}",
|
||||
# "检测消息", udid)
|
||||
# # last_msg_text = random.choice(text_list)
|
||||
# last_msg_text = last_msg
|
||||
|
||||
# 获取主播的名称
|
||||
# anchor_name = AiUtils.get_navbar_anchor_name(session)
|
||||
@@ -1347,7 +1334,6 @@ class ScriptManager():
|
||||
|
||||
sel = session.xpath("//TextView")
|
||||
if anchor_name not in anchorWithSession:
|
||||
print("没有记忆")
|
||||
|
||||
# 如果是第一次发消息(没有sessionId的情况)
|
||||
LogManager.method_info(f"第一次发消息:{anchor_name},没有记忆 开始请求ai", "检测消息", udid)
|
||||
@@ -1429,14 +1415,15 @@ class ScriptManager():
|
||||
udid)
|
||||
sel.set_text(f"{aiResult or '暂无数据'}\n")
|
||||
|
||||
LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid)
|
||||
event.wait(timeout=1)
|
||||
# 返回
|
||||
ControlUtils.clickBack(session)
|
||||
LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid)
|
||||
event.wait(timeout=1)
|
||||
|
||||
# 重新回到收件箱页面后,强制刷新节点
|
||||
session.appium_settings({"snapshotMaxDepth": 25})
|
||||
event.wait(timeout=1)
|
||||
# 返回
|
||||
ControlUtils.clickBack(session)
|
||||
|
||||
# 重新回到收件箱页面后,强制刷新节点
|
||||
session.appium_settings({"snapshotMaxDepth": 25})
|
||||
event.wait(timeout=1)
|
||||
|
||||
try:
|
||||
# 如果 2 秒内找不到,会抛异常
|
||||
|
||||
Reference in New Issue
Block a user