Skip to content

Commit 1848482

Browse files
committed
Merge branch 'dev'
2 parents 9f25ba1 + 7ffb013 commit 1848482

129 files changed

Lines changed: 3817 additions & 11126 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/api/setting.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
# Contact: DLmaster_361@163.com
2222

2323

24-
import os
25-
from pathlib import Path
26-
import shutil
2724
from fastapi import APIRouter, Body
2825
from app.core import Config
2926
from app.services import System, Notify

app/core/config.py

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979

8080
class AppConfig(GlobalConfig):
81-
VERSION = "v5.0.3"
81+
VERSION = "v5.0.4"
8282

8383
def __init__(self) -> None:
8484
super().__init__()
@@ -117,7 +117,13 @@ def __init__(self) -> None:
117117
self.server: Optional[uvicorn.Server] = None
118118
self.websocket: Optional[WebSocket] = None
119119
self.power_sign: Literal[
120-
"NoAction", "Shutdown", "ShutdownForce", "Hibernate", "Sleep", "KillSelf"
120+
"NoAction",
121+
"Shutdown",
122+
"ShutdownForce",
123+
"Reboot",
124+
"Hibernate",
125+
"Sleep",
126+
"KillSelf",
121127
] = "NoAction"
122128
self.temp_task: List[asyncio.Task] = []
123129

@@ -144,7 +150,7 @@ async def check_data(self) -> None:
144150
db = sqlite3.connect(self.database_path)
145151
cur = db.cursor()
146152
cur.execute("CREATE TABLE version(v text)")
147-
cur.execute("INSERT INTO version VALUES(?)", ("v1.10",))
153+
cur.execute("INSERT INTO version VALUES(?)", ("v1.11",))
148154
db.commit()
149155
cur.close()
150156
db.close()
@@ -155,7 +161,7 @@ async def check_data(self) -> None:
155161
cur.execute("SELECT * FROM version WHERE True")
156162
version = cur.fetchall()
157163

158-
if version[0][0] != "v1.10":
164+
if version[0][0] != "v1.11":
159165
logger.info(
160166
"数据文件版本更新开始",
161167
)
@@ -422,6 +428,30 @@ async def check_data(self) -> None:
422428
cur.execute("DELETE FROM version WHERE v = ?", ("v1.9",))
423429
cur.execute("INSERT INTO version VALUES(?)", ("v1.10",))
424430
db.commit()
431+
# v1.10-->v1.11
432+
if version[0][0] == "v1.10" or if_streaming:
433+
logger.info(
434+
"数据文件版本更新: v1.10-->v1.11",
435+
)
436+
if_streaming = True
437+
438+
if (Path.cwd() / "config/ScriptConfig.json").exists():
439+
data = (Path.cwd() / "config/ScriptConfig.json").read_text(
440+
encoding="utf-8"
441+
)
442+
data.replace("IfWakeUp", "IfStartUp")
443+
data.replace("IfAutoRoguelike", "IfRoguelike")
444+
data.replace("IfBase", "IfInfrast")
445+
data.replace("IfCombat", "IfFight")
446+
data.replace("IfMission", "IfAward")
447+
data.replace("IfRecruiting", "IfRecruit")
448+
(Path.cwd() / "config/ScriptConfig.json").write_text(
449+
data, encoding="utf-8"
450+
)
451+
452+
cur.execute("DELETE FROM version WHERE v = ?", ("v1.10",))
453+
cur.execute("INSERT INTO version VALUES(?)", ("v1.11",))
454+
db.commit()
425455

426456
cur.close()
427457
db.close()
@@ -1407,6 +1437,7 @@ def proxy(self) -> Optional[httpx.Proxy]:
14071437
async def get_stage_info(
14081438
self,
14091439
type: Literal[
1440+
"User",
14101441
"Today",
14111442
"ALL",
14121443
"Monday",
@@ -1441,15 +1472,17 @@ async def get_stage_info(
14411472
"Activity": json.loads(self.get("Data", "Stage")).get("Info", []),
14421473
"Resource": res_stage_info,
14431474
}
1444-
elif type == "Today":
1445-
data = json.loads(self.get("Data", "Stage")).get(
1446-
datetime.now(tz=UTC4).strftime("%A"), []
1447-
)
1475+
elif type == "User":
1476+
data = json.loads(self.get("Data", "Stage")).get("ALL", [])
14481477
for combox in data:
14491478
combox["label"] = RESOURCE_STAGE_DATE_TEXT.get(
14501479
combox["value"], combox["label"]
14511480
)
14521481
return data
1482+
elif type == "Today":
1483+
return json.loads(self.get("Data", "Stage")).get(
1484+
datetime.now(tz=UTC4).strftime("%A"), []
1485+
)
14531486
else:
14541487
return json.loads(self.get("Data", "Stage")).get(type, [])
14551488

@@ -1807,26 +1840,16 @@ async def save_maa_log(self, log_path: Path, logs: list, maa_result: str) -> boo
18071840
# 查找所有Fight任务的开始和结束位置
18081841
fight_tasks = []
18091842
for i, line in enumerate(logs):
1810-
if (
1811-
"开始任务: Fight" in line
1812-
or "开始任务: 刷理智" in line
1813-
or "开始任务: 理智作战" in line
1814-
):
1843+
if "开始任务: Fight" in line or "开始任务: 理智作战" in line:
18151844
# 查找对应的任务结束位置
18161845
end_index = -1
18171846
for j in range(i + 1, len(logs)):
1818-
if (
1819-
"完成任务: Fight" in logs[j]
1820-
or "完成任务: 刷理智" in logs[j]
1821-
or "完成任务: 理智作战" in logs[j]
1822-
):
1847+
if "完成任务: Fight" in logs[j] or "完成任务: 理智作战" in logs[j]:
18231848
end_index = j
18241849
break
18251850
# 如果遇到新的Fight任务开始, 则当前任务没有正常结束
18261851
if j < len(logs) and (
1827-
"开始任务: Fight" in logs[j]
1828-
or "开始任务: 刷理智" in logs[j]
1829-
or "开始任务: 理智作战" in logs[j]
1852+
"开始任务: Fight" in logs[j] or "开始任务: 理智作战" in logs[j]
18301853
):
18311854
break
18321855

app/core/emulator_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ async def get_emulator_instance(self, emulator_id: str) -> DeviceBase:
7878
raise ValueError(f"不支持的模拟器类型: {config.get('Data', 'Type')}")
7979

8080
async def operate_emulator(
81-
self, operate: Literal["open", "close"], emulator_id: str, index: str
81+
self, operate: Literal["open", "close", "show"], emulator_id: str, index: str
8282
):
8383

8484
asyncio.create_task(self.operate_emulator_task(operate, emulator_id, index))
8585

8686
async def operate_emulator_task(
87-
self, operate: Literal["open", "close"], emulator_id: str, index: str
87+
self, operate: Literal["open", "close", "show"], emulator_id: str, index: str
8888
):
8989

9090
try:
@@ -96,6 +96,8 @@ async def operate_emulator_task(
9696
await temp_emulator.open(index)
9797
elif operate == "close":
9898
await temp_emulator.close(index)
99+
elif operate == "show":
100+
await temp_emulator.setVisible(index, True)
99101
except Exception as e:
100102
await Config.send_websocket_message(
101103
id="EmulatorManager",

app/core/timer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ async def timed_start(self):
7575
"""定时启动代理任务"""
7676

7777
curtime = datetime.now().strftime("%Y-%m-%d %H:%M")
78+
curday = datetime.now().strftime("%A")
7879

7980
for uid, queue in Config.QueueConfig.items():
8081

@@ -86,8 +87,10 @@ async def timed_start(self):
8687
continue
8788

8889
for time_set in queue.TimeSet.values():
89-
if time_set.get("Info", "Enabled") and curtime[11:16] == time_set.get(
90-
"Info", "Time"
90+
if (
91+
time_set.get("Info", "Enabled")
92+
and curday in time_set.get("Info", "Days")
93+
and curtime[11:16] == time_set.get("Info", "Time")
9194
):
9295
logger.info(f"定时唤起任务:{uid}")
9396
task_id = await TaskManager.add_task("AutoProxy", str(uid))

app/models/ConfigBase.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ def correct(self, value: Any) -> Any:
8888
return value if self.validate(value) else self.options[0]
8989

9090

91+
class MultipleOptionsValidator(ConfigValidator):
92+
"""多选选项验证器"""
93+
94+
def __init__(self, options: list):
95+
if not options:
96+
raise ValueError("可选项不能为空")
97+
98+
self.options = options
99+
100+
def validate(self, value: Any) -> bool:
101+
if not isinstance(value, list):
102+
return False
103+
104+
return all(item in self.options for item in value)
105+
106+
def correct(self, value: Any) -> Any:
107+
return value if self.validate(value) else []
108+
109+
91110
class UUIDValidator(ConfigValidator):
92111
"""UUID验证器"""
93112

app/models/config.py

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# Contact: DLmaster_361@163.com
2020

2121

22-
import re
2322
import uuid
2423
import json
2524
import calendar
@@ -34,6 +33,7 @@
3433
MultipleUIDValidator,
3534
BoolValidator,
3635
OptionsValidator,
36+
MultipleOptionsValidator,
3737
RangeValidator,
3838
VirtualConfigValidator,
3939
FileValidator,
@@ -137,8 +137,15 @@ def __init__(self) -> None:
137137

138138
## Info ------------------------------------------------------------
139139
## 是否启用
140-
self.Info_Enabled = ConfigItem("Info", "Enabled", False, BoolValidator())
141-
## 时间点
140+
self.Info_Enabled = ConfigItem("Info", "Enabled", True, BoolValidator())
141+
## 执行周期
142+
self.Info_Days = ConfigItem(
143+
"Info",
144+
"Days",
145+
list(calendar.day_name),
146+
MultipleOptionsValidator(list(calendar.day_name)),
147+
)
148+
## 执行时间
142149
self.Info_Time = ConfigItem("Info", "Time", "00:00", DateTimeValidator("%H:%M"))
143150

144151

@@ -167,11 +174,12 @@ def __init__(self) -> None:
167174
OptionsValidator(
168175
[
169176
"NoAction",
170-
"KillSelf",
171-
"Sleep",
172-
"Hibernate",
173177
"Shutdown",
174178
"ShutdownForce",
179+
"Reboot",
180+
"Hibernate",
181+
"Sleep",
182+
"KillSelf",
175183
]
176184
),
177185
)
@@ -295,10 +303,6 @@ def __init__(self) -> None:
295303
self.Data_LastProxyDate = ConfigItem(
296304
"Data", "LastProxyDate", "2000-01-01", DateTimeValidator("%Y-%m-%d")
297305
)
298-
## 上次剿灭日期
299-
self.Data_LastAnnihilationDate = ConfigItem(
300-
"Data", "LastAnnihilationDate", "2000-01-01", DateTimeValidator("%Y-%m-%d")
301-
)
302306
## 上次森空岛签到日期
303307
self.Data_LastSklandDate = ConfigItem(
304308
"Data", "LastSklandDate", "2000-01-01", DateTimeValidator("%Y-%m-%d")
@@ -315,23 +319,21 @@ def __init__(self) -> None:
315319
)
316320

317321
## Task ------------------------------------------------------------
318-
## 是否 自动唤醒
319-
self.Task_IfWakeUp = ConfigItem("Task", "IfWakeUp", True, BoolValidator())
320-
## 是否公招
321-
self.Task_IfRecruiting = ConfigItem(
322-
"Task", "IfRecruiting", True, BoolValidator()
323-
)
324-
## 是否基建
325-
self.Task_IfBase = ConfigItem("Task", "IfBase", True, BoolValidator())
326-
## 是否刷图
327-
self.Task_IfCombat = ConfigItem("Task", "IfCombat", True, BoolValidator())
328-
## 是否商店
322+
## 是否自动唤醒
323+
self.Task_IfStartUp = ConfigItem("Task", "IfStartUp", True, BoolValidator())
324+
## 是否理智作战
325+
self.Task_IfFight = ConfigItem("Task", "IfFight", True, BoolValidator())
326+
## 是否基建换班
327+
self.Task_IfInfrast = ConfigItem("Task", "IfInfrast", True, BoolValidator())
328+
## 是否公开招募
329+
self.Task_IfRecruit = ConfigItem("Task", "IfRecruit", True, BoolValidator())
330+
## 是否信用收支
329331
self.Task_IfMall = ConfigItem("Task", "IfMall", True, BoolValidator())
330-
## 是否任务
331-
self.Task_IfMission = ConfigItem("Task", "IfMission", True, BoolValidator())
332+
## 是否领取奖励
333+
self.Task_IfAward = ConfigItem("Task", "IfAward", True, BoolValidator())
332334
## 是否自动肉鸽
333-
self.Task_IfAutoRoguelike = ConfigItem(
334-
"Task", "IfAutoRoguelike", False, BoolValidator()
335+
self.Task_IfRoguelike = ConfigItem(
336+
"Task", "IfRoguelike", False, BoolValidator()
335337
)
336338
## 是否生息演算
337339
self.Task_IfReclamation = ConfigItem(
@@ -455,9 +457,9 @@ def __init__(self) -> None:
455457
self.Run_RoutineTimeLimit = ConfigItem(
456458
"Run", "RoutineTimeLimit", 10, RangeValidator(1, 9999)
457459
)
458-
## 是否限制剿灭每周一次
459-
self.Run_AnnihilationWeeklyLimit = ConfigItem(
460-
"Run", "AnnihilationWeeklyLimit", True, BoolValidator()
460+
## 剿灭避免无代理卡浪费理智
461+
self.Run_AnnihilationAvoidWaste = ConfigItem(
462+
"Run", "AnnihilationAvoidWaste", False, BoolValidator()
461463
)
462464

463465
self.UserData = MultipleConfig([MaaUserConfig])
@@ -479,16 +481,7 @@ def __init__(self) -> None:
479481

480482
self.config_item_dict: dict[str, dict[str, ConfigItem]] = {}
481483

482-
for group in [
483-
"ALL",
484-
"Monday",
485-
"Tuesday",
486-
"Wednesday",
487-
"Thursday",
488-
"Friday",
489-
"Saturday",
490-
"Sunday",
491-
]:
484+
for group in ["ALL", *calendar.day_name]:
492485
self.config_item_dict[group] = {}
493486

494487
## 理智药数量

0 commit comments

Comments
 (0)