Skip to content

Commit

Permalink
初步完成调度队列开发
Browse files Browse the repository at this point in the history
  • Loading branch information
DLmaster361 committed Jan 5, 2025
1 parent f94e129 commit 684211c
Show file tree
Hide file tree
Showing 14 changed files with 2,529 additions and 959 deletions.
6 changes: 4 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@
__author__ = "DLmaster361 <[email protected]>"
__license__ = "GPL-3.0 license"

from .config import AppConfig, MaaConfig
from .config import AppConfig, QueueConfig, MaaConfig
from .models import MaaManager
from .services import Notification, CryptoHandler
from .services import Notification, CryptoHandler, SystemHandler
from .ui import AUTO_MAA
from .utils import Updater, version_text

__all__ = [
"AppConfig",
"QueueConfig",
"MaaConfig",
"MaaManager",
"Notification",
"CryptoHandler",
"SystemHandler",
"AUTO_MAA",
"Updater",
"version_text",
Expand Down
113 changes: 80 additions & 33 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __init__(self) -> None:
self.gameid_path = self.app_path / "data/gameid.txt"
self.version_path = self.app_path / "resources/version.json"

self.PASSWORD = ""
self.if_database_opened = False

# 检查文件完整性
self.initialize()

Expand Down Expand Up @@ -87,16 +90,16 @@ def initialize(self) -> None:
encoding="utf-8",
)

self.check_config()
self.check_database()
self.get_config()
# self.check_database()

def check_config(self) -> None:
"""检查配置文件字段完整性并补全"""
def get_config(self) -> None:
"""创建配置类"""

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

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

def check_database(self) -> None:
Expand Down Expand Up @@ -178,48 +181,44 @@ def check_database(self) -> None:
cur.close()
db.close()

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

if mode == "Maa":
self.cur.execute(
"CREATE TABLE adminx(admin text,id text,server text,day int,status text,last date,game text,game_1 text,game_2 text,routine text,annihilation text,infrastructure text,password byte,notes text,numb int,mode text,uid int)"
)
self.cur.execute("CREATE TABLE version(v text)")
self.cur.execute("INSERT INTO version VALUES(?)", ("v1.3",))
self.db.commit()

def open_database(self, mode: str, index: str = None) -> None:
"""打开数据库"""

self.db = sqlite3.connect(self.database_path)
if self.if_database_opened:
self.close_database()

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

def close_database(self) -> None:
"""关闭数据库"""

self.cur.close()
self.db.close()
self.if_database_opened = False


class GlobalConfig(QConfig):
"""全局配置"""

# ["TimeSet.set1", "False"],
# ["TimeSet.run1", "00:00"],
# ["TimeSet.set2", "False"],
# ["TimeSet.run2", "00:00"],
# ["TimeSet.set3", "False"],
# ["TimeSet.run3", "00:00"],
# ["TimeSet.set4", "False"],
# ["TimeSet.run4", "00:00"],
# ["TimeSet.set5", "False"],
# ["TimeSet.run5", "00:00"],
# ["TimeSet.set6", "False"],
# ["TimeSet.run6", "00:00"],
# ["TimeSet.set7", "False"],
# ["TimeSet.run7", "00:00"],
# ["TimeSet.set8", "False"],
# ["TimeSet.run8", "00:00"],
# ["TimeSet.set9", "False"],
# ["TimeSet.run9", "00:00"],
# ["TimeSet.set10", "False"],
# ["TimeSet.run10", "00:00"],
# ["MaaSet.path", ""],
# ["TimeLimit.routine", 10],
# ["TimeLimit.annihilation", 40],
# ["TimesLimit.run", 3],

function_IfSleep = ConfigItem("Function", "IfSleep", False, BoolValidator())
function_IfAllowSleep = ConfigItem(
"Function", "IfAllowSleep", False, BoolValidator()
)
function_IfSilence = ConfigItem("Function", "IfSilence", False, BoolValidator())
function_BossKey = ConfigItem("Function", "BossKey", "")

Expand All @@ -243,6 +242,54 @@ class GlobalConfig(QConfig):
update_IfAutoUpdate = ConfigItem("Update", "IfAutoUpdate", False, BoolValidator())


class QueueConfig(QConfig):
"""队列配置"""

queueSet_Name = ConfigItem("QueueSet", "Name", "")
queueSet_Enabled = ConfigItem("QueueSet", "Enabled", False, BoolValidator())

time_TimeEnabled_0 = ConfigItem("Time", "TimeEnabled_0", False, BoolValidator())
time_TimeSet_0 = ConfigItem("Time", "TimeSet_0", "00:00")

time_TimeEnabled_1 = ConfigItem("Time", "TimeEnabled_1", False, BoolValidator())
time_TimeSet_1 = ConfigItem("Time", "TimeSet_1", "00:00")

time_TimeEnabled_2 = ConfigItem("Time", "TimeEnabled_2", False, BoolValidator())
time_TimeSet_2 = ConfigItem("Time", "TimeSet_2", "00:00")

time_TimeEnabled_3 = ConfigItem("Time", "TimeEnabled_3", False, BoolValidator())
time_TimeSet_3 = ConfigItem("Time", "TimeSet_3", "00:00")

time_TimeEnabled_4 = ConfigItem("Time", "TimeEnabled_4", False, BoolValidator())
time_TimeSet_4 = ConfigItem("Time", "TimeSet_4", "00:00")

time_TimeEnabled_5 = ConfigItem("Time", "TimeEnabled_5", False, BoolValidator())
time_TimeSet_5 = ConfigItem("Time", "TimeSet_5", "00:00")

time_TimeEnabled_6 = ConfigItem("Time", "TimeEnabled_6", False, BoolValidator())
time_TimeSet_6 = ConfigItem("Time", "TimeSet_6", "00:00")

time_TimeEnabled_7 = ConfigItem("Time", "TimeEnabled_7", False, BoolValidator())
time_TimeSet_7 = ConfigItem("Time", "TimeSet_7", "00:00")

time_TimeEnabled_8 = ConfigItem("Time", "TimeEnabled_8", False, BoolValidator())
time_TimeSet_8 = ConfigItem("Time", "TimeSet_8", "00:00")

time_TimeEnabled_9 = ConfigItem("Time", "TimeEnabled_9", False, BoolValidator())
time_TimeSet_9 = ConfigItem("Time", "TimeSet_9", "00:00")

queue_Member_1 = OptionsConfigItem("Queue", "Member_1", "禁用")
queue_Member_2 = OptionsConfigItem("Queue", "Member_2", "禁用")
queue_Member_3 = OptionsConfigItem("Queue", "Member_3", "禁用")
queue_Member_4 = OptionsConfigItem("Queue", "Member_4", "禁用")
queue_Member_5 = OptionsConfigItem("Queue", "Member_5", "禁用")
queue_Member_6 = OptionsConfigItem("Queue", "Member_6", "禁用")
queue_Member_7 = OptionsConfigItem("Queue", "Member_7", "禁用")
queue_Member_8 = OptionsConfigItem("Queue", "Member_8", "禁用")
queue_Member_9 = OptionsConfigItem("Queue", "Member_9", "禁用")
queue_Member_10 = OptionsConfigItem("Queue", "Member_10", "禁用")


class MaaConfig(QConfig):
"""MAA配置"""

Expand Down
3 changes: 2 additions & 1 deletion app/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@

from .notification import Notification
from .security import CryptoHandler
from .system import SystemHandler

__all__ = ["Notification", "CryptoHandler"]
__all__ = ["Notification", "CryptoHandler", "SystemHandler"]
91 changes: 51 additions & 40 deletions app/services/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def __init__(self, config: AppConfig):
def push_notification(self, title, message, ticker, t):
"""推送系统通知"""

notification.notify(
title=title,
message=message,
app_name="AUTO_MAA",
app_icon=str(self.config.app_path / "resources/icons/AUTO_MAA.ico"),
timeout=t,
ticker=ticker,
toast=True,
)
if self.config.global_config.get(self.config.global_config.notify_IfPushPlyer):

notification.notify(
title=title,
message=message,
app_name="AUTO_MAA",
app_icon=str(self.config.app_path / "resources/icons/AUTO_MAA.ico"),
timeout=t,
ticker=ticker,
toast=True,
)

return True

Expand All @@ -62,34 +64,43 @@ def send_mail(self, title, content):
# 声明:此邮箱为AUTO_MAA项目组资产,未经授权不得私自使用
# 注意:此声明注释只有使用者更换发信邮箱时才能删除,本条规则优先级高于GPLv3

# 第三方 SMTP 服务配置
mail_host = "smtp.163.com" # 设置服务器
mail_sender = "[email protected]" # 用户名
mail_key = "SYrq87nDLD4RNB5T" # 授权码 24/11/15

# 定义邮件正文
message = MIMEText(content, "plain", "utf-8")
message["From"] = formataddr(
(Header("AUTO_MAA通知服务", "utf-8").encode(), "[email protected]")
) # 发件人显示的名字
message["To"] = formataddr(
(
Header("AUTO_MAA用户", "utf-8").encode(),
self.config.content["Default"]["SelfSet.MailAddress"],
)
) # 收件人显示的名字
message["Subject"] = Header(title, "utf-8")

try:
smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 465为SMTP_SSL默认端口
smtpObj.login(mail_sender, mail_key)
smtpObj.sendmail(
mail_sender,
self.config.content["Default"]["SelfSet.MailAddress"],
message.as_string(),
)
return True
except smtplib.SMTPException as e:
return f"发送邮件时出错:\n{e}"
finally:
smtpObj.quit()
if self.config.global_config.get(self.config.global_config.notify_IfSendMail):

# 第三方 SMTP 服务配置
mail_host = "smtp.163.com" # 设置服务器
mail_sender = "[email protected]" # 用户名
mail_key = "SYrq87nDLD4RNB5T" # 授权码 24/11/15

# 定义邮件正文
message = MIMEText(content, "plain", "utf-8")
message["From"] = formataddr(
(
Header("AUTO_MAA通知服务", "utf-8").encode(),
"[email protected]",
)
) # 发件人显示的名字
message["To"] = formataddr(
(
Header("AUTO_MAA用户", "utf-8").encode(),
self.config.global_config.get(
self.config.global_config.notify_MailAddress
),
)
) # 收件人显示的名字
message["Subject"] = Header(title, "utf-8")

try:
smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 465为SMTP_SSL默认端口
smtpObj.login(mail_sender, mail_key)
smtpObj.sendmail(
mail_sender,
self.config.global_config.get(
self.config.global_config.notify_MailAddress
),
message.as_string(),
)
return True
except smtplib.SMTPException as e:
return f"发送邮件时出错:\n{e}"
finally:
smtpObj.quit()
2 changes: 1 addition & 1 deletion app/services/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

"""
AUTO_MAA
AUTO_MAA主程序
AUTO_MAA安全服务
v4.2
作者:DLmaster_361
"""
Expand Down
Loading

0 comments on commit 684211c

Please sign in to comment.