add 插件API

This commit is contained in:
jxxghp
2023-06-18 10:22:14 +08:00
parent c0ea8097f8
commit 5dd7878e1b
17 changed files with 146 additions and 83 deletions

View File

@ -1,9 +1,9 @@
from types import FunctionType
from typing import Generator, Optional
from app.core.config import settings
from app.helper.module import ModuleHelper
from app.log import logger
from app.utils.object import ObjectUtils
from app.utils.singleton import Singleton
@ -68,16 +68,9 @@ class ModuleManager(metaclass=Singleton):
"""
获取模块列表
"""
def check_method(func: FunctionType) -> bool:
"""
检查函数是否已实现
"""
return func.__code__.co_code != b'd\x01S\x00'
if not self._running_modules:
return []
for _, module in self._running_modules.items():
if hasattr(module, method) \
and check_method(getattr(module, method)):
and ObjectUtils.check_method(getattr(module, method)):
yield module