update 合并转发

This commit is contained in:
gallonyin
2023-04-03 23:44:51 +08:00
parent 4d06dc0b34
commit 939bf7c022
2 changed files with 66 additions and 45 deletions

View File

@@ -180,13 +180,17 @@ object WeworkOperationImpl {
LogUtils.d("开始转发") LogUtils.d("开始转发")
if (relaySelectTarget(nameList, extraText)) { if (relaySelectTarget(nameList, extraText)) {
LogUtils.d("$title: 转发成功") LogUtils.d("$title: 转发成功")
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "$title: 转发成功", startTime, titleList, listOf())
return true
} else { } else {
LogUtils.e("$title: 转发失败") LogUtils.d("$title: 转发失败 $originalContent")
error("$title: 转发失败 $originalContent") uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "$title: 转发失败 $originalContent", startTime, listOf(), titleList)
return false
} }
} else { } else {
LogUtils.e("$title: 长按条目失败") LogUtils.e("$title: 长按条目失败 $originalContent")
error("$title: 长按条目失败 $originalContent") uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "$title: 长按条目失败 $originalContent", startTime, listOf(), titleList)
return false
} }
} else { } else {
if (WeworkTextUtil.longClickMyMessageItem( if (WeworkTextUtil.longClickMyMessageItem(
@@ -200,13 +204,17 @@ object WeworkOperationImpl {
LogUtils.d("开始转发") LogUtils.d("开始转发")
if (relaySelectTarget(nameList, extraText)) { if (relaySelectTarget(nameList, extraText)) {
LogUtils.d("$title: 转发成功") LogUtils.d("$title: 转发成功")
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "$title: 转发成功", startTime, titleList, listOf())
return true
} else { } else {
LogUtils.d("$title: 转发失败") LogUtils.d("$title: 转发失败 $originalContent")
error("$title: 转发失败 $originalContent") uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "$title: 转发失败 $originalContent", startTime, listOf(), titleList)
return false
} }
} else { } else {
LogUtils.e("$title: 长按条目失败") LogUtils.e("$title: 长按条目失败 $originalContent")
error("$title: 长按条目失败 $originalContent") uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "$title: 长按条目失败 $originalContent", startTime, listOf(), titleList)
return false
} }
} }
} else { } else {
@@ -214,7 +222,9 @@ object WeworkOperationImpl {
error("$title: 转发失败 $originalContent") error("$title: 转发失败 $originalContent")
} }
} }
return true LogUtils.d("转发失败 未找到房间名")
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "转发失败 未找到房间名", startTime, listOf(), titleList)
return false
} }
/** /**
@@ -519,25 +529,6 @@ object WeworkOperationImpl {
extraText: String? = null extraText: String? = null
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
goHomeTab("工作台")
val node = AccessibilityUtil.scrollAndFindByText(WeworkController.weworkService, getRoot(), "用过的小程序")
if (node != null) {
AccessibilityUtil.performClick(node)
sleep(Constant.CHANGE_PAGE_INTERVAL)
val textViewList = AccessibilityUtil.findAllByClazz(getRoot(), Views.TextView)
if (textViewList.size > 3) {
AccessibilityUtil.performClick(textViewList[2])
AccessibilityUtil.findTextInput(getRoot(), objectName)
AccessibilityUtil.findOneByClazz(getRoot(), Views.RecyclerView)
sleep(2000)
//todo 转发小程序
return true
} else {
LogUtils.e("未找到小程序内搜索")
}
} else {
LogUtils.e("未找到小程序")
}
return false return false
} }
@@ -885,7 +876,6 @@ object WeworkOperationImpl {
return false return false
} else if (messageList.size == 1) { } else if (messageList.size == 1) {
val subMessageBean = messageList.first() val subMessageBean = messageList.first()
//todo 检查receivedName异常场景
val receivedName = subMessageBean.nameList?.firstOrNull() val receivedName = subMessageBean.nameList?.firstOrNull()
val textType = subMessageBean.textType val textType = subMessageBean.textType
val originalContent = subMessageBean.itemMessageList?.firstOrNull()?.text ?: "" val originalContent = subMessageBean.itemMessageList?.firstOrNull()?.text ?: ""
@@ -896,7 +886,6 @@ object WeworkOperationImpl {
if (WeworkRoomUtil.intoRoom(title)) { if (WeworkRoomUtil.intoRoom(title)) {
var hasOpenMulti = false var hasOpenMulti = false
for (subMessageBean in messageList) { for (subMessageBean in messageList) {
//todo 检查receivedName异常场景
val receivedName = subMessageBean.nameList?.firstOrNull() val receivedName = subMessageBean.nameList?.firstOrNull()
val textType = subMessageBean.textType val textType = subMessageBean.textType
val originalContent = subMessageBean.itemMessageList?.firstOrNull()?.text ?: "" val originalContent = subMessageBean.itemMessageList?.firstOrNull()?.text ?: ""
@@ -948,8 +937,8 @@ object WeworkOperationImpl {
) )
) { ) {
LogUtils.d("单击成功 $originalContent") LogUtils.d("单击成功 $originalContent")
sleep(3000)
hasOpenMulti = true hasOpenMulti = true
sleep(Constant.POP_WINDOW_INTERVAL / 2)
} else { } else {
LogUtils.e("$title: 单击失败") LogUtils.e("$title: 单击失败")
error("$title: 单击失败 $originalContent") error("$title: 单击失败 $originalContent")
@@ -964,8 +953,8 @@ object WeworkOperationImpl {
) )
) { ) {
LogUtils.d("单击成功 $originalContent") LogUtils.d("单击成功 $originalContent")
sleep(3000)
hasOpenMulti = true hasOpenMulti = true
sleep(Constant.POP_WINDOW_INTERVAL / 2)
} else { } else {
LogUtils.e("$title: 单击失败") LogUtils.e("$title: 单击失败")
error("$title: 单击失败 $originalContent") error("$title: 单击失败 $originalContent")
@@ -979,25 +968,33 @@ object WeworkOperationImpl {
if (AccessibilityUtil.findTextAndClick(getRoot(), key)) { if (AccessibilityUtil.findTextAndClick(getRoot(), key)) {
if (relaySelectTarget(nameList, extraText)) { if (relaySelectTarget(nameList, extraText)) {
LogUtils.d("$title: 转发成功") LogUtils.d("$title: 转发成功")
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "$title: 转发成功", startTime, titleList, listOf())
return true
} else { } else {
LogUtils.e("$title: 转发失败") LogUtils.e("$title: 转发失败")
error("$title: 转发失败") uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "$title: 转发失败", startTime, listOf(), titleList)
return false
} }
} else { } else {
LogUtils.e("未找到逐条转发按钮") LogUtils.e("未找到逐条转发按钮")
error("未找到逐条转发按钮") uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到逐条转发按钮", startTime, listOf(), titleList)
return false
} }
} else { } else {
LogUtils.e("未找到转发按钮") LogUtils.e("未找到转发按钮")
error("未找到转发按钮") uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到转发按钮", startTime, listOf(), titleList)
return false
} }
} }
} else { } else {
LogUtils.d("$title: 转发失败 未找到房间") LogUtils.d("$title: 转发失败 未找到房间")
error("$title: 转发失败 未找到房间") uploadCommandResult(message, ExecCallbackBean.ERROR_INTO_ROOM, "$title: 转发失败 未找到房间", startTime, listOf(), titleList)
return false
} }
} }
return true LogUtils.d("转发失败 未找到房间名")
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "转发失败 未找到房间名", startTime, listOf(), titleList)
return false
} }
/** /**
@@ -1649,7 +1646,7 @@ object WeworkOperationImpl {
AccessibilityUtil.findTextInput(getRoot(), groupName) AccessibilityUtil.findTextInput(getRoot(), groupName)
val confirmButton = AccessibilityUtil.findOneByText(getRoot(), "确定") val confirmButton = AccessibilityUtil.findOneByText(getRoot(), "确定")
AccessibilityUtil.performClick(confirmButton) AccessibilityUtil.performClick(confirmButton)
sleep(2000) sleep(Constant.CHANGE_PAGE_INTERVAL * 2)
return true return true
} else { } else {
LogUtils.e("未找到填写群名按钮") LogUtils.e("未找到填写群名按钮")
@@ -1661,7 +1658,7 @@ object WeworkOperationImpl {
AccessibilityUtil.findTextInput(getRoot(), groupName) AccessibilityUtil.findTextInput(getRoot(), groupName)
val confirmButton = AccessibilityUtil.findOneByText(getRoot(), "确定") val confirmButton = AccessibilityUtil.findOneByText(getRoot(), "确定")
AccessibilityUtil.performClick(confirmButton) AccessibilityUtil.performClick(confirmButton)
sleep(2000) sleep(Constant.CHANGE_PAGE_INTERVAL * 2)
return true return true
} else { } else {
LogUtils.e("未找到群聊名称按钮") LogUtils.e("未找到群聊名称按钮")
@@ -1920,7 +1917,7 @@ object WeworkOperationImpl {
if (publishButtonList.size >= 2) { if (publishButtonList.size >= 2) {
AccessibilityUtil.performClick(publishButtonList[1]) AccessibilityUtil.performClick(publishButtonList[1])
} }
sleep(3000) sleep(Constant.CHANGE_PAGE_INTERVAL * 3)
} else { } else {
LogUtils.e("无法进行群公告发布") LogUtils.e("无法进行群公告发布")
} }

View File

@@ -271,7 +271,7 @@ object WeworkTextUtil {
//消息主体 //消息主体
val relativeLayoutItem = AccessibilityUtil.findOnceByClazz(node, Views.RelativeLayout, limitDepth = 1) val relativeLayoutItem = AccessibilityUtil.findOnceByClazz(node, Views.RelativeLayout, limitDepth = 1)
if (relativeLayoutItem != null && relativeLayoutItem.childCount >= 2) { if (relativeLayoutItem != null && relativeLayoutItem.childCount >= 2) {
if (Views.ImageView.equals(relativeLayoutItem.getChild(0).className)) { if (Views.ImageView.equals(relativeLayoutItem.getChild(relativeLayoutItem.childCount - 2).className)) {
LogUtils.v("头像在左边 本条消息发送者为其他联系人") LogUtils.v("头像在左边 本条消息发送者为其他联系人")
var textType = WeworkMessageBean.TEXT_TYPE_UNKNOWN var textType = WeworkMessageBean.TEXT_TYPE_UNKNOWN
val relativeLayoutContent = val relativeLayoutContent =
@@ -281,10 +281,10 @@ object WeworkTextUtil {
LogUtils.v("textType: $textType") LogUtils.v("textType: $textType")
return textType return textType
} }
} else if (Views.ImageView.equals(relativeLayoutItem.getChild(1).className)) { } else if (Views.ImageView.equals(relativeLayoutItem.getChild(relativeLayoutItem.childCount - 1).className)) {
LogUtils.v("头像在右边 本条消息发送者为自己") LogUtils.v("头像在右边 本条消息发送者为自己")
var textType = WeworkMessageBean.TEXT_TYPE_UNKNOWN var textType = WeworkMessageBean.TEXT_TYPE_UNKNOWN
val subLayout = relativeLayoutItem.getChild(0) val subLayout = relativeLayoutItem.getChild(relativeLayoutItem.childCount - 2)
if (subLayout.childCount > 0) { if (subLayout.childCount > 0) {
textType = WeworkTextUtil.getTextType(subLayout) textType = WeworkTextUtil.getTextType(subLayout)
LogUtils.v("textType: $textType") LogUtils.v("textType: $textType")
@@ -295,6 +295,24 @@ object WeworkTextUtil {
return WeworkMessageBean.TEXT_TYPE_UNKNOWN return WeworkMessageBean.TEXT_TYPE_UNKNOWN
} }
/**
* 企微消息 发送者
* sender 0其他人 1机器人自己 2unknown(如系统消息)
*/
private fun getSender(node: AccessibilityNodeInfo?, isGroup: Boolean = true): Int {
if (node == null) return WeworkMessageBean.TEXT_TYPE_UNKNOWN
//消息主体
val relativeLayoutItem = AccessibilityUtil.findOnceByClazz(node, Views.RelativeLayout, limitDepth = 1)
if (relativeLayoutItem != null && relativeLayoutItem.childCount >= 2) {
if (Views.ImageView.equals(relativeLayoutItem.getChild(0).className)) {
return 0
} else if (Views.ImageView.equals(relativeLayoutItem.getChild(1).className)) {
return 1
}
}
return 2
}
/** /**
* 是否为消息上方时间 * 是否为消息上方时间
*/ */
@@ -360,8 +378,13 @@ object WeworkTextUtil {
if (nameList.isEmpty()) { if (nameList.isEmpty()) {
val backNode = getMessageListNode(item, WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT) val backNode = getMessageListNode(item, WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT)
if (backNode != null) { if (backNode != null) {
val textTypeFromItem = getTextTypeFromItem(item)
val sender = getSender(item)
if ((replyNick != null && sender == 1) || (replyNick == null && sender == 0)) {
continue
}
if ((replyTextType == WeworkMessageBean.TEXT_TYPE_IMAGE) if ((replyTextType == WeworkMessageBean.TEXT_TYPE_IMAGE)
&& (replyTextType == getTextTypeFromItem(item))) { && (replyTextType == textTypeFromItem)) {
LogUtils.d("nameList: $nameList\nreplyContent: $replyContent") LogUtils.d("nameList: $nameList\nreplyContent: $replyContent")
return longClickMessageItem(item, WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT, key) return longClickMessageItem(item, WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT, key)
} }
@@ -385,8 +408,9 @@ object WeworkTextUtil {
if (name == replyNick) { if (name == replyNick) {
val backNode = getMessageListNode(item, WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP) val backNode = getMessageListNode(item, WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP)
if (backNode != null) { if (backNode != null) {
val textTypeFromItem = getTextTypeFromItem(item)
if ((replyTextType == WeworkMessageBean.TEXT_TYPE_IMAGE) if ((replyTextType == WeworkMessageBean.TEXT_TYPE_IMAGE)
&& (replyTextType == getTextTypeFromItem(item))) { && (replyTextType == textTypeFromItem)) {
LogUtils.d("nameList: $nameList\nreplyContent: $replyContent") LogUtils.d("nameList: $nameList\nreplyContent: $replyContent")
return longClickMessageItem(item, WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP, key) return longClickMessageItem(item, WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP, key)
} }