starrailassistant 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- SRACore/__init__.py +1 -0
- SRACore/__main__.py +218 -0
- SRACore/assets/background.default.jpg +0 -0
- SRACore/cli2.py +618 -0
- SRACore/extension/__init__.py +741 -0
- SRACore/extension/locales.py +102 -0
- SRACore/localization/__init__.py +3 -0
- SRACore/localization/resources.py +1150 -0
- SRACore/localization/resources.toml +767 -0
- SRACore/localization/resources_en-us.json +155 -0
- SRACore/localization/resources_ru-ru.json +155 -0
- SRACore/localization/resources_zh-cn.json +155 -0
- SRACore/localization/terms.en-us.json +210 -0
- SRACore/localization/terms.py +73 -0
- SRACore/localization/terms.ru-ru.json +210 -0
- SRACore/localization/terms.zh-cn.json +210 -0
- SRACore/models/__init__.py +0 -0
- SRACore/models/app_settings.py +207 -0
- SRACore/models/tasks_config.py +180 -0
- SRACore/notification/__init__.py +21 -0
- SRACore/notification/channels/__init__.py +33 -0
- SRACore/notification/channels/bark.py +43 -0
- SRACore/notification/channels/base.py +15 -0
- SRACore/notification/channels/common.py +44 -0
- SRACore/notification/channels/dingtalk.py +50 -0
- SRACore/notification/channels/discord.py +56 -0
- SRACore/notification/channels/email.py +65 -0
- SRACore/notification/channels/feishu.py +51 -0
- SRACore/notification/channels/onebot.py +54 -0
- SRACore/notification/channels/serverchan.py +30 -0
- SRACore/notification/channels/system.py +30 -0
- SRACore/notification/channels/telegram.py +50 -0
- SRACore/notification/channels/webhook.py +20 -0
- SRACore/notification/channels/wecom.py +63 -0
- SRACore/notification/channels/xxtui.py +28 -0
- SRACore/notification/dispatcher.py +40 -0
- SRACore/notification/http_client.py +112 -0
- SRACore/notification/models.py +29 -0
- SRACore/notification/service.py +218 -0
- SRACore/operators/__init__.py +0 -0
- SRACore/operators/browser_operator.py +717 -0
- SRACore/operators/color_detector.py +382 -0
- SRACore/operators/factory.py +76 -0
- SRACore/operators/ioperator.py +1002 -0
- SRACore/operators/model.py +86 -0
- SRACore/operators/operator.py +520 -0
- SRACore/runtime/__init__.py +3 -0
- SRACore/runtime/event_listener.py +143 -0
- SRACore/services/__init__.py +33 -0
- SRACore/services/app_context.py +356 -0
- SRACore/services/app_info_service.py +152 -0
- SRACore/services/backend_service.py +51 -0
- SRACore/services/cache_service.py +61 -0
- SRACore/services/config_service.py +189 -0
- SRACore/services/log_stream.py +61 -0
- SRACore/services/setting_service.py +88 -0
- SRACore/task/__init__.py +165 -0
- SRACore/thread/__init__.py +2 -0
- SRACore/thread/runner.py +182 -0
- SRACore/thread/task_process.py +340 -0
- SRACore/util/__init__.py +72 -0
- SRACore/util/const.py +34 -0
- SRACore/util/data_persister.py +80 -0
- SRACore/util/encryption.py +55 -0
- SRACore/util/errors.py +238 -0
- SRACore/util/image_util.py +59 -0
- SRACore/util/logger.py +28 -0
- SRACore/util/standard_io.py +18 -0
- SRACore/util/strutil.py +62 -0
- SRACore/util/sys_util.py +117 -0
- SRACore/util/task_recovery.py +93 -0
- SRAServer/__init__.py +5 -0
- SRAServer/__main__.py +99 -0
- SRAServer/app.py +132 -0
- SRAServer/config.py +78 -0
- SRAServer/context.py +141 -0
- SRAServer/controllers/__init__.py +28 -0
- SRAServer/controllers/_responses.py +23 -0
- SRAServer/controllers/app.py +28 -0
- SRAServer/controllers/auth.py +25 -0
- SRAServer/controllers/backend.py +81 -0
- SRAServer/controllers/configs.py +67 -0
- SRAServer/controllers/extensions.py +112 -0
- SRAServer/controllers/operator.py +44 -0
- SRAServer/controllers/settings.py +32 -0
- SRAServer/controllers/task.py +81 -0
- SRAServer/mcp/__init__.py +1 -0
- SRAServer/mcp/server.py +335 -0
- SRAServer/middleware.py +66 -0
- SRAServer/openapi.py +47 -0
- SRAServer/schemas/__init__.py +1 -0
- SRAServer/schemas/envelope.py +23 -0
- SRAServer/schemas/requests.py +60 -0
- starrailassistant-0.0.0.dist-info/METADATA +206 -0
- starrailassistant-0.0.0.dist-info/RECORD +99 -0
- starrailassistant-0.0.0.dist-info/WHEEL +5 -0
- starrailassistant-0.0.0.dist-info/entry_points.txt +3 -0
- starrailassistant-0.0.0.dist-info/licenses/LICENSE +661 -0
- starrailassistant-0.0.0.dist-info/top_level.txt +2 -0
SRACore/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""StarRailAssistant Core - 崩坏:星穹铁道自动化助手"""
|
SRACore/__main__.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
sys.path.append(os.getcwd()) # 将当前工作目录添加到 sys.path,以便导入 tasks
|
|
7
|
+
|
|
8
|
+
from SRACore.localization import Resources
|
|
9
|
+
from SRACore.services.setting_service import SettingsService
|
|
10
|
+
from SRACore.util.const import VERSION, AppDataDir, CacheDir, ConfigsDir, LogsDir, SettingsJson
|
|
11
|
+
from SRACore.util.standard_io import configure_standard_streams
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main():
|
|
15
|
+
# Must precede argparse output and cmd2/Rich/logging stream capture.
|
|
16
|
+
configure_standard_streams()
|
|
17
|
+
settings = SettingsService()
|
|
18
|
+
language: int = settings.settings.Display.Language
|
|
19
|
+
Resources.set_language(language)
|
|
20
|
+
parser = argparse.ArgumentParser(
|
|
21
|
+
description=Resources.argparse_description,
|
|
22
|
+
epilog=Resources.argparse_epilog,
|
|
23
|
+
formatter_class=argparse.RawTextHelpFormatter
|
|
24
|
+
)
|
|
25
|
+
setup_argumentparser(parser)
|
|
26
|
+
# 解析参数
|
|
27
|
+
args = parser.parse_known_args()[0]
|
|
28
|
+
if args.subcommand:
|
|
29
|
+
if subcommand_handler(args.subcommand, args.rest):
|
|
30
|
+
return
|
|
31
|
+
if args.no_admin:
|
|
32
|
+
sys.argv.remove('--no-admin') # 移除参数,不向下传递(无论是否已是管理员)
|
|
33
|
+
if not is_admin():
|
|
34
|
+
if args.no_admin:
|
|
35
|
+
print(Resources.cli_noAdminWarning)
|
|
36
|
+
else:
|
|
37
|
+
restart_as_admin()
|
|
38
|
+
# 构造进程内宿主:统一负责日志、tasks/extensions 动态导入与任务/扩展编排
|
|
39
|
+
from SRACore.services import AppContext
|
|
40
|
+
context = AppContext(log_level=args.log_level)
|
|
41
|
+
from SRACore.util.logger import logger
|
|
42
|
+
logger.info(f"Current version: {VERSION}")
|
|
43
|
+
logger.debug(f"cwd: {os.getcwd()}")
|
|
44
|
+
|
|
45
|
+
if args.command:
|
|
46
|
+
for cmd in args.command:
|
|
47
|
+
sys.argv.remove(cmd) # 移除命令参数, 避免重复执行
|
|
48
|
+
cmd_str = " ".join(args.command).replace('&', '+')
|
|
49
|
+
commands = cmd_str.split('+')
|
|
50
|
+
for cmd in commands:
|
|
51
|
+
sys.argv.append(cmd)
|
|
52
|
+
print(sys.argv)
|
|
53
|
+
if args.inline:
|
|
54
|
+
sys.argv.remove('--inline')
|
|
55
|
+
# 延迟导入 SRACli
|
|
56
|
+
from SRACore.cli2 import SRACli
|
|
57
|
+
cli_instance = SRACli(context)
|
|
58
|
+
# 配置交互式模式(隐藏提示符)
|
|
59
|
+
if args.inline:
|
|
60
|
+
cli_instance.intro = ''
|
|
61
|
+
cli_instance.prompt = ''
|
|
62
|
+
cli_instance.cmdloop()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def setup_argumentparser(parser: argparse.ArgumentParser) -> None:
|
|
66
|
+
parser.add_argument(
|
|
67
|
+
'--inline',
|
|
68
|
+
action='store_true',
|
|
69
|
+
help=Resources.argparse_inline_help
|
|
70
|
+
)
|
|
71
|
+
parser.add_argument(
|
|
72
|
+
'--command', '-c', '--execute', '-e',
|
|
73
|
+
nargs='*',
|
|
74
|
+
type=str,
|
|
75
|
+
help=Resources.cli_argHelp_command,
|
|
76
|
+
)
|
|
77
|
+
parser.add_argument(
|
|
78
|
+
'-v', '--version',
|
|
79
|
+
action='version',
|
|
80
|
+
version=f'{VERSION}',
|
|
81
|
+
help=Resources.argparse_version_help
|
|
82
|
+
)
|
|
83
|
+
parser.add_argument(
|
|
84
|
+
'--log-level',
|
|
85
|
+
type=str,
|
|
86
|
+
choices=['TRACE', 'DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'],
|
|
87
|
+
default='TRACE',
|
|
88
|
+
help=Resources.argparse_log_level_help
|
|
89
|
+
)
|
|
90
|
+
parser.add_argument(
|
|
91
|
+
'--no-admin',
|
|
92
|
+
action='store_true',
|
|
93
|
+
help=Resources.cli_argHelp_noAdmin
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
parser.add_argument(
|
|
97
|
+
'subcommand',
|
|
98
|
+
type=str,
|
|
99
|
+
nargs='?',
|
|
100
|
+
default='',
|
|
101
|
+
metavar=f'{{{",".join(subcommands.keys())}}}',
|
|
102
|
+
help=Resources.cli_argHelp_subcommand
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
parser.add_argument(
|
|
106
|
+
'rest',
|
|
107
|
+
nargs=argparse.REMAINDER,
|
|
108
|
+
help=argparse.SUPPRESS
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def subcommand_handler(subcommand: str, rest: list) -> bool:
|
|
113
|
+
"""处理子命令"""
|
|
114
|
+
if subcommand in subcommands:
|
|
115
|
+
parser, func = subcommands[subcommand] # 值为 (解析器, 处理函数) 的单个元组
|
|
116
|
+
args = parser().parse_args(rest)
|
|
117
|
+
return func(args)
|
|
118
|
+
return False
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def where_parser() -> argparse.ArgumentParser:
|
|
122
|
+
"""返回路径查找解析器"""
|
|
123
|
+
parser = argparse.ArgumentParser(
|
|
124
|
+
prog=f'{os.path.basename(sys.argv[0])} where',
|
|
125
|
+
description=Resources.cli_argHelp_whereDescription,
|
|
126
|
+
)
|
|
127
|
+
parser.add_argument(
|
|
128
|
+
'path',
|
|
129
|
+
type=str,
|
|
130
|
+
nargs='?',
|
|
131
|
+
choices=['configs', 'logs', 'cache', 'data', 'settings', ''],
|
|
132
|
+
default='',
|
|
133
|
+
help=Resources.cli_argHelp_wherePath,
|
|
134
|
+
)
|
|
135
|
+
return parser
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def where(args: argparse.Namespace) -> bool:
|
|
139
|
+
"""查找路径"""
|
|
140
|
+
paths = {
|
|
141
|
+
'': sys.executable,
|
|
142
|
+
'configs': str(ConfigsDir),
|
|
143
|
+
'logs': str(LogsDir),
|
|
144
|
+
'cache': str(CacheDir),
|
|
145
|
+
'data': str(AppDataDir),
|
|
146
|
+
'settings': str(SettingsJson),
|
|
147
|
+
}
|
|
148
|
+
if args.path in paths:
|
|
149
|
+
print(paths[args.path])
|
|
150
|
+
else:
|
|
151
|
+
print(f'Unknown path: {args.path}, available paths: {",".join(paths.keys())}')
|
|
152
|
+
return True
|
|
153
|
+
|
|
154
|
+
def serve_parser() -> argparse.ArgumentParser:
|
|
155
|
+
"""返回服务器解析器"""
|
|
156
|
+
parser = argparse.ArgumentParser(
|
|
157
|
+
prog=f'{os.path.basename(sys.argv[0])} serve',
|
|
158
|
+
description=Resources.cli_argHelp_serverDescription,
|
|
159
|
+
)
|
|
160
|
+
parser.add_argument(
|
|
161
|
+
'--host',
|
|
162
|
+
action='store_true',
|
|
163
|
+
help=Resources.cli_argHelp_serverHost,
|
|
164
|
+
)
|
|
165
|
+
parser.add_argument(
|
|
166
|
+
'--port',
|
|
167
|
+
type=int,
|
|
168
|
+
default=None,
|
|
169
|
+
help=Resources.cli_argHelp_serverPort,
|
|
170
|
+
)
|
|
171
|
+
parser.add_argument(
|
|
172
|
+
'--no-webui',
|
|
173
|
+
action='store_true',
|
|
174
|
+
help=Resources.cli_argHelp_serverNoWebui,
|
|
175
|
+
)
|
|
176
|
+
return parser
|
|
177
|
+
|
|
178
|
+
def serve(args: argparse.Namespace) -> bool:
|
|
179
|
+
"""启动服务端(与 ``sra-server`` 共用 ``SRAServer.run_server``,进程内运行)。"""
|
|
180
|
+
from SRAServer.__main__ import run_server
|
|
181
|
+
run_server(host=args.host, port=args.port, webui=False if args.no_webui else None)
|
|
182
|
+
return True
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
subcommands = {
|
|
186
|
+
'where': (where_parser, where),
|
|
187
|
+
'serve': (serve_parser, serve),
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
# noinspection unresolved-references
|
|
192
|
+
def restart_as_admin():
|
|
193
|
+
"""以管理员权限重启当前进程"""
|
|
194
|
+
if sys.platform == 'win32' and not is_admin():
|
|
195
|
+
import ctypes
|
|
196
|
+
cmdline = subprocess.list2cmdline(sys.argv)
|
|
197
|
+
executable = sys.executable.removesuffix('.exe')
|
|
198
|
+
executable += '.exe'
|
|
199
|
+
# 保留当前工作目录:源码分发模式下 main.py、tasks/ 与 resources/ 均按 cwd 解析
|
|
200
|
+
cwd = os.getcwd()
|
|
201
|
+
result = ctypes.windll.shell32.ShellExecuteW(None, 'runas', 'wt.exe', f'"{executable}" {cmdline}', cwd, 1)
|
|
202
|
+
if result > 32:
|
|
203
|
+
sys.exit(0)
|
|
204
|
+
else:
|
|
205
|
+
result = ctypes.windll.shell32.ShellExecuteW(None, 'runas', executable, cmdline, cwd, 1)
|
|
206
|
+
sys.exit(result)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def is_admin() -> bool:
|
|
210
|
+
"""检查当前用户是否具有管理员权限(仅限 Windows)"""
|
|
211
|
+
if sys.platform == 'win32':
|
|
212
|
+
import ctypes
|
|
213
|
+
return ctypes.windll.shell32.IsUserAnAdmin() != 0 # NOQA
|
|
214
|
+
return True
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
if __name__ == '__main__':
|
|
218
|
+
main()
|
|
Binary file
|