继承插件总基类,注释更新

This commit is contained in:
UnCLAS-Prommer
2025-07-17 00:28:14 +08:00
parent a83f8948e9
commit 696325cb57
5 changed files with 30 additions and 29 deletions

View File

@@ -21,3 +21,6 @@
- `config_api.py`中的`get_global_config``get_plugin_config`方法现在支持嵌套访问的配置键名。 - `config_api.py`中的`get_global_config``get_plugin_config`方法现在支持嵌套访问的配置键名。
- `database_api.py`中的`db_query`方法调整了参数顺序以增强参数限制的同时保证了typing正确`db_get`方法增加了`single_result`参数,与`db_query`保持一致。 - `database_api.py`中的`db_query`方法调整了参数顺序以增强参数限制的同时保证了typing正确`db_get`方法增加了`single_result`参数,与`db_query`保持一致。
4. 现在增加了参数类型检查,完善了对应注释 4. 现在增加了参数类型检查,完善了对应注释
5. 现在插件抽象出了总基类 `PluginBase`
- 基于`Action``Command`的插件基类现在为`BasePlugin`,它继承自`PluginBase`,由`register_plugin`装饰器注册。
- 基于`Event`的插件基类现在为`BaseEventPlugin`,它也继承自`PluginBase`,由`register_event_plugin`装饰器注册。

View File

@@ -34,7 +34,4 @@ def register_event_plugin(cls, *args, **kwargs):
用法: 用法:
@register_event_plugin @register_event_plugin
class MyEventPlugin:
event_type = EventType.MESSAGE_RECEIVED
...
""" """

View File

@@ -1,18 +1,14 @@
from abc import ABC, abstractmethod from abc import abstractmethod
class BaseEventsPlugin(ABC): from .plugin_base import PluginBase
""" from src.common.logger import get_logger
事件触发型插件基类
所有事件触发型插件都应该继承这个基类而不是 BasePlugin
class BaseEventPlugin(PluginBase):
"""基于事件的插件基类
所有事件类型的插件都应该继承这个基类
""" """
@property def __init__(self, *args, **kwargs):
@abstractmethod super().__init__(*args, **kwargs)
def plugin_name(self) -> str:
return "" # 插件内部标识符(如 "hello_world_plugin"
@property
@abstractmethod
def enable_plugin(self) -> bool:
return False

View File

@@ -7,7 +7,16 @@ from src.plugin_system.base.component_types import ComponentInfo
logger = get_logger("base_plugin") logger = get_logger("base_plugin")
class BasePlugin(PluginBase): class BasePlugin(PluginBase):
"""基于Action和Command的插件基类
所有上述类型的插件都应该继承这个基类,一个插件可以包含多种组件:
- Action组件处理聊天中的动作
- Command组件处理命令请求
- 未来可扩展Scheduler、Listener等
"""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)

View File

@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Dict, List, Type, Any, Union from typing import Dict, List, Any, Union
import os import os
import inspect import inspect
import toml import toml
@@ -10,7 +10,6 @@ import datetime
from src.common.logger import get_logger from src.common.logger import get_logger
from src.plugin_system.base.component_types import ( from src.plugin_system.base.component_types import (
PluginInfo, PluginInfo,
ComponentInfo,
PythonDependency, PythonDependency,
) )
from src.plugin_system.base.config_types import ConfigField from src.plugin_system.base.config_types import ConfigField
@@ -20,12 +19,9 @@ logger = get_logger("plugin_base")
class PluginBase(ABC): class PluginBase(ABC):
"""插件基类 """插件基类
所有插件都应该继承这个基类,一个插件可以包含多种组件: 所有衍生插件基类都应该继承自此类,这个类定义了插件的基本结构和行为。
- Action组件处理聊天中的动作
- Command组件处理命令请求
- 未来可扩展Scheduler、Listener等
""" """
# 插件基本信息(子类必须定义) # 插件基本信息(子类必须定义)