合并代码。临时上传
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, List
|
||||
import tidevice
|
||||
import usb
|
||||
import wda
|
||||
from tidevice import Usbmux, ConnectionType
|
||||
from tidevice._device import BaseDevice
|
||||
@@ -40,6 +38,7 @@ class DeviceInfo:
|
||||
orphan_gc_tick = 0
|
||||
while True:
|
||||
online = {d.udid for d in Usbmux().device_list() if d.conn_type == ConnectionType.USB}
|
||||
|
||||
# 拔掉——同步
|
||||
for udid in list(self._models):
|
||||
if udid not in online:
|
||||
@@ -123,7 +122,9 @@ class DeviceInfo:
|
||||
args=(udid,)
|
||||
).start()
|
||||
else:
|
||||
print("准备启动wda")
|
||||
dev.app_start(WdaAppBundleId)
|
||||
print("启动wda完成")
|
||||
print("启动wda成功")
|
||||
time.sleep(3)
|
||||
return True
|
||||
@@ -137,12 +138,12 @@ class DeviceInfo:
|
||||
c.home()
|
||||
size = c.window_size()
|
||||
scale = c.scale
|
||||
print("已获取到屏幕大小信息")
|
||||
return int(size.width), int(size.height), float(scale)
|
||||
except Exception as e:
|
||||
print("获取设备信息遇到错误:", e)
|
||||
return 0, 0, 0
|
||||
|
||||
...
|
||||
# ---------------- 原来代码不变,只替换下面一个函数 ----------------
|
||||
def _start_iproxy(self, udid: str, port: int) -> Optional[subprocess.Popen]:
|
||||
try:
|
||||
|
||||
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
from queue import Queue
|
||||
from typing import Any, Dict
|
||||
|
||||
from Entity import Variables
|
||||
from Utils.AiUtils import AiUtils
|
||||
from Utils.IOSAIStorage import IOSAIStorage
|
||||
from Utils.LogManager import LogManager
|
||||
@@ -247,6 +248,7 @@ def longPressAction():
|
||||
def growAccount():
|
||||
body = request.get_json()
|
||||
udid = body.get("udid")
|
||||
Variables.commentList = body.get("comment")
|
||||
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
@@ -286,16 +288,25 @@ def passAnchorData():
|
||||
try:
|
||||
LogManager.method_info("关注打招呼", "关注打招呼")
|
||||
data: Dict[str, Any] = request.get_json()
|
||||
|
||||
# 设备列表
|
||||
idList = data.get("deviceList", [])
|
||||
|
||||
# 主播列表
|
||||
acList = data.get("anchorList", [])
|
||||
Variables.commentList = data.get("comment")
|
||||
|
||||
|
||||
LogManager.info(f"[INFO] 获取数据: {idList} {acList}")
|
||||
|
||||
AiUtils.save_aclist_flat_append(acList)
|
||||
|
||||
# 是否需要回复
|
||||
needReply = data.get("needReply", True)
|
||||
needReply = data.get("needReply", False)
|
||||
|
||||
# 是否需要进行翻译
|
||||
needTranslate = data.get("needTranslate", True)
|
||||
|
||||
# 获取打招呼数据
|
||||
ev.prologueList = data.get("prologueList", [])
|
||||
|
||||
@@ -306,7 +317,8 @@ def passAnchorData():
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
# 启动脚本
|
||||
thread = threading.Thread(target=manager.safe_greetNewFollowers, args=(udid, needReply, event))
|
||||
thread = threading.Thread(target=manager.safe_greetNewFollowers,
|
||||
args=(udid, needReply, needTranslate, event))
|
||||
# 添加到线程管理
|
||||
ThreadManager.add(udid, thread, event)
|
||||
return ResultData(data="").toJson()
|
||||
@@ -330,6 +342,10 @@ def followAndGreetUnion():
|
||||
|
||||
# 是否需要回复
|
||||
needReply = data.get("needReply", True)
|
||||
|
||||
# 是否需要进行翻译
|
||||
needTranslate = data.get("needTranslate", True)
|
||||
|
||||
# 获取打招呼数据
|
||||
ev.prologueList = data.get("prologueList", [])
|
||||
|
||||
@@ -340,7 +356,8 @@ def followAndGreetUnion():
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
# 启动脚本
|
||||
thread = threading.Thread(target=manager.safe_followAndGreetUnion, args=(udid, needReply, event))
|
||||
thread = threading.Thread(target=manager.safe_followAndGreetUnion,
|
||||
args=(udid, needReply, needTranslate, event))
|
||||
# 添加到线程管理
|
||||
ThreadManager.add(udid, thread, event)
|
||||
return ResultData(data="").toJson()
|
||||
@@ -378,12 +395,28 @@ def addTempAnchorData():
|
||||
def getChatTextInfo():
|
||||
data = request.get_json()
|
||||
udid = data.get("udid")
|
||||
client = wda.USBClient(udid, wdaFunctionPort)
|
||||
client = wda.USBClient(udid,wdaFunctionPort)
|
||||
session = client.session()
|
||||
xml = session.source()
|
||||
try:
|
||||
result = AiUtils.extract_messages_from_xml(xml)
|
||||
print(result)
|
||||
|
||||
last_in = None
|
||||
last_out = None
|
||||
|
||||
for item in reversed(result): # 从后往前找
|
||||
if item.get('type') != 'msg':
|
||||
continue
|
||||
if last_in is None and item['dir'] == 'in':
|
||||
last_in = item['text']
|
||||
if last_out is None and item['dir'] == 'out':
|
||||
last_out = item['text']
|
||||
if last_in is not None and last_out is not None:
|
||||
break
|
||||
|
||||
print(f"检测出对方的最后一条数据:{last_in},{type(last_in)}")
|
||||
print(f"检测出我的最后一条数据:{last_out},{type(last_out)}")
|
||||
|
||||
return ResultData(data=result).toJson()
|
||||
except Exception as e:
|
||||
|
||||
@@ -410,6 +443,8 @@ def monitorMessages():
|
||||
LogManager.method_info("开始监控消息,监控消息脚本启动", "监控消息")
|
||||
body = request.get_json()
|
||||
udid = body.get("udid")
|
||||
# Variables.commentList = body.get("comment")
|
||||
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
thread = threading.Thread(target=manager.replyMessages, args=(udid, event))
|
||||
@@ -525,11 +560,29 @@ def aiConfig():
|
||||
contactTool = data.get("contactTool")
|
||||
contact = data.get("contact")
|
||||
|
||||
age = data.get("age")
|
||||
sex = data.get("sex")
|
||||
height = data.get("height")
|
||||
weight = data.get("weight")
|
||||
body_features = data.get("body_features")
|
||||
nationality = data.get("nationality")
|
||||
personality = data.get("personality")
|
||||
strengths = data.get("strengths")
|
||||
|
||||
dict = {
|
||||
"agentName": agentName,
|
||||
"guildName": guildName,
|
||||
"contactTool": contactTool,
|
||||
"contact": contact
|
||||
"contact": contact,
|
||||
"age": age,
|
||||
"sex": sex,
|
||||
"height": height,
|
||||
"weight": weight,
|
||||
"body_features": body_features,
|
||||
"nationality": nationality,
|
||||
"personality": personality,
|
||||
"strengths": strengths,
|
||||
"api-key": "app-sdRfZy2by9Kq7uJg7JdOSVr8"
|
||||
}
|
||||
|
||||
# JsonUtils.write_json("aiConfig", dict)
|
||||
@@ -554,9 +607,9 @@ def update_last_message():
|
||||
|
||||
updated_count = JsonUtils.update_json_items(
|
||||
match={"sender": sender, "text": text}, # 匹配条件
|
||||
patch={"state": 1}, # 修改内容
|
||||
filename="last_message.json", # 要修改的文件
|
||||
multi=False # 只改第一条匹配的
|
||||
patch={"status": 1}, # 修改内容
|
||||
filename="log/last_message.json", # 要修改的文件
|
||||
multi=True # 只改第一条匹配的
|
||||
)
|
||||
if updated_count > 0:
|
||||
return ResultData(data=updated_count, message="修改成功").toJson()
|
||||
@@ -573,15 +626,16 @@ def delete_last_message():
|
||||
|
||||
updated_count = JsonUtils.delete_json_items(
|
||||
match={"sender": sender, "text": text}, # 匹配条件
|
||||
filename="last_message.json", # 要修改的文件
|
||||
multi=False # 只改第一条匹配的
|
||||
filename="log/last_message.json", # 要修改的文件
|
||||
multi=True # 只改第一条匹配的
|
||||
)
|
||||
if updated_count > 0:
|
||||
return ResultData(data=updated_count, message="修改成功").toJson()
|
||||
|
||||
return ResultData(data=updated_count, message="修改失败").toJson()
|
||||
|
||||
|
||||
# 的停止所有任务
|
||||
# 停止所有任务
|
||||
@app.route("/stopAllTask", methods=['POST'])
|
||||
def stopAllTask():
|
||||
idList = request.get_json()
|
||||
@@ -594,20 +648,34 @@ def stopAllTask():
|
||||
def changeAccount():
|
||||
body = request.get_json()
|
||||
udid = body.get("udid")
|
||||
account_id = body.get("account_id")
|
||||
if not udid:
|
||||
return ResultData(data="", code=400, message="缺少 udid").toJson()
|
||||
|
||||
IOSAIStorage.save(account_id, f"{udid}/accountId.json")
|
||||
|
||||
# 存储到本地
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
threading.Event()
|
||||
|
||||
# 启动脚本
|
||||
thread = threading.Thread(target=manager.changeAccount, args=(udid, event))
|
||||
# 添加到线程管理
|
||||
code, msg = ThreadManager.add(udid, thread, event)
|
||||
code, msg = manager.changeAccount(udid)
|
||||
# thread = threading.Thread(target=, args=(udid,))
|
||||
# # 添加到线程管理
|
||||
# thread.start()
|
||||
return ResultData(data="", code=code, message=msg).toJson()
|
||||
|
||||
|
||||
@app.route('/test', methods=['POST'])
|
||||
def test():
|
||||
body = request.get_json()
|
||||
|
||||
manager = ScriptManager()
|
||||
threading.Event()
|
||||
|
||||
# 启动脚本
|
||||
manager.test()
|
||||
# thread = threading.Thread(target=, args=(udid,))
|
||||
# # 添加到线程管理
|
||||
# thread.start()
|
||||
return ResultData(data="", code=200, message="成功").toJson()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run("0.0.0.0", port=5000, debug=True, use_reloader=False)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user