forked from moesnow/March7thAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
155 lines (123 loc) · 4.29 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
149
150
151
152
153
154
155
import os
import sys
os.chdir(os.path.dirname(sys.executable) if getattr(sys, 'frozen', False)
else os.path.dirname(os.path.abspath(__file__)))
from tasks.version.version import Version
from managers.notify_manager import notify
from managers.logger_manager import logger
from managers.config_manager import config
from managers.ocr_manager import ocr
from managers.translate_manager import _
from tasks.game.game import Game
from tasks.daily.daily import Daily
import tasks.activity as activity
import tasks.reward as reward
from tasks.daily.fight import Fight
from tasks.power.power import Power
from tasks.weekly.universe import Universe
from tasks.weekly.forgottenhall import ForgottenHall
from tasks.weekly.purefiction import PureFiction
from tasks.tools.game_screenshot import game_screenshot
from tasks.tools.automatic_plot import automatic_plot
import atexit
import pyuac
import sys
def agreed_to_disclaimer():
if not config.agreed_to_disclaimer:
logger.error(_("您尚未同意《免责声明》"))
input(_("按回车键关闭窗口. . ."))
sys.exit(0)
def run_main_actions():
while True:
Version.start()
Game.start()
activity.start()
Daily.start()
reward.start()
Game.stop(True)
def run_sub_task(action):
Game.start()
if action == "daily":
Daily.run()
reward.start()
elif action == "power":
Power.run()
elif action == "fight":
Fight.start()
elif action == "universe":
Universe.start()
elif action == "forgottenhall":
ForgottenHall.start()
PureFiction.start()
Game.stop(False)
def run_sub_task_gui(action):
if action == "universe_gui" and not Universe.gui():
input(_("按回车键关闭窗口. . ."))
elif action == "fight_gui" and not Fight.gui():
input(_("按回车键关闭窗口. . ."))
sys.exit(0)
def run_sub_task_update(action):
if action == "universe_update":
Universe.update()
elif action == "fight_update":
Fight.update()
input(_("按回车键关闭窗口. . ."))
sys.exit(0)
def run_notify_action():
from io import BytesIO
from PIL import Image
IMAGE_PATH = "./assets/app/images/March7th.jpg"
image_io = BytesIO()
Image.open(IMAGE_PATH).save(image_io, format='JPEG')
notify.notify(_("三月七小助手|・ω・)"), _("这是一条测试消息"), image_io)
input(_("按回车键关闭窗口. . ."))
sys.exit(0)
def main(action=None):
# 免责申明
agreed_to_disclaimer()
# 完整运行
if action is None or action == "main":
run_main_actions()
# 子任务
elif action in ["daily", "power", "fight", "universe", "forgottenhall"]:
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 == "screenshot":
game_screenshot()
elif action == "plot":
automatic_plot()
elif action == "notify":
run_notify_action()
else:
logger.error(_("未知任务: {action}").format(action=action))
input(_("按回车键关闭窗口. . ."))
sys.exit(1)
def exit_handler():
ocr.exit_ocr()
if __name__ == "__main__":
if not pyuac.isUserAdmin():
try:
pyuac.runAsAdmin(wait=False)
sys.exit(0)
except Exception:
logger.error(_("管理员权限获取失败"))
input(_("按回车键关闭窗口. . ."))
sys.exit(1)
else:
try:
atexit.register(exit_handler)
main(sys.argv[1]) if len(sys.argv) > 1 else main()
except KeyboardInterrupt:
logger.error(_("发生错误: 手动强制停止"))
input(_("按回车键关闭窗口. . ."))
sys.exit(1)
except Exception as e:
logger.error(_("发生错误: {e}").format(e=e))
notify.notify(_("发生错误: {e}").format(e=e))
input(_("按回车键关闭窗口. . ."))
sys.exit(1)