Merge branch 'fluent-gui-dev' into dev
This commit is contained in:
@@ -24,63 +24,70 @@ MAA功能组件
|
||||
v4.2
|
||||
作者:DLmaster_361
|
||||
"""
|
||||
|
||||
from PySide6 import QtCore
|
||||
from loguru import logger
|
||||
from PySide6.QtCore import QObject, Signal, QEventLoop
|
||||
import json
|
||||
import sqlite3
|
||||
import datetime
|
||||
import os
|
||||
import subprocess
|
||||
import shutil
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from app import AppConfig
|
||||
from app.core import Config
|
||||
from app.services import Notify
|
||||
|
||||
|
||||
class MaaManager(QtCore.QThread):
|
||||
class MaaManager(QObject):
|
||||
"""MAA控制器"""
|
||||
|
||||
question = QtCore.Signal()
|
||||
push_notification = QtCore.Signal(str, str, str, int)
|
||||
send_mail = QtCore.Signal(str, str)
|
||||
update_gui = QtCore.Signal(str, str, str, str, str)
|
||||
update_user_info = QtCore.Signal(list, list, list, list, list, list)
|
||||
set_silence = QtCore.Signal(str, str, list)
|
||||
accomplish = QtCore.Signal()
|
||||
get_json = QtCore.Signal(list)
|
||||
question = Signal(str, str)
|
||||
question_response = Signal(bool)
|
||||
update_user_info = Signal(list, list, list, list, list, list)
|
||||
push_info_bar = Signal(str, str, str, int)
|
||||
create_user_list = Signal(list)
|
||||
update_user_list = Signal(list)
|
||||
update_log_text = Signal(str)
|
||||
accomplish = Signal(dict)
|
||||
|
||||
def __init__(self, config: AppConfig):
|
||||
isInterruptionRequested = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
mode: str,
|
||||
config_path: Path,
|
||||
user_config_path: Path = None,
|
||||
):
|
||||
super(MaaManager, self).__init__()
|
||||
|
||||
self.config = config
|
||||
self.mode = None
|
||||
self.data = None
|
||||
self.get_json_path = [0, 0, 0]
|
||||
self.mode = mode
|
||||
self.config_path = config_path
|
||||
self.user_config_path = user_config_path
|
||||
|
||||
with (self.config_path / "config.json").open("r", encoding="utf-8") as f:
|
||||
self.set = json.load(f)
|
||||
|
||||
if "设置MAA" not in self.mode:
|
||||
|
||||
db = sqlite3.connect(self.config_path / "user_data.db")
|
||||
cur = db.cursor()
|
||||
cur.execute("SELECT * FROM adminx WHERE True")
|
||||
self.data = cur.fetchall()
|
||||
self.data = [list(row) for row in self.data]
|
||||
cur.close()
|
||||
db.close()
|
||||
|
||||
else:
|
||||
self.data = []
|
||||
|
||||
def configure(self):
|
||||
"""提取配置信息"""
|
||||
|
||||
self.maa_root_path = Path(self.config.content["Default"]["MaaSet.path"])
|
||||
self.set_path = self.maa_root_path / "config/gui.json"
|
||||
self.log_path = self.maa_root_path / "debug/gui.log"
|
||||
self.maa_path = self.maa_root_path / "MAA.exe"
|
||||
self.json_path = self.config.app_path / "data/MAAconfig"
|
||||
self.routine = self.config.content["Default"]["TimeLimit.routine"]
|
||||
self.annihilation = self.config.content["Default"]["TimeLimit.annihilation"]
|
||||
self.num = self.config.content["Default"]["TimesLimit.run"]
|
||||
self.boss_key = [
|
||||
_.strip().lower()
|
||||
for _ in self.config.content["Default"]["SelfSet.BossKey"].split("+")
|
||||
]
|
||||
self.if_send_mail = bool(
|
||||
self.config.content["Default"]["SelfSet.IfSendMail"] == "True"
|
||||
)
|
||||
self.if_send_error_only = bool(
|
||||
self.config.content["Default"]["SelfSet.IfSendMail.OnlyError"] == "True"
|
||||
)
|
||||
self.if_silence = bool(
|
||||
self.config.content["Default"]["SelfSet.IfSilence"] == "True"
|
||||
)
|
||||
self.maa_root_path = Path(self.set["MaaSet"]["Path"])
|
||||
self.maa_set_path = self.maa_root_path / "config/gui.json"
|
||||
self.maa_log_path = self.maa_root_path / "debug/gui.log"
|
||||
self.maa_exe_path = self.maa_root_path / "MAA.exe"
|
||||
|
||||
def run(self):
|
||||
"""主进程,运行MAA代理进程"""
|
||||
@@ -89,86 +96,102 @@ class MaaManager(QtCore.QThread):
|
||||
begin_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
self.configure()
|
||||
# 检查MAA路径是否可用
|
||||
if not self.maa_exe_path.exists() or not self.maa_set_path.exists():
|
||||
|
||||
logger.error("未正确配置MAA路径,MAA代理进程中止")
|
||||
self.push_info_bar.emit(
|
||||
"error", "启动MAA代理进程失败", "您还未正确配置MAA路径!", -1
|
||||
)
|
||||
self.accomplish.emit(
|
||||
{
|
||||
"Time": begin_time,
|
||||
"History": "由于未正确配置MAA路径,MAA代理进程中止",
|
||||
}
|
||||
)
|
||||
return None
|
||||
|
||||
# 整理用户数据,筛选需代理的用户
|
||||
self.data = sorted(self.data, key=lambda x: (-len(x[15]), x[16]))
|
||||
wait_index = []
|
||||
over_index = []
|
||||
error_index = []
|
||||
all_index = [
|
||||
_
|
||||
for _ in range(len(self.data))
|
||||
if (self.data[_][3] != 0 and self.data[_][4] == "y")
|
||||
user_list: List[List[str, str, int]] = [
|
||||
[_[0], "等待", index]
|
||||
for index, _ in enumerate(self.data)
|
||||
if (_[3] != 0 and _[4] == "y")
|
||||
]
|
||||
self.create_user_list.emit(user_list)
|
||||
|
||||
# 日常代理模式
|
||||
if self.mode == "日常代理":
|
||||
# 自动代理模式
|
||||
if self.mode == "自动代理":
|
||||
|
||||
# 执行情况预处理
|
||||
for _ in all_index:
|
||||
if self.data[_][5] != curdate:
|
||||
self.data[_][5] = curdate
|
||||
self.data[_][14] = 0
|
||||
self.data[_][0] += f"_第{str(self.data[_][14] + 1)}次代理"
|
||||
for _ in user_list:
|
||||
if self.data[_[2]][5] != curdate:
|
||||
self.data[_[2]][5] = curdate
|
||||
self.data[_[2]][14] = 0
|
||||
_[0] += f" - 第{self.data[_[2]][14] + 1}次代理"
|
||||
|
||||
# 开始代理
|
||||
for index in all_index:
|
||||
for user in user_list:
|
||||
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
break
|
||||
|
||||
user[1] = "运行"
|
||||
self.update_user_list.emit(user_list)
|
||||
|
||||
# 初始化代理情况记录和模式替换记录
|
||||
run_book = [False for _ in range(2)]
|
||||
mode_book = ["日常代理_剿灭", "日常代理_日常"]
|
||||
mode_book = ["自动代理_剿灭", "自动代理_日常"]
|
||||
|
||||
# 简洁模式用户默认开启日常代理
|
||||
if self.data[index][15] == "simple":
|
||||
self.data[index][9] = "y"
|
||||
# 简洁模式用户默认开启日常选项
|
||||
if self.data[user[2]][15] == "simple":
|
||||
self.data[user[2]][9] = "y"
|
||||
|
||||
# 尝试次数循环
|
||||
for i in range(self.num):
|
||||
for i in range(self.set["RunSet"]["RunTimesLimit"]):
|
||||
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
break
|
||||
|
||||
# 剿灭-日常模式循环
|
||||
for j in range(2):
|
||||
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
break
|
||||
|
||||
if self.data[index][10 - j] == "n":
|
||||
if self.data[user[2]][10 - j] == "n":
|
||||
run_book[j] = True
|
||||
continue
|
||||
if run_book[j]:
|
||||
continue
|
||||
|
||||
# 配置MAA
|
||||
self.set_maa(mode_book[j], index)
|
||||
self.set_maa(mode_book[j], user[2])
|
||||
# 记录当前时间
|
||||
start_time = datetime.datetime.now()
|
||||
# 创建MAA任务
|
||||
maa = subprocess.Popen(
|
||||
[self.maa_path],
|
||||
[self.maa_exe_path],
|
||||
shell=True,
|
||||
creationflags=subprocess.CREATE_NO_WINDOW,
|
||||
)
|
||||
# 启动静默进程
|
||||
if self.if_silence:
|
||||
self.set_silence.emit(
|
||||
"启用", self.get_emulator_path(), self.boss_key
|
||||
# 添加静默进程标记
|
||||
if Config.global_config.get(
|
||||
Config.global_config.function_IfSilence
|
||||
):
|
||||
with self.maa_set_path.open(
|
||||
mode="r", encoding="utf-8"
|
||||
) as f:
|
||||
set = json.load(f)
|
||||
self.emulator_path = Path(
|
||||
set["Configurations"]["Default"]["Start.EmulatorPath"]
|
||||
)
|
||||
Config.silence_list.append(self.emulator_path)
|
||||
# 记录是否超时的标记
|
||||
self.if_time_out = False
|
||||
# 更新运行信息
|
||||
wait_index = [
|
||||
_
|
||||
for _ in all_index
|
||||
if (not _ in over_index + error_index + [index])
|
||||
]
|
||||
|
||||
# 监测MAA运行状态
|
||||
while not self.isInterruptionRequested():
|
||||
while not self.isInterruptionRequested:
|
||||
|
||||
# 获取MAA日志
|
||||
logs = self.get_maa_log(start_time)
|
||||
@@ -188,11 +211,17 @@ class MaaManager(QtCore.QThread):
|
||||
if (
|
||||
j == 0
|
||||
and now_time - latest_time
|
||||
> datetime.timedelta(minutes=self.annihilation)
|
||||
> datetime.timedelta(
|
||||
minutes=self.set["RunSet"][
|
||||
"AnnihilationTimeLimit"
|
||||
]
|
||||
)
|
||||
) or (
|
||||
j == 1
|
||||
and now_time - latest_time
|
||||
> datetime.timedelta(minutes=self.routine)
|
||||
> datetime.timedelta(
|
||||
minutes=self.set["RunSet"]["RoutineTimeLimit"]
|
||||
)
|
||||
):
|
||||
self.if_time_out = True
|
||||
|
||||
@@ -201,38 +230,24 @@ class MaaManager(QtCore.QThread):
|
||||
|
||||
# 更新MAA日志
|
||||
if len(logs) > 100:
|
||||
self.update_gui.emit(
|
||||
f"{self.data[index][0]}_第{i + 1}次_{mode_book[j][5:7]}",
|
||||
"\n".join([self.data[_][0] for _ in wait_index]),
|
||||
"\n".join([self.data[_][0] for _ in over_index]),
|
||||
"\n".join([self.data[_][0] for _ in error_index]),
|
||||
"".join(logs[-100:]),
|
||||
)
|
||||
self.update_log_text.emit("".join(logs[-100:]))
|
||||
else:
|
||||
self.update_gui.emit(
|
||||
f"{self.data[index][0]}_第{i + 1}次_{mode_book[j][5:7]}",
|
||||
"\n".join([self.data[_][0] for _ in wait_index]),
|
||||
"\n".join([self.data[_][0] for _ in over_index]),
|
||||
"\n".join([self.data[_][0] for _ in error_index]),
|
||||
"".join(logs),
|
||||
)
|
||||
self.update_log_text.emit("".join(logs))
|
||||
|
||||
# 判断MAA程序运行状态
|
||||
result = self.if_maa_success(log, mode_book[j])
|
||||
if result == "Success!":
|
||||
run_book[j] = True
|
||||
self.update_gui.emit(
|
||||
f"{self.data[index][0]}_第{i + 1}次_{mode_book[j][5:7]}",
|
||||
"\n".join([self.data[_][0] for _ in wait_index]),
|
||||
"\n".join([self.data[_][0] for _ in over_index]),
|
||||
"\n".join([self.data[_][0] for _ in error_index]),
|
||||
"检测到MAA进程完成代理任务\n正在等待相关程序结束\n请等待10s",
|
||||
self.update_log_text.emit(
|
||||
"检测到MAA进程完成代理任务\n正在等待相关程序结束\n请等待10s"
|
||||
)
|
||||
# 关闭静默进程
|
||||
if self.if_silence:
|
||||
self.set_silence.emit("禁用", "", [])
|
||||
# 移除静默进程标记
|
||||
if Config.global_config.get(
|
||||
Config.global_config.function_IfSilence
|
||||
):
|
||||
Config.silence_list.remove(self.emulator_path)
|
||||
for _ in range(10):
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
break
|
||||
time.sleep(1)
|
||||
break
|
||||
@@ -242,13 +257,7 @@ class MaaManager(QtCore.QThread):
|
||||
else:
|
||||
# 打印中止信息
|
||||
# 此时,log变量内存储的就是出现异常的日志信息,可以保存或发送用于问题排查
|
||||
self.update_gui.emit(
|
||||
f"{self.data[index][0]}_第{i + 1}次_{mode_book[j][5:7]}",
|
||||
"\n".join([self.data[_][0] for _ in wait_index]),
|
||||
"\n".join([self.data[_][0] for _ in over_index]),
|
||||
"\n".join([self.data[_][0] for _ in error_index]),
|
||||
result,
|
||||
)
|
||||
self.update_log_text.emit(result)
|
||||
# 无命令行中止MAA与其子程序
|
||||
killprocess = subprocess.Popen(
|
||||
f"taskkill /F /T /PID {maa.pid}",
|
||||
@@ -256,39 +265,43 @@ class MaaManager(QtCore.QThread):
|
||||
creationflags=subprocess.CREATE_NO_WINDOW,
|
||||
)
|
||||
killprocess.wait()
|
||||
# 关闭静默进程
|
||||
if self.if_silence:
|
||||
self.set_silence.emit("禁用", "", [])
|
||||
# 移除静默进程标记
|
||||
if Config.global_config.get(
|
||||
Config.global_config.function_IfSilence
|
||||
):
|
||||
Config.silence_list.remove(self.emulator_path)
|
||||
# 推送异常通知
|
||||
self.push_notification.emit(
|
||||
"用户日常代理出现异常!",
|
||||
f"用户 {self.data[index][0].replace("_", " 今天的")}的{mode_book[j][5:7]}部分出现一次异常",
|
||||
f"{self.data[index][0].replace("_", " ")}的{mode_book[j][5:7]}出现异常",
|
||||
Notify.push_notification(
|
||||
"用户自动代理出现异常!",
|
||||
f"用户 {user[0].replace("_", " 今天的")}的{mode_book[j][5:7]}部分出现一次异常",
|
||||
f"{user[0].replace("_", " ")}的{mode_book[j][5:7]}出现异常",
|
||||
1,
|
||||
)
|
||||
for _ in range(10):
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
break
|
||||
time.sleep(1)
|
||||
break
|
||||
|
||||
# 成功完成代理的用户修改相关参数
|
||||
if run_book[0] and run_book[1]:
|
||||
if self.data[index][14] == 0 and self.data[index][3] != -1:
|
||||
self.data[index][3] -= 1
|
||||
self.data[index][14] += 1
|
||||
over_index.append(index)
|
||||
self.push_notification.emit(
|
||||
"成功完成一个日常代理任务!",
|
||||
f"已完成用户 {self.data[index][0].replace("_", " 今天的")}任务",
|
||||
f"已完成 {self.data[index][0].replace("_", " 的")}",
|
||||
if self.data[user[2]][14] == 0 and self.data[user[2]][3] != -1:
|
||||
self.data[user[2]][3] -= 1
|
||||
self.data[user[2]][14] += 1
|
||||
user[1] = "完成"
|
||||
Notify.push_notification(
|
||||
"成功完成一个自动代理任务!",
|
||||
f"已完成用户 {user[0].replace("_", " 今天的")}任务",
|
||||
f"已完成 {user[0].replace("_", " 的")}",
|
||||
3,
|
||||
)
|
||||
break
|
||||
|
||||
# 录入代理失败的用户
|
||||
if not (run_book[0] and run_book[1]):
|
||||
error_index.append(index)
|
||||
user[1] = "异常"
|
||||
|
||||
self.update_user_list.emit(user_list)
|
||||
|
||||
# 人工排查模式
|
||||
elif self.mode == "人工排查":
|
||||
@@ -296,47 +309,44 @@ class MaaManager(QtCore.QThread):
|
||||
# 标记是否需要启动模拟器
|
||||
if_strat_app = True
|
||||
# 标识排查模式
|
||||
for _ in all_index:
|
||||
self.data[_][0] += "_排查模式"
|
||||
for _ in user_list:
|
||||
_[0] += "_排查模式"
|
||||
|
||||
# 开始排查
|
||||
for index in all_index:
|
||||
for user in user_list:
|
||||
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
break
|
||||
|
||||
if self.data[index][15] == "beta":
|
||||
user[1] = "运行"
|
||||
self.update_user_list.emit(user_list)
|
||||
|
||||
if self.data[user[2]][15] == "beta":
|
||||
if_strat_app = True
|
||||
|
||||
run_book = [False for _ in range(2)]
|
||||
|
||||
# 启动重试循环
|
||||
while not self.isInterruptionRequested():
|
||||
while not self.isInterruptionRequested:
|
||||
|
||||
# 配置MAA
|
||||
if if_strat_app:
|
||||
self.set_maa("人工排查_启动模拟器", index)
|
||||
self.set_maa("人工排查_启动模拟器", user[2])
|
||||
if_strat_app = False
|
||||
else:
|
||||
self.set_maa("人工排查_仅切换账号", index)
|
||||
self.set_maa("人工排查_仅切换账号", user[2])
|
||||
|
||||
# 记录当前时间
|
||||
start_time = datetime.datetime.now()
|
||||
# 创建MAA任务
|
||||
maa = subprocess.Popen(
|
||||
[self.maa_path],
|
||||
[self.maa_exe_path],
|
||||
shell=True,
|
||||
creationflags=subprocess.CREATE_NO_WINDOW,
|
||||
)
|
||||
# 更新运行信息
|
||||
wait_index = [
|
||||
_
|
||||
for _ in all_index
|
||||
if (not _ in over_index + error_index + [index])
|
||||
]
|
||||
|
||||
# 监测MAA运行状态
|
||||
while not self.isInterruptionRequested():
|
||||
while not self.isInterruptionRequested:
|
||||
|
||||
# 获取MAA日志
|
||||
logs = self.get_maa_log(start_time)
|
||||
@@ -345,45 +355,21 @@ class MaaManager(QtCore.QThread):
|
||||
|
||||
# 更新MAA日志
|
||||
if len(logs) > 100:
|
||||
self.update_gui.emit(
|
||||
self.data[index][0],
|
||||
"\n".join([self.data[_][0] for _ in wait_index]),
|
||||
"\n".join([self.data[_][0] for _ in over_index]),
|
||||
"\n".join([self.data[_][0] for _ in error_index]),
|
||||
"".join(logs[-100:]),
|
||||
)
|
||||
self.update_log_text.emit("".join(logs[-100:]))
|
||||
else:
|
||||
self.update_gui.emit(
|
||||
self.data[index][0],
|
||||
"\n".join([self.data[_][0] for _ in wait_index]),
|
||||
"\n".join([self.data[_][0] for _ in over_index]),
|
||||
"\n".join([self.data[_][0] for _ in error_index]),
|
||||
"".join(logs),
|
||||
)
|
||||
self.update_log_text.emit("".join(logs))
|
||||
|
||||
# 判断MAA程序运行状态
|
||||
result = self.if_maa_success(log, "人工排查")
|
||||
if result == "Success!":
|
||||
run_book[0] = True
|
||||
self.update_gui.emit(
|
||||
self.data[index][0],
|
||||
"\n".join([self.data[_][0] for _ in wait_index]),
|
||||
"\n".join([self.data[_][0] for _ in over_index]),
|
||||
"\n".join([self.data[_][0] for _ in error_index]),
|
||||
"检测到MAA进程成功登录PRTS",
|
||||
)
|
||||
self.update_log_text.emit("检测到MAA进程成功登录PRTS")
|
||||
break
|
||||
elif result == "Wait":
|
||||
# 检测时间间隔
|
||||
time.sleep(1)
|
||||
else:
|
||||
self.update_gui.emit(
|
||||
self.data[index][0],
|
||||
"\n".join([self.data[_][0] for _ in wait_index]),
|
||||
"\n".join([self.data[_][0] for _ in over_index]),
|
||||
"\n".join([self.data[_][0] for _ in error_index]),
|
||||
result,
|
||||
)
|
||||
self.update_log_text.emit(result)
|
||||
# 无命令行中止MAA与其子程序
|
||||
killprocess = subprocess.Popen(
|
||||
f"taskkill /F /T /PID {maa.pid}",
|
||||
@@ -393,7 +379,7 @@ class MaaManager(QtCore.QThread):
|
||||
killprocess.wait()
|
||||
if_strat_app = True
|
||||
for _ in range(10):
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
break
|
||||
time.sleep(1)
|
||||
break
|
||||
@@ -402,38 +388,36 @@ class MaaManager(QtCore.QThread):
|
||||
if run_book[0]:
|
||||
break
|
||||
# 登录失败,询问是否结束循环
|
||||
elif not self.isInterruptionRequested():
|
||||
self.question_title = "操作提示"
|
||||
self.question_info = "MAA未能正确登录到PRTS,是否重试?"
|
||||
self.question_choice = "wait"
|
||||
self.question.emit()
|
||||
while self.question_choice == "wait":
|
||||
time.sleep(1)
|
||||
if self.question_choice == "No":
|
||||
elif not self.isInterruptionRequested:
|
||||
|
||||
if not self.push_question(
|
||||
"操作提示", "MAA未能正确登录到PRTS,是否重试?"
|
||||
):
|
||||
break
|
||||
|
||||
# 登录成功,录入人工排查情况
|
||||
if run_book[0] and not self.isInterruptionRequested():
|
||||
self.question_title = "操作提示"
|
||||
self.question_info = "请检查用户代理情况,如无异常请按下确认键。"
|
||||
self.question_choice = "wait"
|
||||
self.question.emit()
|
||||
while self.question_choice == "wait":
|
||||
time.sleep(1)
|
||||
if self.question_choice == "Yes":
|
||||
if run_book[0] and not self.isInterruptionRequested:
|
||||
|
||||
if self.push_question(
|
||||
"操作提示", "请检查用户代理情况,是否将该用户标记为异常?"
|
||||
):
|
||||
run_book[1] = True
|
||||
|
||||
# 结果录入用户备注栏
|
||||
if run_book[0] and run_book[1]:
|
||||
if "未通过人工排查" in self.data[index][13]:
|
||||
self.data[index][13] = self.data[index][13].replace(
|
||||
if "未通过人工排查" in self.data[user[2]][13]:
|
||||
self.data[user[2]][13] = self.data[user[2]][13].replace(
|
||||
"未通过人工排查|", ""
|
||||
)
|
||||
over_index.append(index)
|
||||
user[1] = "完成"
|
||||
elif not (run_book[0] and run_book[1]):
|
||||
if not "未通过人工排查" in self.data[index][13]:
|
||||
self.data[index][13] = f"未通过人工排查|{self.data[index][13]}"
|
||||
error_index.append(index)
|
||||
if not "未通过人工排查" in self.data[user[2]][13]:
|
||||
self.data[user[2]][
|
||||
13
|
||||
] = f"未通过人工排查|{self.data[user[2]][13]}"
|
||||
user[1] = "异常"
|
||||
|
||||
self.update_user_list.emit(user_list)
|
||||
|
||||
# 设置MAA模式
|
||||
elif "设置MAA" in self.mode:
|
||||
@@ -442,7 +426,7 @@ class MaaManager(QtCore.QThread):
|
||||
self.set_maa(self.mode, "")
|
||||
# 创建MAA任务
|
||||
maa = subprocess.Popen(
|
||||
[self.maa_path],
|
||||
[self.maa_exe_path],
|
||||
shell=True,
|
||||
creationflags=subprocess.CREATE_NO_WINDOW,
|
||||
)
|
||||
@@ -450,7 +434,7 @@ class MaaManager(QtCore.QThread):
|
||||
start_time = datetime.datetime.now()
|
||||
|
||||
# 监测MAA运行状态
|
||||
while not self.isInterruptionRequested():
|
||||
while not self.isInterruptionRequested:
|
||||
|
||||
# 获取MAA日志
|
||||
logs = self.get_maa_log(start_time)
|
||||
@@ -465,19 +449,22 @@ class MaaManager(QtCore.QThread):
|
||||
# 检测时间间隔
|
||||
time.sleep(1)
|
||||
|
||||
# 保存MAA配置文件
|
||||
if "全局" in self.mode:
|
||||
self.get_json.emit(["Default"])
|
||||
elif "用户" in self.mode:
|
||||
self.get_json.emit(self.get_json_path)
|
||||
(self.config_path / "Default").mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(self.maa_set_path, self.config_path / "Default")
|
||||
|
||||
self.accomplish.emit()
|
||||
elif "用户" in self.mode:
|
||||
self.user_config_path.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(self.maa_set_path, self.user_config_path)
|
||||
logger.debug(self.user_config_path)
|
||||
|
||||
end_log = ""
|
||||
|
||||
# 导出结果
|
||||
if self.mode in ["日常代理", "人工排查"]:
|
||||
if self.mode in ["自动代理", "人工排查"]:
|
||||
|
||||
# 关闭可能未正常退出的MAA进程
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
killprocess = subprocess.Popen(
|
||||
f"taskkill /F /T /PID {maa.pid}",
|
||||
shell=True,
|
||||
@@ -486,14 +473,18 @@ class MaaManager(QtCore.QThread):
|
||||
killprocess.wait()
|
||||
|
||||
# 更新用户数据
|
||||
modes = [self.data[_][15] for _ in all_index]
|
||||
uids = [self.data[_][16] for _ in all_index]
|
||||
days = [self.data[_][3] for _ in all_index]
|
||||
lasts = [self.data[_][5] for _ in all_index]
|
||||
notes = [self.data[_][13] for _ in all_index]
|
||||
numbs = [self.data[_][14] for _ in all_index]
|
||||
modes = [self.data[_[2]][15] for _ in user_list]
|
||||
uids = [self.data[_[2]][16] for _ in user_list]
|
||||
days = [self.data[_[2]][3] for _ in user_list]
|
||||
lasts = [self.data[_[2]][5] for _ in user_list]
|
||||
notes = [self.data[_[2]][13] for _ in user_list]
|
||||
numbs = [self.data[_[2]][14] for _ in user_list]
|
||||
self.update_user_info.emit(modes, uids, days, lasts, notes, numbs)
|
||||
|
||||
error_index = [_[2] for _ in user_list if _[1] == "异常"]
|
||||
over_index = [_[2] for _ in user_list if _[1] == "完成"]
|
||||
wait_index = [_[2] for _ in user_list if _[1] == "等待"]
|
||||
|
||||
# 保存运行日志
|
||||
end_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
end_log = (
|
||||
@@ -506,46 +497,55 @@ class MaaManager(QtCore.QThread):
|
||||
f"{self.mode[2:4]}未成功的用户:\n"
|
||||
f"{"\n".join([self.data[_][0] for _ in error_index])}\n"
|
||||
)
|
||||
wait_index = [_ for _ in all_index if (not _ in over_index + error_index)]
|
||||
if len(wait_index) != 0:
|
||||
end_log += (
|
||||
f"\n未开始{self.mode[2:4]}的用户:\n"
|
||||
f"{"\n".join([self.data[_][0] for _ in wait_index])}\n"
|
||||
)
|
||||
|
||||
(self.config.app_path / "log.txt").write_text(
|
||||
end_log,
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
# 恢复GUI运行面板
|
||||
self.update_gui.emit("", "", "", "", end_log)
|
||||
|
||||
# 推送代理结果通知
|
||||
self.push_notification.emit(
|
||||
Notify.push_notification(
|
||||
f"{self.mode[2:4]}任务已完成!",
|
||||
f"已完成用户数:{len(over_index)},未完成用户数:{len(error_index) + len(wait_index)}",
|
||||
f"已完成用户数:{len(over_index)},未完成用户数:{len(error_index) + len(wait_index)}",
|
||||
10,
|
||||
)
|
||||
if self.if_send_mail and (
|
||||
not self.if_send_error_only
|
||||
or (self.if_send_error_only and len(error_index) + len(wait_index) != 0)
|
||||
if not Config.global_config.get(
|
||||
Config.global_config.notify_IfSendErrorOnly
|
||||
) or (
|
||||
Config.global_config.get(Config.global_config.notify_IfSendErrorOnly)
|
||||
and len(error_index) + len(wait_index) != 0
|
||||
):
|
||||
self.send_mail.emit(
|
||||
Notify.send_mail(
|
||||
f"{self.mode[:4]}任务报告",
|
||||
f"{end_log}\n\nAUTO_MAA 敬上\n\n我们根据您在 AUTO_MAA 中的设置发送了这封电子邮件,本邮件无需回复\n",
|
||||
)
|
||||
|
||||
if not self.isInterruptionRequested():
|
||||
self.accomplish.emit()
|
||||
self.accomplish.emit({"Time": begin_time, "History": end_log})
|
||||
|
||||
def requestInterruption(self) -> None:
|
||||
|
||||
logger.info("申请中止本次任务")
|
||||
self.isInterruptionRequested = True
|
||||
|
||||
def push_question(self, title: str, message: str) -> bool:
|
||||
|
||||
self.question.emit(title, message)
|
||||
loop = QEventLoop()
|
||||
self.question_response.connect(self._capture_response)
|
||||
self.question_response.connect(loop.quit)
|
||||
loop.exec()
|
||||
return self.response
|
||||
|
||||
def _capture_response(self, response: bool) -> None:
|
||||
self.response = response
|
||||
|
||||
def get_maa_log(self, start_time):
|
||||
"""获取MAA日志"""
|
||||
|
||||
logs = []
|
||||
if_log_start = False
|
||||
with self.log_path.open(mode="r", encoding="utf-8") as f:
|
||||
with self.maa_log_path.open(mode="r", encoding="utf-8") as f:
|
||||
for entry in f:
|
||||
if not if_log_start:
|
||||
try:
|
||||
@@ -564,8 +564,8 @@ class MaaManager(QtCore.QThread):
|
||||
def if_maa_success(self, log, mode):
|
||||
"""判断MAA程序运行状态"""
|
||||
|
||||
if "日常代理" in mode:
|
||||
if mode == "日常代理_日常" and "任务出错: Fight" in log:
|
||||
if "自动代理" in mode:
|
||||
if mode == "自动代理_日常" and "任务出错: Fight" in log:
|
||||
return "检测到MAA未能实际执行任务\n正在中止相关程序\n请等待10s"
|
||||
if "任务出错: StartUp" in log:
|
||||
return "检测到MAA未能正确登录PRTS\n正在中止相关程序\n请等待10s"
|
||||
@@ -579,7 +579,7 @@ class MaaManager(QtCore.QThread):
|
||||
return "检测到MAA进程异常\n正在中止相关程序\n请等待10s"
|
||||
elif self.if_time_out:
|
||||
return "检测到MAA进程超时\n正在中止相关程序\n请等待10s"
|
||||
elif self.isInterruptionRequested():
|
||||
elif self.isInterruptionRequested:
|
||||
return "您中止了本次任务\n正在中止相关程序\n请等待"
|
||||
else:
|
||||
return "Wait"
|
||||
@@ -593,7 +593,7 @@ class MaaManager(QtCore.QThread):
|
||||
or ("MaaAssistantArknights GUI exited" in log)
|
||||
):
|
||||
return "检测到MAA进程异常\n正在中止相关程序\n请等待10s"
|
||||
elif self.isInterruptionRequested():
|
||||
elif self.isInterruptionRequested:
|
||||
return "您中止了本次任务\n正在中止相关程序\n请等待"
|
||||
else:
|
||||
return "Wait"
|
||||
@@ -609,51 +609,43 @@ class MaaManager(QtCore.QThread):
|
||||
|
||||
# 预导入MAA配置文件
|
||||
if mode == "设置MAA_用户":
|
||||
set_book = ["simple", "beta"]
|
||||
if (
|
||||
self.json_path
|
||||
/ f"{set_book[self.get_json_path[0]]}/{self.get_json_path[1]}/{self.get_json_path[2]}/gui.json"
|
||||
).exists():
|
||||
shutil.copy(
|
||||
self.json_path
|
||||
/ f"{set_book[self.get_json_path[0]]}/{self.get_json_path[1]}/{self.get_json_path[2]}/gui.json",
|
||||
self.set_path,
|
||||
)
|
||||
if self.user_config_path.exists():
|
||||
shutil.copy(self.user_config_path / "gui.json", self.maa_set_path)
|
||||
else:
|
||||
shutil.copy(
|
||||
self.json_path / "Default/gui.json",
|
||||
self.set_path,
|
||||
self.config_path / "Default/gui.json",
|
||||
self.maa_set_path,
|
||||
)
|
||||
elif (mode == "设置MAA_全局") or (
|
||||
("日常代理" in mode or "人工排查" in mode)
|
||||
("自动代理" in mode or "人工排查" in mode)
|
||||
and self.data[index][15] == "simple"
|
||||
):
|
||||
shutil.copy(
|
||||
self.json_path / "Default/gui.json",
|
||||
self.set_path,
|
||||
self.config_path / "Default/gui.json",
|
||||
self.maa_set_path,
|
||||
)
|
||||
elif "日常代理" in mode and self.data[index][15] == "beta":
|
||||
if mode == "日常代理_剿灭":
|
||||
elif "自动代理" in mode and self.data[index][15] == "beta":
|
||||
if mode == "自动代理_剿灭":
|
||||
shutil.copy(
|
||||
self.json_path
|
||||
self.config_path
|
||||
/ f"beta/{self.data[index][16]}/annihilation/gui.json",
|
||||
self.set_path,
|
||||
self.maa_set_path,
|
||||
)
|
||||
elif mode == "日常代理_日常":
|
||||
elif mode == "自动代理_日常":
|
||||
shutil.copy(
|
||||
self.json_path / f"beta/{self.data[index][16]}/routine/gui.json",
|
||||
self.set_path,
|
||||
self.config_path / f"beta/{self.data[index][16]}/routine/gui.json",
|
||||
self.maa_set_path,
|
||||
)
|
||||
elif "人工排查" in mode and self.data[index][15] == "beta":
|
||||
shutil.copy(
|
||||
self.json_path / f"beta/{self.data[index][16]}/routine/gui.json",
|
||||
self.set_path,
|
||||
self.config_path / f"beta/{self.data[index][16]}/routine/gui.json",
|
||||
self.maa_set_path,
|
||||
)
|
||||
with self.set_path.open(mode="r", encoding="utf-8") as f:
|
||||
with self.maa_set_path.open(mode="r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
# 日常代理配置
|
||||
if "日常代理" in mode:
|
||||
# 自动代理配置
|
||||
if "自动代理" in mode:
|
||||
|
||||
data["Current"] = "Default" # 切换配置
|
||||
for i in range(1, 9):
|
||||
@@ -661,22 +653,14 @@ class MaaManager(QtCore.QThread):
|
||||
data["Configurations"]["Default"][
|
||||
"MainFunction.PostActions"
|
||||
] = "12" # 完成后退出MAA和模拟器
|
||||
|
||||
# v5.1.11版本对于以下字段处理
|
||||
# 启动MAA后直接运行
|
||||
data["Global"]["Start.RunDirectly"] = "True"
|
||||
# 启动MAA后自动开启模拟器
|
||||
data["Global"][
|
||||
data["Configurations"]["Default"][
|
||||
"Start.RunDirectly"
|
||||
] = "True" # 启动MAA后直接运行
|
||||
data["Configurations"]["Default"][
|
||||
"Start.OpenEmulatorAfterLaunch"
|
||||
] = "True"
|
||||
] = "True" # 启动MAA后自动开启模拟器
|
||||
|
||||
# v5.1.12版本对以下字段处理
|
||||
# 启动MAA后直接运行
|
||||
data["Configurations"]["Default"]["Start.OpenEmulatorAfterLaunch"] = "True"
|
||||
# 启动MAA后自动开启模拟器
|
||||
data["Configurations"]["Default"]["Start.RunDirectly"] = "True"
|
||||
|
||||
if self.if_silence:
|
||||
if Config.global_config.get(Config.global_config.function_IfSilence):
|
||||
data["Global"]["Start.MinimizeDirectly"] = "True" # 启动MAA后直接最小化
|
||||
data["Global"]["GUI.UseTray"] = "True" # 显示托盘图标
|
||||
data["Global"]["GUI.MinimizeToTray"] = "True" # 最小化时隐藏至托盘
|
||||
@@ -867,7 +851,7 @@ class MaaManager(QtCore.QThread):
|
||||
] = "False" # 自定义基建配置文件只读
|
||||
data["Configurations"]["Default"][
|
||||
"Infrast.CustomInfrastFile"
|
||||
] = f"{self.json_path}/simple/{self.data[index][16]}/infrastructure/infrastructure.json" # 自定义基建配置文件地址
|
||||
] = f"{self.config_path}/simple/{self.data[index][16]}/infrastructure/infrastructure.json" # 自定义基建配置文件地址
|
||||
|
||||
# 人工排查配置
|
||||
elif "人工排查" in mode:
|
||||
@@ -878,9 +862,9 @@ class MaaManager(QtCore.QThread):
|
||||
data["Configurations"]["Default"][
|
||||
"MainFunction.PostActions"
|
||||
] = "8" # 完成后退出MAA
|
||||
|
||||
# v5.1.11版本对于以下字段处理
|
||||
data["Global"]["Start.RunDirectly"] = "True" # 启动MAA后直接运行
|
||||
data["Configurations"]["Default"][
|
||||
"Start.RunDirectly"
|
||||
] = "True" # 启动MAA后直接运行
|
||||
data["Global"]["Start.MinimizeDirectly"] = "True" # 启动MAA后直接最小化
|
||||
# v5.1.12版本对以下字段处理
|
||||
# 启动MAA后直接运行
|
||||
@@ -888,14 +872,17 @@ class MaaManager(QtCore.QThread):
|
||||
# 启动MAA后自动开启模拟器
|
||||
data["Configurations"]["Default"]["Start.RunDirectly"] = "True"
|
||||
|
||||
|
||||
data["Global"]["GUI.UseTray"] = "True" # 显示托盘图标
|
||||
data["Global"]["GUI.MinimizeToTray"] = "True" # 最小化时隐藏至托盘
|
||||
# 启动MAA后自动开启模拟器
|
||||
if "启动模拟器" in mode:
|
||||
data["Global"]["Start.OpenEmulatorAfterLaunch"] = "True"
|
||||
data["Configurations"]["Default"][
|
||||
"Start.OpenEmulatorAfterLaunch"
|
||||
] = "True"
|
||||
elif "仅切换账号" in mode:
|
||||
data["Global"]["Start.OpenEmulatorAfterLaunch"] = "False"
|
||||
data["Configurations"]["Default"][
|
||||
"Start.OpenEmulatorAfterLaunch"
|
||||
] = "False"
|
||||
|
||||
if self.data[index][15] == "simple":
|
||||
|
||||
@@ -957,20 +944,14 @@ class MaaManager(QtCore.QThread):
|
||||
data["Configurations"]["Default"][
|
||||
"MainFunction.PostActions"
|
||||
] = "0" # 完成后无动作
|
||||
|
||||
# v5.11.1及以下版本的字段处理
|
||||
data["Global"]["Start.RunDirectly"] = "False" # 启动MAA后直接运行
|
||||
data["Global"][
|
||||
data["Configurations"]["Default"][
|
||||
"Start.RunDirectly"
|
||||
] = "False" # 启动MAA后直接运行
|
||||
data["Configurations"]["Default"][
|
||||
"Start.OpenEmulatorAfterLaunch"
|
||||
] = "False" # 启动MAA后自动开启模拟器
|
||||
|
||||
# v5.1.12版本对以下字段处理
|
||||
# 启动MAA后直接运行
|
||||
data["Configurations"]["Default"]["Start.OpenEmulatorAfterLaunch"] = "False"
|
||||
# 启动MAA后自动开启模拟器
|
||||
data["Configurations"]["Default"]["Start.RunDirectly"] = "False"
|
||||
|
||||
if self.if_silence:
|
||||
if Config.global_config.get(Config.global_config.function_IfSilence):
|
||||
data["Global"][
|
||||
"Start.MinimizeDirectly"
|
||||
] = "False" # 启动MAA后直接最小化
|
||||
@@ -1012,8 +993,8 @@ class MaaManager(QtCore.QThread):
|
||||
] = "False" # 生息演算
|
||||
|
||||
# 覆写配置文件
|
||||
with self.set_path.open(mode="w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=4)
|
||||
with self.maa_set_path.open(mode="w", encoding="utf-8") as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||
|
||||
return True
|
||||
|
||||
@@ -1021,7 +1002,7 @@ class MaaManager(QtCore.QThread):
|
||||
"""获取模拟器路径"""
|
||||
|
||||
# 读取配置文件
|
||||
with self.set_path.open(mode="r", encoding="utf-8") as f:
|
||||
with self.maa_set_path.open(mode="r", encoding="utf-8") as f:
|
||||
set = json.load(f)
|
||||
# 获取模拟器路径
|
||||
return Path(set["Configurations"]["Default"]["Start.EmulatorPath"])
|
||||
|
||||
Reference in New Issue
Block a user