Merge pull request #2 from HendricksJudy/codex/fix-core-initialization-failure-handling-in-initialloader

Fix initialization bug and improve plugin utility
This commit is contained in:
HendricksJudy
2025-05-19 01:43:22 -07:00
committed by GitHub
2 changed files with 11 additions and 4 deletions
+8 -2
View File
@@ -59,7 +59,13 @@ def get_git_repo(url: str, target_path: Path, proxy: str | None = None):
proxy=proxy if proxy else None, follow_redirects=True
) as client:
resp = client.get(download_url)
resp.raise_for_status()
if resp.status_code == 404 and "archive/refs/heads/master.zip" in download_url:
alt_url = download_url.replace("master.zip", "main.zip")
click.echo("master 分支不存在,尝试下载 main 分支")
resp = client.get(alt_url)
resp.raise_for_status()
else:
resp.raise_for_status()
zip_content = BytesIO(resp.content)
with ZipFile(zip_content) as z:
z.extractall(temp_dir)
@@ -106,7 +112,7 @@ def extract_py_metadata(plugin_dir: Path) -> dict:
try:
content = py_file.read_text(encoding="utf-8")
register_match = re.search(
r'@register_star\s*\(\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*"([^"]+)"(?:\s*,\s*"?([^")]+)"?)?\s*\)',
r'@register(?:_star)?\s*\(\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*"([^"]+)"(?:\s*,\s*"?([^")]+)"?)?\s*\)',
content,
)
if register_match:
+3 -2
View File
@@ -26,13 +26,14 @@ class InitialLoader:
async def start(self):
core_lifecycle = AstrBotCoreLifecycle(self.log_broker, self.db)
core_task = []
try:
await core_lifecycle.initialize()
core_task = core_lifecycle.start()
except Exception as e:
logger.critical(traceback.format_exc())
logger.critical(f"😭 初始化 AstrBot 失败:{e} !!!")
return
core_task = core_lifecycle.start()
self.dashboard_server = AstrBotDashboard(
core_lifecycle, self.db, core_lifecycle.dashboard_shutdown_event