termux+python+uiautomator2实现soul无限循环检测指定成员并对其进行封麦+禁言处理

termux+python+uiautomator2实现soul无限循环检测指定成员并对其进行封麦+禁言处理

代码实现

只需要修改要匹配的用户名字就行,名字由双引号括着:if d(descriptionContains="行一+一").exists() or d(textContains="行一+一").exists():

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import re
import time
import uiautomator2 as u2

connect=os.system('adb devices | grep -w "device" | awk \'{print $1}\'')
d = u2.connect(connect)

element = d(resourceId="cn.soulapp.android:id/tvUserCount")
if element.exists():
    text = element.get_text()  # 获取元素文本,如 "粉丝数:12345"
    # print(text)
    numbers=re.findall(r'\d+', text)
    if numbers:
        number = int(numbers[0])  # 取第一个匹配项
        # print("提取到的数字:", number)
    else:
        print("文本中无数字")
else:
    print("未找到 tvUserCount 元素")    

while True:
    for i in range(number-1):
        xpath = f'//*[@resource-id="cn.soulapp.android:id/rvUser"]/android.widget.FrameLayout[{i+1}]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.ImageView[1]'          
        d.xpath(xpath).click()        
        if d(descriptionContains="行一+一").exists() or d(textContains="行一+一").exists():
            print("文本存在(模糊匹配)")
            if d(text="封麦").exists:
                d(text="封麦").click()
            if d(text="取消封麦").exists:
                d(text="取消封麦").click()
                
            # time.sleep(1)            
            d(resourceId="cn.soulapp.android:id/iv_user_more").click()
            time.sleep(1)
            
            if d(text="禁止发言").exists:
                d(text="禁止发言").click()
            if d(text="取消禁言").exists:
                d(text="取消禁言").click()
        else:
            print("文本不存在")        
            d.press("back")
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计