S122 AstrBot Star主类兼容

这个提交存在于:
YokiiroBW 2026-07-06 09:26:29 +08:00
父节点 d0c4a8fe0e
当前提交 ce03556fa8
共有 2 个文件被更改,包括 59 次插入 和 1 次删除

50
main.py
查看文件

@ -29,6 +29,22 @@ from core.identity import RequestContext
PLUGIN_NAME = "astrbot_plugin_imagestudio"
PLUGIN_DESC = "AstrBot ImageStudio role asset production and image-generation workspace."
PLUGIN_VERSION = "3.0.0"
try:
from astrbot.api.star import Star as AstrBotStar
from astrbot.api.star import register as astrbot_star_register
except Exception: # pragma: no cover - AstrBot is only present in runtime.
class AstrBotStar: # type: ignore[no-redef]
def __init__(self, context: Any | None = None, *args: Any, **kwargs: Any) -> None:
self.context = context
def astrbot_star_register(*args: Any, **kwargs: Any) -> Any:
def decorator(cls: type[Any]) -> type[Any]:
return cls
return decorator
def get_plugin_manifest() -> dict[str, Any]:
@ -62,3 +78,37 @@ def dispatch_web_request(
payload: dict[str, Any] | None = None,
) -> dict[str, Any]:
return dispatch_extension_request(ctx, method, path, query=query, payload=payload)
def _register_star_class(cls: type[Any]) -> type[Any]:
try:
return astrbot_star_register(PLUGIN_NAME, "YokiiroBW", PLUGIN_DESC, PLUGIN_VERSION)(cls)
except Exception:
return cls
@_register_star_class
class Main(AstrBotStar):
"""Minimal AstrBot plugin class for runtime discovery."""
def __init__(self, context: Any | None = None, *args: Any, **kwargs: Any) -> None:
try:
super().__init__(context, *args, **kwargs)
except TypeError:
try:
super().__init__(*args, **kwargs)
except TypeError:
super().__init__()
self.context = context
async def initialize(self) -> None:
return None
async def terminate(self) -> None:
return None
def get_plugin_manifest(self) -> dict[str, Any]:
return get_plugin_manifest()
def register_plugin(self, runtime: Any) -> dict[str, Any]:
return register_plugin(runtime)

查看文件

@ -4,7 +4,7 @@ import unittest
from backend.route_registry import ROUTES
from core.identity import RequestContext
from main import PLUGIN_NAME, dispatch_web_request, get_plugin_manifest, get_runtime_health, register_plugin
from main import Main, PLUGIN_NAME, dispatch_web_request, get_plugin_manifest, get_runtime_health, register_plugin
class PluginEntrypointTests(unittest.TestCase):
@ -51,6 +51,14 @@ class PluginEntrypointTests(unittest.TestCase):
self.assertEqual(len(runtime.mounts), 1)
self.assertTrue(get_runtime_health()["ok"])
def test_astrbot_main_class_exposes_manifest(self):
plugin = Main(context=object())
manifest = plugin.get_plugin_manifest()
self.assertEqual(manifest["plugin_name"], PLUGIN_NAME)
self.assertTrue(manifest["runtime"]["health"]["ok"])
if __name__ == "__main__":
unittest.main()