Compare commits
4 Commits
ac68bb27a3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 89de330e2d | |||
| cd54036ab7 | |||
| 9cb259f2c7 | |||
| ca3cf114e3 |
@@ -80,7 +80,7 @@ class PluginInterface(ABC):
|
|||||||
config.Log("Error", f"{ConsoleFrontColor.RED}提交表 {db_model.table_name} 列更新失败: {e}{ConsoleFrontColor.RESET}")
|
config.Log("Error", f"{ConsoleFrontColor.RED}提交表 {db_model.table_name} 列更新失败: {e}{ConsoleFrontColor.RESET}")
|
||||||
|
|
||||||
@final
|
@final
|
||||||
def execute(self, path:str) -> Optional[APIRouter]:
|
def execute(self) -> Optional[APIRouter]:
|
||||||
'''
|
'''
|
||||||
继承后是否返回路由决定是否启动该插件
|
继承后是否返回路由决定是否启动该插件
|
||||||
若返回None, 则不启动该插件
|
若返回None, 则不启动该插件
|
||||||
@@ -100,16 +100,22 @@ class PluginInterface(ABC):
|
|||||||
|
|
||||||
Architecture.Register(self.__class__, self, setup, *self.dependencies())
|
Architecture.Register(self.__class__, self, setup, *self.dependencies())
|
||||||
router = APIRouter()
|
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
|
return router
|
||||||
|
|
||||||
def generate_router_callback(self) -> Callable|Coroutine:
|
def generate_router_callback(self) -> Callable|Coroutine:
|
||||||
'''
|
'''
|
||||||
继承后重写该方法生成路由回调函数
|
继承后重写该方法生成路由回调函数
|
||||||
'''
|
'''
|
||||||
async def callback(message: str, chat_id: int, user_id: int) -> Any:
|
return self.callback
|
||||||
return await self.callback(message, chat_id, user_id)
|
|
||||||
return callback
|
def generate_router_illustrated_guide(self) -> Callable|Coroutine|None:
|
||||||
|
'''
|
||||||
|
继承后重写该方法生成渲染图鉴与攻略网页的函数
|
||||||
|
'''
|
||||||
|
return None
|
||||||
|
|
||||||
def dependencies(self) -> List[Type]:
|
def dependencies(self) -> List[Type]:
|
||||||
'''
|
'''
|
||||||
@@ -218,7 +224,7 @@ def ImportPlugins(app: FastAPI, plugin_dir:str = "Plugins") -> None:
|
|||||||
plugin = plugin_class()
|
plugin = plugin_class()
|
||||||
if plugin.is_enable_plugin() == False:
|
if plugin.is_enable_plugin() == False:
|
||||||
continue
|
continue
|
||||||
router = plugin.execute(f"/{module_file.GetFullPath().replace(".py", '')}/{class_name}")
|
router = plugin.execute()
|
||||||
if router:
|
if router:
|
||||||
app.include_router(router, prefix=f"/api", tags=[plugin.get_plugin_tag()])
|
app.include_router(router, prefix=f"/api", tags=[plugin.get_plugin_tag()])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -116,6 +116,9 @@ async def handle_command(command: str, message: str,
|
|||||||
if plugin:
|
if plugin:
|
||||||
logger.Log("Info", f"已找到插件注册指令: {command}, class: {plugin.__class__.__name__}")
|
logger.Log("Info", f"已找到插件注册指令: {command}, class: {plugin.__class__.__name__}")
|
||||||
return await plugin.callback(message, chat_id, user_id)
|
return await plugin.callback(message, chat_id, user_id)
|
||||||
|
elif "default" in PluginInterface.plugin_instances:
|
||||||
|
logger.Log("Info", f"未找到插件注册指令: {command}, 使用默认插件: {PluginInterface.plugin_instances["default"].__class__.__name__}")
|
||||||
|
return await PluginInterface.plugin_instances["default"].callback(command+" "+message, chat_id, user_id)
|
||||||
else:
|
else:
|
||||||
return f"❌ 未识别指令: {command}"
|
return f"❌ 未识别指令: {command}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
3
swagger-ui-bundle.js
Normal file
3
swagger-ui-bundle.js
Normal file
File diff suppressed because one or more lines are too long
3
swagger-ui.css
Normal file
3
swagger-ui.css
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user