插件元信息,由插件编写者提供
| 25 | |
| 26 | @dataclass(eq=False) |
| 27 | class PluginMetadata: |
| 28 | """插件元信息,由插件编写者提供""" |
| 29 | |
| 30 | name: str |
| 31 | """插件名称""" |
| 32 | description: str |
| 33 | """插件功能介绍""" |
| 34 | usage: str |
| 35 | """插件使用方法""" |
| 36 | type: str | None = None |
| 37 | """插件类型,用于商店分类""" |
| 38 | homepage: str | None = None |
| 39 | """插件主页""" |
| 40 | config: Type[BaseModel] | None = None # noqa: UP006 |
| 41 | """插件配置项""" |
| 42 | supported_adapters: set[str] | None = None |
| 43 | """插件支持的适配器模块路径 |
| 44 | |
| 45 | 格式为 `<module>[:<Adapter>]`,`~` 为 `nonebot.adapters.` 的缩写。 |
| 46 | |
| 47 | `None` 表示支持**所有适配器**。 |
| 48 | """ |
| 49 | extra: dict[Any, Any] = field(default_factory=dict) |
| 50 | """插件额外信息,可由插件编写者自由扩展定义""" |
| 51 | |
| 52 | def get_supported_adapters(self) -> set[Type["Adapter"]] | None: # noqa: UP006 |
| 53 | """获取当前已安装的插件支持适配器类列表""" |
| 54 | if self.supported_adapters is None: |
| 55 | return None |
| 56 | |
| 57 | adapters = set() |
| 58 | for adapter in self.supported_adapters: |
| 59 | with contextlib.suppress(ModuleNotFoundError, AttributeError): |
| 60 | adapters.add( |
| 61 | resolve_dot_notation(adapter, "Adapter", "nonebot.adapters.") |
| 62 | ) |
| 63 | return adapters |
| 64 | |
| 65 | |
| 66 | @dataclass(eq=False) |
no outgoing calls
no test coverage detected