update 消息发送优化和准确率提升

This commit is contained in:
gallonyin
2023-10-15 22:27:20 +08:00
parent 42020c9c3b
commit 3dad4772a5
4 changed files with 26 additions and 12 deletions

View File

@@ -28,7 +28,7 @@ object Constant {
val wssRegex = "^wss".toRegex()
val wsRegex = "^ws".toRegex()
val suffixString = "(-.*)?(…)?(\\(\\d+\\))?$"
val suffixRegex = "(-.*)?(…)?(\\(\\d+\\))?$"
val suffixRegex = "(-.*)?(…)?(\\(\\d+\\))?$".toRegex()
val digitalRegex = "\\(\\d+\\)\$".toRegex()
var weworkCorpName: String
get() = SPUtils.getInstance().getString("weworkCorpName", "")

View File

@@ -159,12 +159,11 @@ object WeworkLoopImpl {
* @param needInfer 是否需要推断@me并等待回复
* @param timeout 在房间内等待回复的时长
*/
fun getChatMessageList(needInfer: Boolean = !Constant.pushImage, imageCheck: Boolean = true, timeout: Long = 5000, titleList: ArrayList<String>? = null, sendMessageBefore: Boolean = false): Boolean {
fun getChatMessageList(needInfer: Boolean = !Constant.pushImage, imageCheck: Boolean = true, timeout: Long = 5000, titleList: ArrayList<String>? = null): Boolean {
if (Constant.autoReply == 0) return true
val roomType = WeworkRoomUtil.getRoomType()
var titleList = titleList ?: WeworkRoomUtil.getRoomTitle()
if (!sendMessageBefore && titleList.count { it.endsWith("") } > 0) {
LogUtils.e(java.lang.NullPointerException())
if (titleList.count { it.endsWith("") } > 0) {
LogUtils.d("title too long... try get full name titleList: ${titleList.joinToString()}")
if (roomType == WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT || roomType == WeworkMessageBean.ROOM_TYPE_EXTERNAL_CONTACT) {
titleList = WeworkRoomUtil.getFriendName()
@@ -328,8 +327,6 @@ object WeworkLoopImpl {
else -> return true
}
}
} else if (!sendMessageBefore) {
goHome()
}
return true
} else {

View File

@@ -2799,8 +2799,24 @@ object WeworkOperationImpl {
/**
* 发送消息+@at
*/
private fun sendChatMessage(text: String, at: String? = null, atList: List<String>? = null, reply: Boolean? = false, title: String? = null): Boolean {
private fun sendChatMessage(text: String, at: String? = null, atList: List<String>? = null, reply: Boolean? = false, title: String): Boolean {
val roomType = WeworkRoomUtil.getRoomType()
var titleList = arrayListOf(title) ?: WeworkRoomUtil.getRoomTitle()
if (titleList.count { it.endsWith("") } > 0) {
LogUtils.d("title too long... try get full name titleList: ${titleList.joinToString()}")
if (roomType == WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT || roomType == WeworkMessageBean.ROOM_TYPE_EXTERNAL_CONTACT) {
titleList = WeworkRoomUtil.getFriendName()
} else if (Constant.fullGroupName
&& (roomType == WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP || roomType == WeworkMessageBean.ROOM_TYPE_EXTERNAL_GROUP)) {
titleList = WeworkRoomUtil.getFullGroupTitle()
}
}
AccessibilityExtraUtil.loadingPage("ExternalGroupMessageListActivity", "ExternalWechatUserMessageListActivity", "MessageListActivity")
if (roomType == WeworkMessageBean.ROOM_TYPE_UNKNOWN || titleList.size == 0) {
LogUtils.e("非聊天房间 无法发送消息")
error("非聊天房间 无法发送消息")
return false
}
val voiceFlag = AccessibilityUtil.findOnceByText(getRoot(), "按住 说话", "按住说话", exact = true)
if (voiceFlag != null) {
AccessibilityUtil.performClickWithSon(AccessibilityUtil.findFrontNode(voiceFlag))
@@ -2892,7 +2908,7 @@ object WeworkOperationImpl {
LogUtils.v("atFailed: $atFailed")
val content = if (atFailed) "@${atList?.joinToString()} $text" else text
val append = (reply == true) || (!atList.isNullOrEmpty() && !atFailed)
WeworkLoopImpl.getChatMessageList(needInfer = false, imageCheck = false, sendMessageBefore = true)
WeworkLoopImpl.getChatMessageList(needInfer = false, imageCheck = false, titleList = titleList)
if (AccessibilityUtil.findTextInput(getRoot(), content, append = append)) {
AccessibilityUtil.findOneByText(getRoot(), "发送", exact = true, timeout = 2000)
val sendButton = AccessibilityUtil.findAllByClazz(getRoot(), Views.Button)
@@ -2902,7 +2918,8 @@ object WeworkOperationImpl {
log("发送消息: \n$content")
AccessibilityUtil.performClick(sendButton)
sleep(Constant.POP_WINDOW_INTERVAL)
WeworkLoopImpl.getChatMessageList(needInfer = false)
WeworkLoopImpl.getChatMessageList(needInfer = false, titleList = titleList)
goHome()
return true
} else {
LogUtils.e("未找到发送按钮")

View File

@@ -275,7 +275,7 @@ object WeworkRoomUtil {
* 检查当前房间
*/
private fun checkRoom(title: String, strict: Boolean = false): Boolean {
LogUtils.d("checkRoom(): $title")
LogUtils.d("checkRoom(): $title strict: $strict")
var titleList = getRoomTitle(print = false)
if (titleList.isEmpty()) {
return false
@@ -291,10 +291,10 @@ object WeworkRoomUtil {
}
}
val dealTitle = title.replace(Constant.suffixRegex, "")
LogUtils.v("dealTitle: $dealTitle", "titleList: ${titleList.joinToString()}")
LogUtils.d("dealTitle: $dealTitle", "titleList: ${titleList.joinToString()}")
if (roomType != WeworkMessageBean.ROOM_TYPE_UNKNOWN
&& (titleList.count { dealTitle == it.replace(Constant.suffixRegex, "") } > 0
|| (!strict && titleList.count { dealTitle.contains(it.replace(Constant.suffixRegex, "")) } > 0))
|| ((!strict || !Constant.fullGroupName) && titleList.count { dealTitle.contains(it.replace(Constant.suffixRegex, "")) } > 0))
) {
intoRoomPreInit()
LogUtils.d("当前正在房间")