feat(core):初步完成定时执行功能开发
This commit is contained in:
@@ -24,75 +24,76 @@ MAA功能组件
|
||||
v4.2
|
||||
作者:DLmaster_361
|
||||
"""
|
||||
|
||||
from loguru import logger
|
||||
from PySide6 import QtCore
|
||||
import json
|
||||
import sqlite3
|
||||
import datetime
|
||||
import os
|
||||
import subprocess
|
||||
import shutil
|
||||
import time
|
||||
from pathlib import Path
|
||||
from qfluentwidgets import (
|
||||
QConfig,
|
||||
ConfigItem,
|
||||
qconfig,
|
||||
OptionsConfigItem,
|
||||
RangeConfigItem,
|
||||
OptionsValidator,
|
||||
BoolValidator,
|
||||
RangeValidator,
|
||||
EnumSerializer,
|
||||
FolderValidator,
|
||||
)
|
||||
from typing import List, Dict, Union
|
||||
|
||||
from app import AppConfig
|
||||
from app.core import AppConfig
|
||||
from app.services import Notification
|
||||
|
||||
|
||||
class MaaManager(QtCore.QThread):
|
||||
class MaaManager(QtCore.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)
|
||||
question = QtCore.Signal(str, str)
|
||||
question_response = QtCore.Signal(int)
|
||||
update_user_info = QtCore.Signal(list, list, list, list, list, list)
|
||||
set_silence = QtCore.Signal(str, str, list)
|
||||
accomplish = QtCore.Signal()
|
||||
push_info_bar = QtCore.Signal(str, str, str, int)
|
||||
create_user_list = QtCore.Signal(list)
|
||||
update_user_list = QtCore.Signal(list)
|
||||
update_log_text = QtCore.Signal(str)
|
||||
accomplish = QtCore.Signal(dict)
|
||||
get_json = QtCore.Signal(list)
|
||||
|
||||
def __init__(self, config: AppConfig):
|
||||
isInterruptionRequested = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: AppConfig,
|
||||
notify: Notification,
|
||||
mode: str,
|
||||
config_path: Path,
|
||||
):
|
||||
super(MaaManager, self).__init__()
|
||||
|
||||
self.config = config
|
||||
self.mode = None
|
||||
self.data = None
|
||||
self.notify = notify
|
||||
self.mode = mode
|
||||
self.config_path = config_path
|
||||
|
||||
with (self.config_path / "config.json").open("r", encoding="utf-8") as f:
|
||||
self.set = json.load(f)
|
||||
|
||||
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()
|
||||
|
||||
self.get_json_path = [0, 0, 0]
|
||||
|
||||
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.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"
|
||||
self.boss_key = [
|
||||
_.strip().lower()
|
||||
for _ in self.config.content["Default"]["SelfSet.BossKey"].split("+")
|
||||
for _ in self.config.global_config.get(
|
||||
self.config.global_config.function_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"
|
||||
)
|
||||
|
||||
def run(self):
|
||||
"""主进程,运行MAA代理进程"""
|
||||
@@ -101,86 +102,86 @@ 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
|
||||
)
|
||||
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
|
||||
)
|
||||
# 添加静默进程数量标记
|
||||
self.config.if_silence_needed += 1
|
||||
# 记录是否超时的标记
|
||||
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)
|
||||
@@ -200,11 +201,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
|
||||
|
||||
@@ -213,38 +220,21 @@ 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("禁用", "", [])
|
||||
# 移除静默进程数量标记
|
||||
self.config.if_silence_needed -= 1
|
||||
for _ in range(10):
|
||||
if self.isInterruptionRequested():
|
||||
if self.isInterruptionRequested:
|
||||
break
|
||||
time.sleep(1)
|
||||
break
|
||||
@@ -254,13 +244,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}",
|
||||
@@ -268,39 +252,40 @@ class MaaManager(QtCore.QThread):
|
||||
creationflags=subprocess.CREATE_NO_WINDOW,
|
||||
)
|
||||
killprocess.wait()
|
||||
# 关闭静默进程
|
||||
if self.if_silence:
|
||||
self.set_silence.emit("禁用", "", [])
|
||||
# 移除静默进程数量标记
|
||||
self.config.if_silence_needed -= 1
|
||||
# 推送异常通知
|
||||
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]}出现异常",
|
||||
self.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] = "完成"
|
||||
self.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 == "人工排查":
|
||||
@@ -308,47 +293,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)
|
||||
@@ -357,45 +339,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}",
|
||||
@@ -405,7 +363,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
|
||||
@@ -414,7 +372,7 @@ class MaaManager(QtCore.QThread):
|
||||
if run_book[0]:
|
||||
break
|
||||
# 登录失败,询问是否结束循环
|
||||
elif not self.isInterruptionRequested():
|
||||
elif not self.isInterruptionRequested:
|
||||
self.question_title = "操作提示"
|
||||
self.question_info = "MAA未能正确登录到PRTS,是否重试?"
|
||||
self.question_choice = "wait"
|
||||
@@ -425,7 +383,7 @@ class MaaManager(QtCore.QThread):
|
||||
break
|
||||
|
||||
# 登录成功,录入人工排查情况
|
||||
if run_book[0] and not self.isInterruptionRequested():
|
||||
if run_book[0] and not self.isInterruptionRequested:
|
||||
self.question_title = "操作提示"
|
||||
self.question_info = "请检查用户代理情况,如无异常请按下确认键。"
|
||||
self.question_choice = "wait"
|
||||
@@ -437,15 +395,19 @@ class MaaManager(QtCore.QThread):
|
||||
|
||||
# 结果录入用户备注栏
|
||||
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:
|
||||
@@ -454,7 +416,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,
|
||||
)
|
||||
@@ -462,7 +424,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)
|
||||
@@ -483,13 +445,13 @@ class MaaManager(QtCore.QThread):
|
||||
elif "用户" in self.mode:
|
||||
self.get_json.emit(self.get_json_path)
|
||||
|
||||
self.accomplish.emit()
|
||||
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,
|
||||
@@ -498,14 +460,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 = (
|
||||
@@ -518,46 +484,45 @@ 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(
|
||||
self.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 self.config.global_config.get(
|
||||
self.config.global_config.notify_IfSendErrorOnly
|
||||
) or (
|
||||
self.config.global_config.get(
|
||||
self.config.global_config.notify_IfSendErrorOnly
|
||||
)
|
||||
and len(error_index) + len(wait_index) != 0
|
||||
):
|
||||
self.send_mail.emit(
|
||||
self.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 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:
|
||||
@@ -576,8 +541,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"
|
||||
@@ -591,7 +556,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"
|
||||
@@ -605,7 +570,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"
|
||||
@@ -623,49 +588,49 @@ class MaaManager(QtCore.QThread):
|
||||
if mode == "设置MAA_用户":
|
||||
set_book = ["simple", "beta"]
|
||||
if (
|
||||
self.json_path
|
||||
self.config_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
|
||||
self.config_path
|
||||
/ f"{set_book[self.get_json_path[0]]}/{self.get_json_path[1]}/{self.get_json_path[2]}/gui.json",
|
||||
self.set_path,
|
||||
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):
|
||||
@@ -678,7 +643,7 @@ class MaaManager(QtCore.QThread):
|
||||
"Start.OpenEmulatorAfterLaunch"
|
||||
] = "True" # 启动MAA后自动开启模拟器
|
||||
|
||||
if self.if_silence:
|
||||
if self.config.if_silence_needed > 0:
|
||||
data["Global"]["Start.MinimizeDirectly"] = "True" # 启动MAA后直接最小化
|
||||
data["Global"]["GUI.UseTray"] = "True" # 显示托盘图标
|
||||
data["Global"]["GUI.MinimizeToTray"] = "True" # 最小化时隐藏至托盘
|
||||
@@ -869,7 +834,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:
|
||||
@@ -955,7 +920,7 @@ class MaaManager(QtCore.QThread):
|
||||
"Start.OpenEmulatorAfterLaunch"
|
||||
] = "False" # 启动MAA后自动开启模拟器
|
||||
|
||||
if self.if_silence:
|
||||
if self.config.if_silence_needed > 0:
|
||||
data["Global"][
|
||||
"Start.MinimizeDirectly"
|
||||
] = "False" # 启动MAA后直接最小化
|
||||
@@ -997,7 +962,7 @@ class MaaManager(QtCore.QThread):
|
||||
] = "False" # 生息演算
|
||||
|
||||
# 覆写配置文件
|
||||
with self.set_path.open(mode="w", encoding="utf-8") as f:
|
||||
with self.maa_set_path.open(mode="w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=4)
|
||||
|
||||
return True
|
||||
@@ -1006,7 +971,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