20250904-初步功能已完成

This commit is contained in:
2025-09-10 16:54:05 +08:00
parent e2e9e0b348
commit f6dda59c9f
5 changed files with 136 additions and 75 deletions

View File

@@ -170,7 +170,8 @@ class ScriptManager():
time.sleep(3)
# 2) 进入直播 (使用英文)
live_button = session(xpath='//XCUIElementTypeButton[@name="直播"]')
live_button = session(
xpath='//XCUIElementTypeButton[@name="直播"] | //XCUIElementTypeOther[@name="直播"]')
if live_button.exists:
live_button.click()
@@ -275,21 +276,19 @@ class ScriptManager():
retries = 0
while not event.is_set():
try:
anchor = AiUtils.pop_aclist_first()
if not anchor:
break
self.greetNewFollowers(udid, needReply, event)
return # 成功执行就退出
except Exception as e:
retries += 1
LogManager.method_error(f"greetNewFollowers 出现异常: {e},准备第 {retries} 次重试", "关注打招呼", udid)
time.sleep(3)
LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
# try:
# anchor = AiUtils.pop_aclist_first()
#
# if not anchor:
# break
self.greetNewFollowers(udid, needReply, event)
# return # 成功执行就退出
# except Exception as e:
# retries += 1
# LogManager.method_error(f"greetNewFollowers 出现异常: {e},准备第 {retries} 次重试", "关注打招呼", udid)
# time.sleep(3)
# LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
# 关注打招呼以及回复主播消息
def greetNewFollowers(self, udid, needReply, event):
@@ -436,18 +435,6 @@ class ScriptManager():
# 向上滑动
session.swipe_down()
# 点击关注按钮
followButton = AiUtils.getFollowButton(session)
if followButton is not None:
LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
followButton.click()
else:
LogManager.method_info("没找到关注按钮", "关注打招呼", udid)
time.sleep(1)
goBack(3)
session.appium_settings({"snapshotMaxDepth": 15})
continue
time.sleep(2)
msgButton = AiUtils.getSendMesageButton(session)
time.sleep(2)
@@ -476,13 +463,12 @@ class ScriptManager():
# 准备打招呼的文案
text = random.choice(ev.prologueList)
# text = 'hello'
LogManager.method_info(f"取出打招呼的数据,{text}, 判断是否需要翻译", "关注打招呼", udid)
isContainChniese = AiUtils.contains_chinese(text)
if isContainChniese:
# 翻译成主播国家的语言
LogManager.method_info(f"需要翻译:{text}, 即将进行翻译", "关注打招呼", udid)
@@ -494,21 +480,37 @@ class ScriptManager():
msg = text
LogManager.method_info(f"即将发送的私信内容:{msg}", "关注打招呼", udid)
# 准备发送一条信息
chatInput.click()
time.sleep(2)
# 发送消息
chatInput.set_text(msg + "\n")
time.sleep(1)
else:
print("无法发送信息")
LogManager.method_info(f"给主播{aid} 发送消息失败", "关注打招呼", udid)
# 接着下一个主播
# removeModelFromAnchorList(anchor)
goBack(1)
# 点击关注按钮
followButton = AiUtils.getFollowButton(session)
if followButton is not None:
LogManager.method_info("找到关注按钮了", "关注打招呼", udid)
followButton.click()
else:
LogManager.method_info("没找到关注按钮", "关注打招呼", udid)
time.sleep(1)
goBack(4)
session.appium_settings({"snapshotMaxDepth": 15})
continue
session.appium_settings({"snapshotMaxDepth": 15})
goBack(4)
goBack(3)
else:
print(f"{aid}:该主播没有视频")
@@ -580,7 +582,13 @@ class ScriptManager():
# 调整节点的深度为 7
session.appium_settings({"snapshotMaxDepth": 7})
el = session(xpath='//XCUIElementTypeButton[@name="a11y_vo_inbox"]')
el = session.xpath(
'//XCUIElementTypeButton[@name="a11y_vo_inbox"]'
' | '
'//XCUIElementTypeButton[contains(@name,"收件箱")]'
' | '
'//XCUIElementTypeButton[.//XCUIElementTypeStaticText[@value="收件箱"]]'
)
# 如果收件箱有消息 则进行点击
if el.exists:
@@ -594,7 +602,14 @@ class ScriptManager():
info_count = 0
# 创建新的会话
el = session(xpath='//XCUIElementTypeButton[@name="a11y_vo_inbox"]')
el = session.xpath(
'//XCUIElementTypeButton[@name="a11y_vo_inbox"]'
' | '
'//XCUIElementTypeButton[contains(@name,"收件箱")]'
' | '
'//XCUIElementTypeButton[.//XCUIElementTypeStaticText[@value="收件箱"]]'
)
print("el", el)
if not el.exists:
LogManager.method_error(f"检测不到收件箱", "检测消息", udid)
@@ -649,11 +664,26 @@ class ScriptManager():
)
# 用户消息
# xp_badge_numeric = (
# '//XCUIElementTypeOther['
# ' @name="AWEIMChatListCellUnreadCountViewComponent"'
# ' or @name="TikTokIMImpl.InboxCellUnreadCountViewBuilder"'
# ']//XCUIElementTypeStaticText[@value and translate(@value,"0123456789","")=""]'
# )
xp_badge_numeric = (
'//XCUIElementTypeOther['
' @name="AWEIMChatListCellUnreadCountViewComponent"'
' or @name="TikTokIMImpl.InboxCellUnreadCountViewBuilder"'
']//XCUIElementTypeStaticText[@value and translate(@value,"0123456789","")=""]'
"("
# 你的两类未读容器组件 + 数字徽标value 纯数字)
"//XCUIElementTypeOther["
" @name='AWEIMChatListCellUnreadCountViewComponent'"
" or @name='TikTokIMImpl.InboxCellUnreadCountViewBuilder'"
"]//XCUIElementTypeStaticText[@value and translate(@value,'0123456789','')='']"
")/ancestor::XCUIElementTypeCell[1]"
" | "
# 兜底:任何在 CollectionView 下、value 纯数字的徽标 → 找其最近的 Cell
"//XCUIElementTypeCollectionView//XCUIElementTypeStaticText"
"[@value and translate(@value,'0123456789','')='']"
"/ancestor::XCUIElementTypeCell[1]"
)
try:
@@ -682,7 +712,7 @@ class ScriptManager():
'Do you think Im one of the most engaging streamers youve seen?']
last_msg = next((item['text'] for item in reversed(msgs) if item['type'] == 'msg'),
random.choice(text_list))
random.choice(text_list))
isLanguage = AiUtils.is_language(last_msg)
if isLanguage: