Skip to content

Commit

Permalink
feat(core):初步完成定时执行功能开发
Browse files Browse the repository at this point in the history
  • Loading branch information
DLmaster361 committed Jan 25, 2025
1 parent ff7e433 commit 7e08c88
Show file tree
Hide file tree
Showing 64 changed files with 5,862 additions and 512 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ MAA多账号管理与自动化软件

1. **配置:** 根据对应用户的配置信息,生成配置文件并将其导入MAA。
2. **监测:** 在MAA开始代理后,持续读取MAA的日志以判断其运行状态。当软件认定MAA出现异常时,通过重启MAA使之仍能继续完成任务。
3. **循环:** 重复上述步骤,使MAA依次完成各个用户的日常代理任务
3. **循环:** 重复上述步骤,使MAA依次完成各个用户的自动代理任务

### 优势

- **节省运行开销:** 只需要一份MAA软件与一个模拟器,无需多开就能完成多账号代理,羸弱的电脑也能代理日常。
- **自定义空间大:** 依靠高级用户配置模式,支持MAA几乎所有设置选项自定义,同时保留对模拟器多开的支持。
- **一键代理无忧:** 无须中途手动修改MAA配置,将繁琐交给AUTO_MAA,把游戏留给自己。
- **代理结果复核:** 通过人工排查功能核实各用户代理情况,堵住日常代理的最后一丝风险
- **代理结果复核:** 通过人工排查功能核实各用户代理情况,堵住自动代理的最后一丝风险

## 重要声明

Expand Down Expand Up @@ -127,8 +127,8 @@ MAA多账号管理与自动化软件
- `MAA路径`:该项无法直接编辑,仅用于展示当前程序所绑定MAA的路径。
- `浏览`:选择MAA文件夹。
- `设置MAA`:编辑MAA全局配置,具体使用方法参见前文。
- `日常限制`执行日常代理的日常部分时的超时阈值,当MAA日志无变化时间超过阈值时,视为超时。
- `剿灭限制`执行日常代理的剿灭部分时的超时阈值,当MAA日志无变化时间超过阈值时,视为超时。
- `日常限制`执行自动代理的日常部分时的超时阈值,当MAA日志无变化时间超过阈值时,视为超时。
- `剿灭限制`执行自动代理的剿灭部分时的超时阈值,当MAA日志无变化时间超过阈值时,视为超时。
- `运行失败重试次数上限`:对于每一用户,若超过该次数限制仍未完成代理,视为代理失败。
- `开机自动启动AUTO_MAA`:实现AUTO_MAA的自启动。
- `AUTO_MAA启动时禁止电脑休眠`:仅阻止电脑自动休眠,不会影响屏幕是否熄灭。
Expand All @@ -154,8 +154,8 @@ MAA多账号管理与自动化软件
- `状态`:用户的状态,禁用时将不再对其进行代理或排查。
- `执行情况`:当日执行情况,不可编辑。
- `关卡``备选关卡-1``备选关卡-2`:关卡号。
- `日常`单独设定是否进行日常代理的日常部分,可进一步配置MAA的具体代理任务,该配置与全局MAA配置相互独立。
- `剿灭`单独设定是否进行日常代理的剿灭部分,高级配置模式下可进一步配置MAA的具体代理任务,该配置与全局MAA配置相互独立。
- `日常`单独设定是否进行自动代理的日常部分,可进一步配置MAA的具体代理任务,该配置与全局MAA配置相互独立。
- `剿灭`单独设定是否进行自动代理的剿灭部分,高级配置模式下可进一步配置MAA的具体代理任务,该配置与全局MAA配置相互独立。
- `自定义基建`:是否启用自定义基建功能,需要进一步配置自定义基建文件,该配置与其他用户相互独立。
- `密码`:仅用于登记用户的密码,可留空。
- `备注`:用于备注用户信息。
Expand Down
Empty file added Updater.exe
Empty file.
5 changes: 4 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
__author__ = "DLmaster361 <[email protected]>"
__license__ = "GPL-3.0 license"

from .config import AppConfig, QueueConfig, MaaConfig
from .core import AppConfig, QueueConfig, MaaConfig, Task, TaskManager, MainTimer
from .models import MaaManager
from .services import Notification, CryptoHandler, SystemHandler
from .ui import AUTO_MAA
Expand All @@ -39,6 +39,9 @@
"AppConfig",
"QueueConfig",
"MaaConfig",
"Task",
"TaskManager",
"MainTimer",
"MaaManager",
"Notification",
"CryptoHandler",
Expand Down
Binary file added app/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added app/__pycache__/config.cpython-312.pyc
Binary file not shown.
Binary file added app/__pycache__/task_manager.cpython-312.pyc
Binary file not shown.
Binary file added app/__pycache__/timer.cpython-312.pyc
Binary file not shown.
45 changes: 45 additions & 0 deletions app/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# <AUTO_MAA:A MAA Multi Account Management and Automation Tool>
# Copyright © <2024> <DLmaster361>

# This file is part of AUTO_MAA.

# AUTO_MAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.

# AUTO_MAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with AUTO_MAA. If not, see <https://www.gnu.org/licenses/>.

# [email protected]

"""
AUTO_MAA
AUTO_MAA核心组件包
v4.2
作者:DLmaster_361
"""

__version__ = "4.2.0"
__author__ = "DLmaster361 <[email protected]>"
__license__ = "GPL-3.0 license"

from .config import AppConfig, QueueConfig, MaaConfig
from .main_info_bar import MainInfoBar
from .task_manager import Task, TaskManager
from .timer import MainTimer

__all__ = [
"AppConfig",
"QueueConfig",
"MaaConfig",
"MainInfoBar",
"Task",
"TaskManager",
"MainTimer",
]
Binary file added app/core/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added app/core/__pycache__/config.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file added app/core/__pycache__/task_manager.cpython-312.pyc
Binary file not shown.
Binary file added app/core/__pycache__/timer.cpython-312.pyc
Binary file not shown.
73 changes: 64 additions & 9 deletions app/config.py → app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
作者:DLmaster_361
"""

from loguru import logger
import sqlite3
import json
import os
import sys
from pathlib import Path
from typing import Dict, Union
Expand All @@ -37,11 +37,9 @@
qconfig,
OptionsConfigItem,
RangeConfigItem,
OptionsValidator,
FolderValidator,
BoolValidator,
RangeValidator,
EnumSerializer,
)


Expand All @@ -52,13 +50,17 @@ def __init__(self) -> None:
self.app_path = Path(sys.argv[0]).resolve().parent # 获取软件根目录
self.app_path_sys = str(Path(sys.argv[0]).resolve()) # 获取软件自身的路径

self.log_path = self.app_path / "debug/AUTO_MAA.log"
self.database_path = self.app_path / "data/data.db"
self.config_path = self.app_path / "config/config.json"
self.history_path = self.app_path / "config/history.json"
self.key_path = self.app_path / "data/key"
self.gameid_path = self.app_path / "data/gameid.txt"
self.version_path = self.app_path / "resources/version.json"

self.PASSWORD = ""
self.running_list = []
self.if_silence_needed = 0
self.if_database_opened = False

# 检查文件完整性
Expand All @@ -70,6 +72,7 @@ def initialize(self) -> None:
# 检查目录
(self.app_path / "config").mkdir(parents=True, exist_ok=True)
(self.app_path / "data").mkdir(parents=True, exist_ok=True)
(self.app_path / "debug").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/simple").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/beta").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/Default").mkdir(parents=True, exist_ok=True)
Expand All @@ -90,18 +93,47 @@ def initialize(self) -> None:
encoding="utf-8",
)

self.init_logger()
self.init_config()
# self.check_database()
logger.info("程序配置管理模块初始化完成")

def init_logger(self) -> None:
"""初始化日志记录器"""

# logger.remove(0)

# logger.add(
# sink=sys.stdout,
# level="DEBUG",
# format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <level>{message}</level>",
# enqueue=True,
# backtrace=True,
# diagnose=True,
# )
logger.add(
sink=self.log_path,
level="DEBUG",
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <level>{message}</level>",
enqueue=True,
backtrace=True,
diagnose=True,
rotation="1 week",
retention="1 month",
compression="zip",
)

logger.info("日志记录器初始化完成")

def init_config(self) -> None:
"""初始化配置类"""

self.global_config = GlobalConfig()
qconfig.load(self.config_path, self.global_config)

self.queue_config = QueueConfig()
self.maa_config = MaaConfig()

logger.info("配置类初始化完成")

def init_database(self, mode: str) -> None:
"""初始化用户数据库"""

Expand All @@ -113,6 +145,8 @@ def init_database(self, mode: str) -> None:
self.cur.execute("INSERT INTO version VALUES(?)", ("v1.3",))
self.db.commit()

logger.info("用户数据库初始化完成")

def check_database(self) -> None:
"""检查用户数据库文件并处理数据库版本更新"""

Expand Down Expand Up @@ -196,10 +230,9 @@ def open_database(self, mode: str, index: str = None) -> None:
"""打开数据库"""

self.close_database()
if mode == "Maa":
self.db = sqlite3.connect(
self.app_path / f"config/{mode}Config/{index}/user_date.db"
)
self.db = sqlite3.connect(
self.app_path / f"config/{mode}Config/{index}/user_data.db"
)
self.cur = self.db.cursor()
self.if_database_opened = True

Expand All @@ -211,6 +244,28 @@ def close_database(self) -> None:
self.db.close()
self.if_database_opened = False

def save_history(self, key: str, content: dict) -> None:
"""保存历史记录"""

history = {}
if self.history_path.exists():
with self.history_path.open(mode="r", encoding="utf-8") as f:
history = json.load(f)
history[key] = content
with self.history_path.open(mode="w", encoding="utf-8") as f:
json.dump(history, f, indent=4)

def get_history(self, key: str) -> dict:
"""获取历史记录"""

history = {}
if self.history_path.exists():
with self.history_path.open(mode="r", encoding="utf-8") as f:
history = json.load(f)
return history.get(
key, {"Time": "0000-00-00 00:00", "History": "暂无历史运行记录"}
)

def clear_maa_config(self) -> None:
"""清空MAA配置"""

Expand Down
92 changes: 92 additions & 0 deletions app/core/main_info_bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# <AUTO_MAA:A MAA Multi Account Management and Automation Tool>
# Copyright © <2024> <DLmaster361>

# This file is part of AUTO_MAA.

# AUTO_MAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.

# AUTO_MAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with AUTO_MAA. If not, see <https://www.gnu.org/licenses/>.

# [email protected]

"""
AUTO_MAA
AUTO_MAA信息通知栏
v4.2
作者:DLmaster_361
"""

from loguru import logger
from PySide6.QtCore import Qt
from qfluentwidgets import (
InfoBar,
InfoBarPosition,
)


class _MainInfoBar:
"""信息通知栏"""

def __init__(self, parent=None):

self.parent = parent

def push_info_bar(self, mode: str, title: str, content: str, time: int):
"""推送到信息通知栏"""

if self.parent is None:
logger.error("信息通知栏未设置父窗口")
return None

if mode == "success":
InfoBar.success(
title=title,
content=content,
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT,
duration=time,
parent=self.parent,
)
elif mode == "warning":
InfoBar.warning(
title=title,
content=content,
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT,
duration=time,
parent=self.parent,
)
elif mode == "error":
InfoBar.error(
title=title,
content=content,
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT,
duration=time,
parent=self.parent,
)
elif mode == "info":
InfoBar.info(
title=title,
content=content,
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT,
duration=time,
parent=self.parent,
)


MainInfoBar = _MainInfoBar()
Loading

0 comments on commit 7e08c88

Please sign in to comment.