This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy path__main__.py
148 lines (131 loc) · 4.26 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
# -*- coding=UTF-8 -*-
# pyright: strict
"""umamusume pretty derby automation. """
import argparse
import logging
import logging.handlers
import os
import time
import traceback
import warnings
import webbrowser
import win32con
import win32gui
from . import __version__, app, clients, config, jobs, plugin, templates, version
from .infrastructure.client_device_service import ClientDeviceService
from .infrastructure.logging_log_service import LoggingLogService
from .infrastructure.multi_log_service import MultiLogService
from .infrastructure.web_log_service import WebLogService
def main():
app.log.text(f"auto_derby: {__version__.VERSION}")
if config.CHECK_UPDATE:
version.check_update()
available_jobs = {
"team_race": jobs.team_race,
"champions_meeting": jobs.champions_meeting,
"legend_race": jobs.legend_race,
"nurturing": jobs.nurturing,
"daily_race_money": lambda: jobs.daily_race(templates.MOONLIGHT_PRIZE),
"daily_race_sp": lambda: jobs.daily_race(templates.JUPITER_CUP),
"roulette_derby": jobs.roulette_derby,
}
parser = argparse.ArgumentParser()
parser.add_argument("job")
parser.add_argument(
"-p",
"--plugin",
nargs="+",
default=config.PLUGINS,
help="plugin names to enable",
)
parser.add_argument(
"--adb",
help="adb connect address like `127.0.0.1:5037`",
default=config.ADB_ADDRESS,
)
args = parser.parse_args()
job = available_jobs.get(args.job)
config.ADB_ADDRESS = args.adb
def _client() -> clients.Client:
if config.ADB_ADDRESS:
return clients.ADBClient(config.ADB_ADDRESS)
else:
c = clients.DMMClient.find()
if not c:
if (
win32gui.MessageBox(
0,
"Launch DMM umamusume?",
"Can not found window",
win32con.MB_YESNO,
)
== 6
):
webbrowser.open("dmmgameplayer://umamusume/cl/general/umamusume")
while not c:
time.sleep(1)
app.log.text("waiting game launch")
c = clients.DMMClient.find()
app.log.text("game window: %s" % c.h_wnd)
else:
exit(1)
return c
plugin.reload()
config.client = _client
plugins = args.plugin
for i in plugins:
plugin.install(i)
config.apply()
with app.cleanup as cleanup:
if not config.web_log_disabled:
app.log = MultiLogService(
app.log,
WebLogService(cleanup),
)
time.sleep(1) # wait browser
if not job:
app.log.text(
"unknown job: %s\navailable jobs:\n %s"
% (args.job, "\n ".join(available_jobs.keys())),
level=app.ERROR,
)
exit(1)
c = config.client()
c.setup()
app.device = ClientDeviceService(c)
job()
if __name__ == "__main__":
logging.basicConfig(
format="%(levelname)-6s[%(asctime)s]:%(name)s:%(lineno)d: %(message)s",
level=logging.INFO,
datefmt="%H:%M:%S",
)
app.log = LoggingLogService()
LOG_PATH = config.LOG_PATH
if LOG_PATH and LOG_PATH != "-":
handler = logging.handlers.RotatingFileHandler(
LOG_PATH, backupCount=3, encoding="utf-8"
)
handler.doRollover()
formatter = logging.Formatter(
"%(levelname)-6s[%(asctime)s]:%(name)s:%(lineno)d: %(message)s",
"%Y-%m-%d %H:%M:%S",
)
handler.setFormatter(formatter)
logging.root.addHandler(handler)
for i in os.getenv("DEBUG", "").split(","):
if not i:
continue
logging.getLogger(i).setLevel(logging.DEBUG)
warnings.filterwarnings("once", module="auto_derby(\\..*)?")
try:
main()
except SystemExit:
raise
except:
app.log.text(
"unexpected exception: %s" % traceback.format_exc(), level=app.ERROR
)
exit(1)
# DEPRECATED
globals()["LOGGER"] = logging.getLogger(__name__)