Files
abot/plugin_common/message_plugin_interface.py
2025-04-30 13:22:33 +08:00

49 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from typing import Dict, Any, Tuple, Optional, List
from plugin_common.plugin_interface import PluginInterface
class MessagePluginInterface(PluginInterface):
"""消息处理插件接口"""
@property
def command_prefix(self) -> Optional[str]:
"""命令前缀,如 '/'"""
return None
@property
def commands(self) -> List[str]:
"""支持的命令列表"""
return []
def can_process(self, message: Dict[str, Any]) -> bool:
"""
检查插件是否可以处理该消息
Args:
message: 消息字典,包含消息的各种属性
Returns:
是否可以处理
"""
# 默认实现:检查是否是命令
if self.command_prefix and self.commands:
content = message.get("content", "")
if content.startswith(self.command_prefix):
command = content[len(self.command_prefix):].split()[0]
return command in self.commands
return False
def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
"""
处理消息
Args:
message: 消息字典,包含消息的各种属性,以及发送消息所需的对象
- wcf: WcfAPI对象可用于发送消息
- message_util: 消息工具类,提供更高级的消息处理功能
Returns:
(是否已处理, 处理结果)
"""
raise NotImplementedError("子类必须实现此方法")