修复event权限,现在每个component都拥有plugin_name属性
This commit is contained in:
@@ -52,7 +52,6 @@ class LauchNapcatAdapterHandler(BaseEventHandler):
|
|||||||
elif post_type is None:
|
elif post_type is None:
|
||||||
await put_response(decoded_raw_message)
|
await put_response(decoded_raw_message)
|
||||||
|
|
||||||
|
|
||||||
async def message_process(self):
|
async def message_process(self):
|
||||||
while True:
|
while True:
|
||||||
message = await message_queue.get()
|
message = await message_queue.get()
|
||||||
@@ -79,7 +78,7 @@ class LauchNapcatAdapterHandler(BaseEventHandler):
|
|||||||
logger.error(f"启动 WebSocket 连接失败: {e}")
|
logger.error(f"启动 WebSocket 连接失败: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def execute(self, kwargs):
|
async def execute(self, kwargs):
|
||||||
# 执行功能配置迁移(如果需要)
|
# 执行功能配置迁移(如果需要)
|
||||||
logger.info("检查功能配置迁移...")
|
logger.info("检查功能配置迁移...")
|
||||||
auto_migrate_features()
|
auto_migrate_features()
|
||||||
|
|||||||
@@ -119,17 +119,17 @@ class BaseEvent:
|
|||||||
for i, result in enumerate(results):
|
for i, result in enumerate(results):
|
||||||
subscriber = sorted_subscribers[i]
|
subscriber = sorted_subscribers[i]
|
||||||
handler_name = subscriber.handler_name if hasattr(subscriber, 'handler_name') else subscriber.__class__.__name__
|
handler_name = subscriber.handler_name if hasattr(subscriber, 'handler_name') else subscriber.__class__.__name__
|
||||||
|
if result:
|
||||||
if isinstance(result, Exception):
|
if isinstance(result, Exception):
|
||||||
# 处理执行异常
|
# 处理执行异常
|
||||||
logger.error(f"事件处理器 {handler_name} 执行失败: {result}")
|
logger.error(f"事件处理器 {handler_name} 执行失败: {result}")
|
||||||
processed_results.append(HandlerResult(False, True, str(result), handler_name))
|
processed_results.append(HandlerResult(False, True, str(result), handler_name))
|
||||||
else:
|
else:
|
||||||
# 正常执行结果
|
# 正常执行结果
|
||||||
if not result.handler_name:
|
if not result.handler_name:
|
||||||
# 补充handler_name
|
# 补充handler_name
|
||||||
result.handler_name = handler_name
|
result.handler_name = handler_name
|
||||||
processed_results.append(result)
|
processed_results.append(result)
|
||||||
|
|
||||||
return HandlerResultsCollection(processed_results)
|
return HandlerResultsCollection(processed_results)
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ class BaseEventHandler(ABC):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.log_prefix = "[EventHandler]"
|
self.log_prefix = "[EventHandler]"
|
||||||
self.plugin_name = ""
|
|
||||||
"""对应插件名"""
|
"""对应插件名"""
|
||||||
self.plugin_config: Optional[Dict] = None
|
self.plugin_config: Optional[Dict] = None
|
||||||
"""插件配置字典"""
|
"""插件配置字典"""
|
||||||
|
|||||||
@@ -166,7 +166,8 @@ class ComponentRegistry:
|
|||||||
if not isinstance(action_info, ActionInfo) or not issubclass(action_class, BaseAction):
|
if not isinstance(action_info, ActionInfo) or not issubclass(action_class, BaseAction):
|
||||||
logger.error(f"注册失败: {action_name} 不是有效的Action")
|
logger.error(f"注册失败: {action_name} 不是有效的Action")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
action_class.plugin_name = action_info.plugin_name
|
||||||
self._action_registry[action_name] = action_class
|
self._action_registry[action_name] = action_class
|
||||||
|
|
||||||
# 如果启用,添加到默认动作集
|
# 如果启用,添加到默认动作集
|
||||||
@@ -184,6 +185,7 @@ class ComponentRegistry:
|
|||||||
logger.error(f"注册失败: {command_name} 不是有效的Command")
|
logger.error(f"注册失败: {command_name} 不是有效的Command")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
command_class.plugin_name = command_info.plugin_name
|
||||||
self._command_registry[command_name] = command_class
|
self._command_registry[command_name] = command_class
|
||||||
|
|
||||||
# 如果启用了且有匹配模式
|
# 如果启用了且有匹配模式
|
||||||
@@ -213,6 +215,7 @@ class ComponentRegistry:
|
|||||||
if not hasattr(self, '_plus_command_registry'):
|
if not hasattr(self, '_plus_command_registry'):
|
||||||
self._plus_command_registry: Dict[str, Type[PlusCommand]] = {}
|
self._plus_command_registry: Dict[str, Type[PlusCommand]] = {}
|
||||||
|
|
||||||
|
plus_command_class.plugin_name = plus_command_info.plugin_name
|
||||||
self._plus_command_registry[plus_command_name] = plus_command_class
|
self._plus_command_registry[plus_command_name] = plus_command_class
|
||||||
|
|
||||||
logger.debug(f"已注册PlusCommand组件: {plus_command_name}")
|
logger.debug(f"已注册PlusCommand组件: {plus_command_name}")
|
||||||
@@ -222,6 +225,7 @@ class ComponentRegistry:
|
|||||||
"""注册Tool组件到Tool特定注册表"""
|
"""注册Tool组件到Tool特定注册表"""
|
||||||
tool_name = tool_info.name
|
tool_name = tool_info.name
|
||||||
|
|
||||||
|
tool_class.plugin_name = tool_info.plugin_name
|
||||||
self._tool_registry[tool_name] = tool_class
|
self._tool_registry[tool_name] = tool_class
|
||||||
|
|
||||||
# 如果是llm可用的且启用的工具,添加到 llm可用工具列表
|
# 如果是llm可用的且启用的工具,添加到 llm可用工具列表
|
||||||
@@ -246,6 +250,7 @@ class ComponentRegistry:
|
|||||||
logger.warning(f"EventHandler组件 {handler_name} 未启用")
|
logger.warning(f"EventHandler组件 {handler_name} 未启用")
|
||||||
return True # 未启用,但是也是注册成功
|
return True # 未启用,但是也是注册成功
|
||||||
|
|
||||||
|
handler_class.plugin_name = handler_info.plugin_name
|
||||||
# 使用EventManager进行事件处理器注册
|
# 使用EventManager进行事件处理器注册
|
||||||
from src.plugin_system.core.event_manager import event_manager
|
from src.plugin_system.core.event_manager import event_manager
|
||||||
return event_manager.register_event_handler(handler_class)
|
return event_manager.register_event_handler(handler_class)
|
||||||
|
|||||||
Reference in New Issue
Block a user