From 9cb259f2c71f5814062c8aeae3cc83a90f0f9ec3 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Wed, 12 Nov 2025 22:58:07 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E5=8F=AF=E9=80=89=E7=9A=84?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E7=BD=91=E9=A1=B52.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreModules/plugin_interface.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/CoreModules/plugin_interface.py b/CoreModules/plugin_interface.py index e5e9808..b7609c7 100644 --- a/CoreModules/plugin_interface.py +++ b/CoreModules/plugin_interface.py @@ -80,7 +80,7 @@ class PluginInterface(ABC): config.Log("Error", f"{ConsoleFrontColor.RED}提交表 {db_model.table_name} 列更新失败: {e}{ConsoleFrontColor.RESET}") @final - def execute(self, path:str) -> Optional[APIRouter]: + def execute(self) -> Optional[APIRouter]: ''' 继承后是否返回路由决定是否启动该插件 若返回None, 则不启动该插件 @@ -100,16 +100,22 @@ class PluginInterface(ABC): Architecture.Register(self.__class__, self, setup, *self.dependencies()) router = APIRouter() - router.post(path)(self.generate_router_callback()) + router.post(f"/{self.__class__.__name__}/callback")(self.generate_router_callback()) + if self.generate_router_illustrated_guide() is not None: + router.get(f"/{self.__class__.__name__}")(self.generate_router_illustrated_guide()) return router def generate_router_callback(self) -> Callable|Coroutine: ''' 继承后重写该方法生成路由回调函数 ''' - async def callback(message: str, chat_id: int, user_id: int) -> Any: - return await self.callback(message, chat_id, user_id) - return callback + return self.callback + + def generate_router_illustrated_guide(self) -> Callable|Coroutine|None: + ''' + 继承后重写该方法生成渲染图鉴与攻略网页的函数 + ''' + return None def dependencies(self) -> List[Type]: ''' @@ -218,7 +224,7 @@ def ImportPlugins(app: FastAPI, plugin_dir:str = "Plugins") -> None: plugin = plugin_class() if plugin.is_enable_plugin() == False: continue - router = plugin.execute(f"/{module_file.GetFullPath().replace(".py", '')}/{class_name}") + router = plugin.execute() if router: app.include_router(router, prefix=f"/api", tags=[plugin.get_plugin_tag()]) except Exception as e: