Skip to content

Commit

Permalink
update 机器人速度大幅度提升
Browse files Browse the repository at this point in the history
  • Loading branch information
尹甲仑 committed Jun 20, 2022
1 parent 097a917 commit 65aafa7
Show file tree
Hide file tree
Showing 14 changed files with 656 additions and 297 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ out/
# Gradle files
.gradle/
build/
release/

# Local configuration file (sdk path, etc)
local.properties
Expand Down
Binary file removed app/release/app-release.apk
Binary file not shown.
20 changes: 0 additions & 20 deletions app/release/output.json

This file was deleted.

9 changes: 9 additions & 0 deletions app/src/main/java/org/yameida/worktool/Demo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ object Demo {
//打印当前视图树
// AccessibilityUtil.printNodeClazzTree(getRoot())

//手机号添加好友
// WeworkOperationImpl.addFriendByPhone(WeworkMessageBean.Friend().apply {
// this.phone = "13010001000"
// this.markName = "hhh"
// this.markCorp = "corp"
// this.markExtra = "ex"
// this.tagList = arrayListOf("tag1", "tag2")
// })

//自动通过好友
// WeworkLoopImpl.getFriendRequest()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public class WeworkMessageBean {
//对象名称(图片、文件、小程序等)
public String objectName;

//添加好友
public Friend friend;

public WeworkMessageBean() {}

public WeworkMessageBean(String receivedName, String receivedContent, int type, Integer roomType, List<String> titleList, List<SubMessageBean> messageList, String log) {
Expand Down Expand Up @@ -224,6 +227,22 @@ public static class MyInfo {
public String job;
}

//添加好友
public static class Friend {
//按手机号搜索
public String phone;
//好友姓名
public String name;
//备注名
public String markName;
//备注企业
public String markCorp;
//备注更多描述
public String markExtra;
//备注标签(推荐)
public List<String> tagList;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
19 changes: 10 additions & 9 deletions app/src/main/java/org/yameida/worktool/service/GlobalMethod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun goHomeTab(title: String): Boolean {
var atHome = false
var find = false
while (!atHome) {
val list = getRoot().findAccessibilityNodeInfosByText("消息")
val list = AccessibilityUtil.findAllByText(getRoot(), "消息", timeout = 0)
for (item in list) {
if (item.parent.parent.parent.childCount == 5) {
//处理侧边栏抽屉打开
Expand All @@ -42,7 +42,7 @@ fun goHomeTab(title: String): Boolean {
}
}
atHome = true
val tempList = getRoot().findAccessibilityNodeInfosByText(title)
val tempList = AccessibilityUtil.findAllByText(getRoot(), title, timeout = 0)
for (tempItem in tempList) {
if (tempItem.parent.parent.parent.childCount == 5) {
AccessibilityUtil.performClick(tempItem)
Expand All @@ -54,7 +54,6 @@ fun goHomeTab(title: String): Boolean {
}
if (!atHome) {
backPress()
sleep(1500)
}
}
LogUtils.v("进入首页-${title}")
Expand All @@ -65,7 +64,7 @@ fun goHomeTab(title: String): Boolean {
* 当前是否在首页
*/
fun isAtHome(): Boolean {
val list = getRoot().findAccessibilityNodeInfosByText("消息")
val list = AccessibilityUtil.findAllByText(getRoot(), "消息", timeout = 0)
return list.count { it.parent.parent.parent.childCount == 5 } > 0
}

Expand Down Expand Up @@ -106,30 +105,32 @@ fun getRoot(ignoreCheck: Boolean): AccessibilityNodeInfo {
* 后退
*/
fun backPress() {
val textView = AccessibilityUtil.findOneByClazz(getRoot(), Views.TextView)
val textView = AccessibilityUtil.findOnceByClazz(getRoot(), Views.TextView)
if (textView != null && textView.text.isNullOrBlank() && AccessibilityUtil.performClick(textView)) {
LogUtils.v("找到回退按钮")
} else {
val ivButton = AccessibilityUtil.findOneByClazz(getRoot(), Views.ImageView)
val ivButton = AccessibilityUtil.findOnceByClazz(getRoot(), Views.ImageView)
if (ivButton != null && ivButton.isClickable && AccessibilityUtil.findFrontNode(ivButton) == null) {
LogUtils.d("未找到回退按钮 点击第一个IV按钮")
AccessibilityUtil.performClick(ivButton)
} else {
LogUtils.d("未找到回退按钮 点击第一个BT按钮")
val button = AccessibilityUtil.findOneByClazz(getRoot(), Views.Button)
val button = AccessibilityUtil.findOnceByClazz(getRoot(), Views.Button)
if (button != null && button.childCount > 0) {
AccessibilityUtil.performClick(button.getChild(0))
} else if (button != null) {
AccessibilityUtil.performClick(button)
} else {
LogUtils.d("未找到BT按钮")
if (AccessibilityUtil.findTextAndClick(getRoot(), "确定")) {
val confirm = AccessibilityUtil.findOnceByText(getRoot(), "确定")
if (confirm != null) {
LogUtils.d("尝试点击确定")
AccessibilityUtil.performClick(confirm)
}
}
}
}
sleep(1000)
sleep(500)
}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/yameida/worktool/service/MyLooper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ object MyLooper {
for (message in LinkedHashSet(messageList.list)) {
getInstance().removeMessages(WeworkMessageBean.LOOP_RECEIVE_NEW_MESSAGE)
if (message.type == WeworkMessageBean.LOOP_RECEIVE_NEW_MESSAGE) {
WeworkController.enableLoopRunning = true
if (!WeworkController.mainLoopRunning) {
getInstance().sendMessage(Message.obtain().apply {
what = WeworkMessageBean.LOOP_RECEIVE_NEW_MESSAGE
Expand Down Expand Up @@ -134,6 +135,7 @@ object MyLooper {
WeworkMessageBean.PASS_ALL_FRIEND_REQUEST -> {
}
WeworkMessageBean.ADD_FRIEND_BY_PHONE -> {
WeworkController.addFriendByPhone(message)
}
WeworkMessageBean.SHOW_GROUP_INFO -> {
WeworkController.showGroupInfo(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.yameida.worktool.model.WeworkMessageBean
object WeworkController {

lateinit var weworkService: WeworkService
var enableLoopRunning = false
var mainLoopRunning = false

/**
Expand All @@ -21,6 +22,7 @@ object WeworkController {
@RequestMapping
fun stopAndGoHome() {
LogUtils.d("stopAndGoHome()")
enableLoopRunning = false
mainLoopRunning = false
goHome()
}
Expand Down Expand Up @@ -60,7 +62,7 @@ object WeworkController {
*/
@RequestMapping
fun replyMessage(message: WeworkMessageBean): Boolean {
LogUtils.d("replyMessage(): ${message.receivedContent}")
LogUtils.d("replyMessage(): ${message.receivedName} ${message.originalContent} ${message.receivedContent}")
return WeworkOperationImpl.replyMessage(
message.titleList,
message.receivedName,
Expand Down Expand Up @@ -214,6 +216,17 @@ object WeworkController {
)
}

/**
* 按手机号添加好友
* @see WeworkMessageBean.ADD_FRIEND_BY_PHONE
* @param message#friend 待添加用户列表
*/
@RequestMapping
fun addFriendByPhone(message: WeworkMessageBean): Boolean {
LogUtils.d("addFriendByPhone(): ${message.friend}")
return WeworkOperationImpl.addFriendByPhone(message.friend)
}

/**
* 展示群信息
* @see WeworkMessageBean.SHOW_GROUP_INFO
Expand Down
34 changes: 24 additions & 10 deletions app/src/main/java/org/yameida/worktool/service/WeworkGetImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object WeworkGetImpl {
if (!goHomeTab("")) {
LogUtils.d("未找到我的信息")
goHomeTab("消息")
val firstTv = AccessibilityUtil.findAllByClazz(getRoot(), Views.TextView)
val firstTv = AccessibilityUtil.findAllByClazz(getRoot(), Views.TextView, root = true)
.firstOrNull { it.text == null }
AccessibilityUtil.performClick(firstTv)
sleep(1000)
Expand All @@ -67,11 +67,10 @@ object WeworkGetImpl {
}
}
AccessibilityUtil.performClick(AccessibilityUtil.findOneByClazz(getRoot(), Views.ImageView))
sleep(1500)
val relativeLayoutList = AccessibilityUtil.findAllByClazz(getRoot(), Views.RelativeLayout)
val relativeLayoutList = AccessibilityUtil.findAllByClazz(getRoot(), Views.RelativeLayout, minSize = 70)
val myInfo = WeworkMessageBean.MyInfo()
for (relativeLayout in relativeLayoutList.filter { it.childCount >= 2 }) {
val textViewList = AccessibilityUtil.findAllByClazz(relativeLayout, Views.TextView)
val textViewList = AccessibilityUtil.findAllOnceByClazz(relativeLayout, Views.TextView)
if (textViewList.size >= 2) {
val firstText = textViewList[0].text?.toString()
if (firstText == "姓名" && myInfo.name == null) {
Expand Down Expand Up @@ -105,6 +104,7 @@ object WeworkGetImpl {
weworkMessageBean.type = WeworkMessageBean.GET_MY_INFO
weworkMessageBean.myInfo = myInfo
WeworkController.weworkService.webSocketManager.send(weworkMessageBean)
WeworkLoopImpl.startLoop()
return true
}

Expand All @@ -114,30 +114,44 @@ object WeworkGetImpl {
fun getGroupInfoDetail(): WeworkMessageBean {
val weworkMessageBean = WeworkMessageBean()
weworkMessageBean.type = WeworkMessageBean.GET_GROUP_INFO
val tvManagerFlag =
AccessibilityUtil.findOneByText(getRoot(), "微信用户创建")
val tvManagerFlag = AccessibilityUtil.findOneByText(getRoot(), "微信用户创建", timeout = 2000)
//不是管理员的群可能没有微信用户创建 todo
// AccessibilityUtil.findOneByText(getRoot(), "全部群成员", timeout = 2000)
val button = AccessibilityUtil.findFrontNode(tvManagerFlag)
val tvGroupName = AccessibilityUtil.findOneByClazz(button, Views.TextView)
val tvGroupName = AccessibilityUtil.findOnceByClazz(button, Views.TextView)
if (tvGroupName != null && tvGroupName.text != null) {
LogUtils.d("群名: " + tvGroupName.text)
weworkMessageBean.groupName = tvGroupName.text.toString()
} else {
val groupNameTv = AccessibilityUtil.findOnceByText(getRoot(), "群聊名称")
if (groupNameTv != null) {
val tvList = AccessibilityUtil.findAllOnceByClazz(
groupNameTv.parent.parent.parent,
Views.TextView
)
if (tvList.size >= 2) {
val groupName = tvList[1]
LogUtils.d("群名: " + groupName.text)
weworkMessageBean.groupName = groupName.text.toString()
}
}
}
val gridView = AccessibilityUtil.findOneByClazz(getRoot(), Views.GridView)
if (gridView != null && gridView.childCount >= 2) {
val tvOwnerName = AccessibilityUtil.findOneByClazz(gridView.getChild(0), Views.TextView)
val tvOwnerName = AccessibilityUtil.findOnceByClazz(gridView.getChild(0), Views.TextView)
if (tvOwnerName != null && tvOwnerName.text != null) {
LogUtils.d("群主: " + tvOwnerName.text)
weworkMessageBean.groupOwner = tvOwnerName.text.toString()
}
}
val tvCountFlag = AccessibilityUtil.findOneByText(getRoot(), "查看全部群成员")
val tvCountFlag = AccessibilityUtil.findOnceByText(getRoot(), "查看全部群成员")
val tvCount = AccessibilityUtil.findBackNode(tvCountFlag)
if (tvCount != null && tvCount.text != null) {
LogUtils.d("群成员: " + tvCount.text)
val count = tvCount.text.toString().replace("", "")
weworkMessageBean.groupNumber = count.toIntOrNull()
}
val tvAnnouncementFlag = AccessibilityUtil.findOneByText(getRoot(), "群公告")
val tvAnnouncementFlag = AccessibilityUtil.findOnceByText(getRoot(), "群公告")
val tvAnnouncement = AccessibilityUtil.findBackNode(tvAnnouncementFlag)
if (tvAnnouncement != null && tvAnnouncement.text != null) {
LogUtils.d("群公告: " + tvAnnouncement.text)
Expand Down
Loading

0 comments on commit 65aafa7

Please sign in to comment.