MCPcopy
hub / github.com/AstrBotDevs/AstrBot / InitialLoader

Class InitialLoader

astrbot/core/initial_loader.py:17–57  ·  view source on GitHub ↗

AstrBot 启动器,负责初始化和启动核心组件和仪表板服务器。

Source from the content-addressed store, hash-verified

15
16
17class InitialLoader:
18 """AstrBot 启动器,负责初始化和启动核心组件和仪表板服务器。"""
19
20 def __init__(self, db: BaseDatabase, log_broker: LogBroker) -> None:
21 self.db = db
22 self.logger = logger
23 self.log_broker = log_broker
24 self.webui_dir: str | None = None
25
26 async def start(self) -> None:
27 core_lifecycle = AstrBotCoreLifecycle(self.log_broker, self.db)
28
29 try:
30 await core_lifecycle.initialize()
31 except Exception as e:
32 logger.critical(traceback.format_exc())
33 logger.critical(f"😭 初始化 AstrBot 失败:{e} !!!")
34 return
35
36 core_task = core_lifecycle.start()
37
38 webui_dir = self.webui_dir
39
40 self.dashboard_server = AstrBotDashboard(
41 core_lifecycle,
42 self.db,
43 core_lifecycle.dashboard_shutdown_event,
44 webui_dir,
45 )
46
47 coro = self.dashboard_server.run()
48 if coro:
49 # 启动核心任务和仪表板服务器
50 task = asyncio.gather(core_task, coro)
51 else:
52 task = core_task
53 try:
54 await task # 整个AstrBot在这里运行
55 except asyncio.CancelledError:
56 logger.info("🌈 正在关闭 AstrBot...")
57 await core_lifecycle.stop()

Callers 2

main_asyncFunction · 0.90
run_astrbotFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected