diff --git a/plugins/hello_world_plugin/plugin.py b/plugins/hello_world_plugin/plugin.py index 11ff22bd8..8ede9616a 100644 --- a/plugins/hello_world_plugin/plugin.py +++ b/plugins/hello_world_plugin/plugin.py @@ -20,6 +20,7 @@ class HelloAction(BaseAction): # === 基本信息(必须填写)=== action_name = "hello_greeting" action_description = "向用户发送问候消息" + activation_type = ActionActivationType.ALWAYS # 始终激活 # === 功能描述(必须填写)=== action_parameters = {"greeting_message": "要发送的问候消息"} @@ -44,8 +45,7 @@ class ByeAction(BaseAction): action_description = "向用户发送告别消息" # 使用关键词激活 - focus_activation_type = ActionActivationType.KEYWORD - normal_activation_type = ActionActivationType.KEYWORD + activation_type = ActionActivationType.KEYWORD # 关键词设置 activation_keywords = ["再见", "bye", "88", "拜拜"] @@ -75,8 +75,6 @@ class TimeCommand(BaseCommand): # === 命令设置(必须填写)=== command_pattern = r"^/time$" # 精确匹配 "/time" 命令 - command_help = "查询当前时间" - command_examples = ["/time"] async def execute(self) -> Tuple[bool, str, bool]: """执行时间查询""" diff --git a/src/plugin_system/base/base_command.py b/src/plugin_system/base/base_command.py index b79f68845..60ee99add 100644 --- a/src/plugin_system/base/base_command.py +++ b/src/plugin_system/base/base_command.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Dict, Tuple, Optional, List +from typing import Dict, Tuple, Optional from src.common.logger import get_logger from src.plugin_system.base.component_types import CommandInfo, ComponentType from src.chat.message_receive.message import MessageRecv @@ -26,9 +26,6 @@ class BaseCommand(ABC): # 默认命令设置 command_pattern: str = r"" """命令匹配的正则表达式""" - command_help: str = "" - """命令帮助信息""" - command_examples: List[str] = [] def __init__(self, message: MessageRecv, plugin_config: Optional[dict] = None): """初始化Command组件 @@ -228,6 +225,4 @@ class BaseCommand(ABC): component_type=ComponentType.COMMAND, description=cls.command_description, command_pattern=cls.command_pattern, - command_help=cls.command_help, - command_examples=cls.command_examples.copy() if cls.command_examples else [], ) diff --git a/src/plugin_system/base/component_types.py b/src/plugin_system/base/component_types.py index 74b01ddd7..eeb2a5a08 100644 --- a/src/plugin_system/base/component_types.py +++ b/src/plugin_system/base/component_types.py @@ -140,13 +140,9 @@ class CommandInfo(ComponentInfo): """命令组件信息""" command_pattern: str = "" # 命令匹配模式(正则表达式) - command_help: str = "" # 命令帮助信息 - command_examples: List[str] = field(default_factory=list) # 命令使用示例 def __post_init__(self): super().__post_init__() - if self.command_examples is None: - self.command_examples = [] self.component_type = ComponentType.COMMAND diff --git a/src/plugin_system/core/events_manager.py b/src/plugin_system/core/events_manager.py index 1f01b4ab4..3c215a7ff 100644 --- a/src/plugin_system/core/events_manager.py +++ b/src/plugin_system/core/events_manager.py @@ -182,17 +182,17 @@ class EventsManager: async def cancel_handler_tasks(self, handler_name: str) -> None: tasks_to_be_cancelled = self._handler_tasks.get(handler_name, []) - remaining_tasks = [task for task in tasks_to_be_cancelled if not task.done()] - for task in remaining_tasks: - task.cancel() - try: - await asyncio.wait_for(asyncio.gather(*remaining_tasks, return_exceptions=True), timeout=5) - logger.info(f"已取消事件处理器 {handler_name} 的所有任务") - except asyncio.TimeoutError: - logger.warning(f"取消事件处理器 {handler_name} 的任务超时,开始强制取消") - except Exception as e: - logger.error(f"取消事件处理器 {handler_name} 的任务时发生异常: {e}") - finally: + if remaining_tasks := [task for task in tasks_to_be_cancelled if not task.done()]: + for task in remaining_tasks: + task.cancel() + try: + await asyncio.wait_for(asyncio.gather(*remaining_tasks, return_exceptions=True), timeout=5) + logger.info(f"已取消事件处理器 {handler_name} 的所有任务") + except asyncio.TimeoutError: + logger.warning(f"取消事件处理器 {handler_name} 的任务超时,开始强制取消") + except Exception as e: + logger.error(f"取消事件处理器 {handler_name} 的任务时发生异常: {e}") + if handler_name in self._handler_tasks: del self._handler_tasks[handler_name] async def unregister_event_subscriber(self, handler_name: str) -> bool: