支持修改已添加的主播以及自定义打招呼信息
This commit is contained in:
119
Utils/AiUtils.py
119
Utils/AiUtils.py
@@ -294,110 +294,6 @@ class AiUtils(object):
|
||||
print(f"btn:{btn}")
|
||||
return cls.findNumber(btn.label)
|
||||
|
||||
# 获取聊天页面的聊天信息
|
||||
# @classmethod
|
||||
# def extract_messages_from_xml(cls, xml: str):
|
||||
# """
|
||||
# 仅返回当前屏幕中“可见的”聊天内容(含时间分隔)
|
||||
# """
|
||||
# from lxml import etree
|
||||
# root = etree.fromstring(xml.encode("utf-8"))
|
||||
# items = []
|
||||
#
|
||||
# # 判断是否是聊天页面
|
||||
# is_chat_page = False
|
||||
# if root.xpath('//XCUIElementTypeStaticText[contains(@traits, "Header")]'):
|
||||
# is_chat_page = True
|
||||
# elif root.xpath('//XCUIElementTypeCell//XCUIElementTypeOther[@name or @label]'):
|
||||
# is_chat_page = True
|
||||
#
|
||||
# if not is_chat_page:
|
||||
# raise Exception("请先进入聊天页面")
|
||||
#
|
||||
# # 屏幕宽度
|
||||
# app = root.xpath('/XCUIElementTypeApplication')
|
||||
#
|
||||
# screen_w = cls.parse_float(app[0], 'width', 414.0) if app else 414.0
|
||||
#
|
||||
# # 找 Table 的可见范围
|
||||
# table = root.xpath('//XCUIElementTypeTable')
|
||||
# if table:
|
||||
# table = table[0]
|
||||
# table_top = cls.parse_float(table, 'y', 0.0)
|
||||
# table_h = cls.parse_float(table, 'height', 0.0)
|
||||
# table_bottom = table_top + table_h
|
||||
# else:
|
||||
# table_top, table_bottom = 0.0, cls.parse_float(app[0], 'height', 736.0) if app else 736.0
|
||||
#
|
||||
# def in_view(el) -> bool:
|
||||
# """元素在聊天区内并且可见"""
|
||||
# if el.get('visible') != 'true':
|
||||
# return False
|
||||
# y = cls.parse_float(el, 'y', -1e9)
|
||||
# h = cls.parse_float(el, 'height', 0.0)
|
||||
# by = y + h
|
||||
# return not (by <= table_top or y >= table_bottom)
|
||||
#
|
||||
# # 时间分隔
|
||||
# for t in root.xpath('//XCUIElementTypeStaticText[contains(@traits, "Header")]'):
|
||||
# if not in_view(t):
|
||||
# continue
|
||||
# txt = (t.get('label') or t.get('name') or t.get('value') or '').strip()
|
||||
# if txt:
|
||||
# items.append({'type': 'time', 'text': txt, 'y': cls.parse_float(t, 'y')})
|
||||
#
|
||||
# # 消息气泡
|
||||
# EXCLUDES = {'Heart', 'Lol', 'ThumbsUp', '分享发布内容', '视频贴纸标签页', '双击发送表情'}
|
||||
#
|
||||
# msg_nodes = table.xpath(
|
||||
# './/XCUIElementTypeCell[@visible="true"]'
|
||||
# '//XCUIElementTypeOther[@visible="true" and (@name or @label) and not(ancestor::XCUIElementTypeCollectionView)]'
|
||||
# ) if table is not None else []
|
||||
#
|
||||
# for o in msg_nodes:
|
||||
# text = (o.get('label') or o.get('name') or '').strip()
|
||||
# if not text or text in EXCLUDES:
|
||||
# continue
|
||||
# if not in_view(o):
|
||||
# continue
|
||||
#
|
||||
# # 找所在 Cell
|
||||
# cell = o.getparent()
|
||||
# while cell is not None and cell.get('type') != 'XCUIElementTypeCell':
|
||||
# cell = cell.getparent()
|
||||
#
|
||||
# x = cls.parse_float(o, 'x')
|
||||
# y = cls.parse_float(o, 'y')
|
||||
# w = cls.parse_float(o, 'width')
|
||||
# right_edge = x + w
|
||||
#
|
||||
# direction = None
|
||||
# # 头像位置判定
|
||||
# if cell is not None:
|
||||
# avatar_btns = cell.xpath(
|
||||
# './/XCUIElementTypeButton[@visible="true" and (@name="图片头像" or @label="图片头像")]')
|
||||
# if avatar_btns:
|
||||
# ax = cls.parse_float(avatar_btns[0], 'x')
|
||||
# direction = 'in' if ax < (screen_w / 2) else 'out'
|
||||
# # 右对齐兜底
|
||||
# if direction is None:
|
||||
# direction = 'out' if right_edge > (screen_w - 20) else 'in'
|
||||
#
|
||||
# items.append({'type': 'msg', 'dir': direction, 'text': text, 'y': y})
|
||||
#
|
||||
# # 排序 & 清理
|
||||
# items.sort(key=lambda i: i['y'])
|
||||
# for it in items:
|
||||
# it.pop('y', None)
|
||||
# return items
|
||||
#
|
||||
# @classmethod
|
||||
# def parse_float(cls, el, attr, default=0.0):
|
||||
# try:
|
||||
# return float(el.get(attr, default))
|
||||
# except Exception:
|
||||
# return default
|
||||
|
||||
@classmethod
|
||||
def extract_messages_from_xml(cls, xml: str):
|
||||
"""
|
||||
@@ -572,4 +468,17 @@ class AiUtils(object):
|
||||
|
||||
return ""
|
||||
|
||||
# AiUtils.getCurrentScreenSource()
|
||||
# 检查字符串中是否包含中文
|
||||
@classmethod
|
||||
def contains_chinese(cls, text):
|
||||
"""
|
||||
判断字符串中是否包含中文字符。
|
||||
参数:
|
||||
text (str): 要检测的字符串。
|
||||
|
||||
返回:
|
||||
bool: 如果字符串中包含中文,返回 True;否则返回 False。
|
||||
"""
|
||||
# 使用正则表达式匹配中文字符
|
||||
pattern = re.compile(r'[\u4e00-\u9fff]')
|
||||
return bool(pattern.search(text))
|
||||
|
||||
Reference in New Issue
Block a user