forked from moesnow/March7thAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
148 lines (117 loc) · 3.99 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
import sys
# 将当前工作目录设置为程序所在的目录,确保无论从哪里执行,其工作目录都正确设置为程序本身的位置,避免路径错误。
os.chdir(os.path.dirname(sys.executable) if getattr(sys, 'frozen', False)else os.path.dirname(os.path.abspath(__file__)))
import pyuac
if not pyuac.isUserAdmin():
try:
pyuac.runAsAdmin(False)
sys.exit(0)
except Exception:
sys.exit(1)
import atexit
import base64
from module.config import cfg
from module.logger import log
from module.notification import notif
from module.ocr import ocr
import tasks.game as game
import tasks.reward as reward
import tasks.challenge as challenge
import tasks.tool as tool
import tasks.version as version
from tasks.daily.daily import Daily
from tasks.daily.fight import Fight
from tasks.power.power import Power
from tasks.weekly.universe import Universe
def first_run():
if not cfg.get_value(base64.b64decode("YXV0b191cGRhdGU=").decode("utf-8")):
log.error("首次使用请先打开图形界面")
input("按回车键关闭窗口. . .")
sys.exit(0)
def run_main_actions():
while True:
version.start()
game.start()
reward.start_specific("dispatch")
Daily.start()
reward.start()
game.stop(True)
def run_sub_task(action):
game.start()
sub_tasks = {
"daily": lambda: (Daily.run(), reward.start()),
"power": Power.run,
"fight": Fight.start,
"universe": Universe.start,
"forgottenhall": lambda: challenge.start("memoryofchaos"),
"purefiction": lambda: challenge.start("purefiction")
}
task = sub_tasks.get(action)
if task:
task()
game.stop(False)
def run_sub_task_gui(action):
gui_tasks = {
"universe_gui": Universe.gui,
"fight_gui": Fight.gui
}
task = gui_tasks.get(action)
if task and not task():
input("按回车键关闭窗口. . .")
sys.exit(0)
def run_sub_task_update(action):
update_tasks = {
"universe_update": Universe.update,
"fight_update": Fight.update
}
task = update_tasks.get(action)
if task:
task()
input("按回车键关闭窗口. . .")
sys.exit(0)
def run_notify_action():
notif.notify(cfg.notify_template['TestMessage'], "./assets/app/images/March7th.jpg")
input("按回车键关闭窗口. . .")
sys.exit(0)
def main(action=None):
first_run()
# 完整运行
if action is None or action == "main":
run_main_actions()
# 子任务
elif action in ["daily", "power", "fight", "universe", "forgottenhall", "purefiction"]:
run_sub_task(action)
# 子任务 原生图形界面
elif action in ["universe_gui", "fight_gui"]:
run_sub_task_gui(action)
# 子任务 更新项目
elif action in ["universe_update", "fight_update"]:
run_sub_task_update(action)
elif action in ["screenshot", "plot"]:
tool.start(action)
elif action == "game":
game.start()
elif action == "notify":
run_notify_action()
else:
log.error(f"未知任务: {action}")
input("按回车键关闭窗口. . .")
sys.exit(1)
# 程序结束时的处理器
def exit_handler():
"""注册程序退出时的处理函数,用于清理OCR资源."""
ocr.exit_ocr()
if __name__ == "__main__":
try:
atexit.register(exit_handler)
main(sys.argv[1]) if len(sys.argv) > 1 else main()
except KeyboardInterrupt:
log.error("发生错误: 手动强制停止")
input("按回车键关闭窗口. . .")
sys.exit(1)
except Exception as e:
log.error(cfg.notify_template['ErrorOccurred'].format(error=e))
notif.notify(cfg.notify_template['ErrorOccurred'].format(error=e))
input("按回车键关闭窗口. . .")
sys.exit(1)