解决打招呼消息的bug

This commit is contained in:
zw
2025-09-08 19:16:05 +08:00
parent a6d5330c73
commit 7a8380af9c
4 changed files with 48 additions and 71 deletions

View File

@@ -16,15 +16,17 @@ from Entity.ResultData import ResultData
from Utils.ControlUtils import ControlUtils
from Utils.ThreadManager import ThreadManager
from script.ScriptManager import ScriptManager
from Entity.Variables import anchorList, addModelToAnchorList, prologueList, removeModelFromAnchorList
from Entity.Variables import anchorList, prologueList, addModelToAnchorList, removeModelFromAnchorList
import Entity.Variables as ev
app = Flask(__name__)
CORS(app)
app.config['JSON_AS_ASCII'] = False # Flask jsonify 不转义中文/emoji
app.config['JSONIFY_MIMETYPE'] = "application/json; charset=utf-8"
listData = []
dataQueue = Queue()
def start_socket_listener():
port = int(os.getenv('FLASK_COMM_PORT', 0))
LogManager.info(f"Received port from environment: {port}")
@@ -230,43 +232,40 @@ def stopScript():
code, msg = ThreadManager.stop(udid)
return ResultData(code=code, data="", msg=msg).toJson()
# 传递主播数据(关注主播打招呼)
# 关注打招呼
@app.route('/passAnchorData', methods=['POST'])
def passAnchorData():
data: Dict[str, Any] = request.get_json()
# 设备列表
try:
data: Dict[str, Any] = request.get_json()
# 设备列表
idList = data.get("deviceList", [])
# 主播列表
acList = data.get("anchorList", [])
# 是否需要回复
needReply = data.get("needReply", True)
# 获取打招呼数据
ev.prologueList = data.get("prologueList", [])
print("接收的数据", data)
idList = data.get("deviceList", [])
# 主播列表
acList = data.get("anchorList", [])
# 是否需要回复
needReply = data.get("needReply", True)
# 获取打招呼数据
ev.prologueList = data.get("prologueList", [])
# 添加主播数据
addModelToAnchorList(acList)
# 启动线程,执行脚本
for udid in idList:
manager = ScriptManager()
event = threading.Event()
# 启动脚本
thread = threading.Thread(target=manager.safe_greetNewFollowers, args=(udid, needReply, event))
thread.start()
# 添加到线程管理
ThreadManager.add(udid, thread, event)
return ResultData(data="").toJson()
# 添加主播数据
addModelToAnchorList(acList)
# 启动线程,执行脚本
for udid in idList:
manager = ScriptManager()
event = threading.Event()
# 启动脚本
thread = threading.Thread(target=manager.safe_greetNewFollowers, args=(udid, needReply, event))
thread.start()
# 添加到线程管理
ThreadManager.add(udid, thread, event)
return ResultData(data="").toJson()
except Exception as e:
LogManager.error(e)
# 获取私信数据
@app.route("/getPrologueList", methods=['GET'])
def getPrologueList():
print(ev.prologueList)
return ResultData(data=ev.prologueList).toJson()
import Entity.Variables as Variables
return ResultData(data=Variables.prologueList).toJson()
# 添加临时数据
@app.route("/addTempAnchorData", methods=['POST'])