继承插件总基类,注释更新
This commit is contained in:
@@ -34,7 +34,4 @@ def register_event_plugin(cls, *args, **kwargs):
|
||||
|
||||
用法:
|
||||
@register_event_plugin
|
||||
class MyEventPlugin:
|
||||
event_type = EventType.MESSAGE_RECEIVED
|
||||
...
|
||||
"""
|
||||
@@ -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
|
||||
|
||||
|
||||
class BaseEventPlugin(PluginBase):
|
||||
"""基于事件的插件基类
|
||||
|
||||
所有事件类型的插件都应该继承这个基类
|
||||
"""
|
||||
事件触发型插件基类
|
||||
|
||||
所有事件触发型插件都应该继承这个基类而不是 BasePlugin
|
||||
"""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def plugin_name(self) -> str:
|
||||
return "" # 插件内部标识符(如 "hello_world_plugin")
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def enable_plugin(self) -> bool:
|
||||
return False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@@ -7,10 +7,19 @@ from src.plugin_system.base.component_types import ComponentInfo
|
||||
|
||||
logger = get_logger("base_plugin")
|
||||
|
||||
|
||||
class BasePlugin(PluginBase):
|
||||
"""基于Action和Command的插件基类
|
||||
|
||||
所有上述类型的插件都应该继承这个基类,一个插件可以包含多种组件:
|
||||
- Action组件:处理聊天中的动作
|
||||
- Command组件:处理命令请求
|
||||
- 未来可扩展:Scheduler、Listener等
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def get_plugin_components(self) -> List[tuple[ComponentInfo, Type]]:
|
||||
"""获取插件包含的组件列表
|
||||
@@ -21,7 +30,7 @@ class BasePlugin(PluginBase):
|
||||
List[tuple[ComponentInfo, Type]]: [(组件信息, 组件类), ...]
|
||||
"""
|
||||
raise NotImplementedError("Subclasses must implement this method")
|
||||
|
||||
|
||||
def register_plugin(self) -> bool:
|
||||
"""注册插件及其所有组件"""
|
||||
from src.plugin_system.core.component_registry import component_registry
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Dict, List, Type, Any, Union
|
||||
from typing import Dict, List, Any, Union
|
||||
import os
|
||||
import inspect
|
||||
import toml
|
||||
@@ -10,7 +10,6 @@ import datetime
|
||||
from src.common.logger import get_logger
|
||||
from src.plugin_system.base.component_types import (
|
||||
PluginInfo,
|
||||
ComponentInfo,
|
||||
PythonDependency,
|
||||
)
|
||||
from src.plugin_system.base.config_types import ConfigField
|
||||
@@ -20,12 +19,9 @@ logger = get_logger("plugin_base")
|
||||
|
||||
|
||||
class PluginBase(ABC):
|
||||
"""插件基类
|
||||
"""插件总基类
|
||||
|
||||
所有插件都应该继承这个基类,一个插件可以包含多种组件:
|
||||
- Action组件:处理聊天中的动作
|
||||
- Command组件:处理命令请求
|
||||
- 未来可扩展:Scheduler、Listener等
|
||||
所有衍生插件基类都应该继承自此类,这个类定义了插件的基本结构和行为。
|
||||
"""
|
||||
|
||||
# 插件基本信息(子类必须定义)
|
||||
|
||||
Reference in New Issue
Block a user