fix:全面移除reply_to,并且非必须

This commit is contained in:
SengokuCola
2025-08-11 20:25:13 +08:00
parent 5299a6e628
commit bad2be2bdc
8 changed files with 66 additions and 95 deletions

View File

@@ -74,7 +74,6 @@ async def generate_reply(
chat_stream: Optional[ChatStream] = None,
chat_id: Optional[str] = None,
action_data: Optional[Dict[str, Any]] = None,
reply_to: str = "",
reply_message: Optional[Dict[str, Any]] = None,
extra_info: str = "",
reply_reason: str = "",
@@ -92,8 +91,7 @@ async def generate_reply(
chat_stream: 聊天流对象(优先)
chat_id: 聊天ID备用
action_data: 动作数据向下兼容包含reply_to和extra_info
reply_to: 回复对象,格式为 "发送者:消息内容"
reply_message: 回复消息
reply_message: 回复的消息对象
extra_info: 额外信息,用于补充上下文
reply_reason: 回复原因
available_actions: 可用动作
@@ -109,6 +107,7 @@ async def generate_reply(
"""
try:
# 获取回复器
logger.debug("[GeneratorAPI] 开始生成回复")
replyer = get_replyer(
chat_stream, chat_id, request_type=request_type
)
@@ -116,11 +115,6 @@ async def generate_reply(
logger.error("[GeneratorAPI] 无法获取回复器")
return False, [], None
logger.debug("[GeneratorAPI] 开始生成回复")
if reply_to:
logger.warning("[GeneratorAPI] 在0.10.0, reply_to 参数已弃用,请使用 reply_message 参数")
if not extra_info and action_data:
extra_info = action_data.get("extra_info", "")

View File

@@ -21,7 +21,6 @@
import traceback
import time
import difflib
from typing import Optional, Union, Dict, Any
from src.common.logger import get_logger
@@ -29,8 +28,6 @@ from src.common.logger import get_logger
from src.chat.message_receive.chat_stream import get_chat_manager
from src.chat.message_receive.uni_message_sender import HeartFCSender
from src.chat.message_receive.message import MessageSending, MessageRecv
from src.chat.utils.chat_message_builder import get_raw_msg_before_timestamp_with_chat, replace_user_references_async
from src.person_info.person_info import get_person_info_manager
from maim_message import Seg, UserInfo
from src.config.config import global_config
@@ -48,9 +45,8 @@ async def _send_to_target(
stream_id: str,
display_message: str = "",
typing: bool = False,
reply_to: str = "",
set_reply: bool = False,
reply_to_message: Optional[Dict[str, Any]] = None,
reply_message: Optional[Dict[str, Any]] = None,
storage_message: bool = True,
show_log: bool = True,
) -> bool:
@@ -70,8 +66,9 @@ async def _send_to_target(
bool: 是否发送成功
"""
try:
if reply_to:
logger.warning("[SendAPI] 在0.10.0, reply_to 参数已弃用,请使用 reply_to_message 参数")
if set_reply and not reply_message:
logger.warning("[SendAPI] 使用引用回复,但未提供回复消息")
return False
if show_log:
logger.debug(f"[SendAPI] 发送{message_type}消息到 {stream_id}")
@@ -99,13 +96,14 @@ async def _send_to_target(
# 创建消息段
message_segment = Seg(type=message_type, data=content) # type: ignore
if reply_to_message:
anchor_message = message_dict_to_message_recv(reply_to_message)
if reply_message:
anchor_message = message_dict_to_message_recv(reply_message)
anchor_message.update_chat_stream(target_stream)
reply_to_platform_id = (
f"{anchor_message.message_info.platform}:{anchor_message.message_info.user_info.user_id}"
)
else:
reply_to_platform_id = ""
anchor_message = None
# 构建发送消息对象
@@ -146,8 +144,7 @@ async def _send_to_target(
def message_dict_to_message_recv(message_dict: Dict[str, Any]) -> Optional[MessageRecv]:
"""查找要回复的消息
"""将数据库dict重建为MessageRecv对象
Args:
message_dict: 消息字典
@@ -184,13 +181,13 @@ def message_dict_to_message_recv(message_dict: Dict[str, Any]) -> Optional[Messa
"template_info": template_info,
}
message_dict = {
message_dict_recv = {
"message_info": message_info,
"raw_message": message_dict.get("processed_plain_text"),
"processed_plain_text": message_dict.get("processed_plain_text"),
}
message_recv = MessageRecv(message_dict)
message_recv = MessageRecv(message_dict_recv)
logger.info(f"[SendAPI] 找到匹配的回复消息,发送者: {message_dict.get('user_nickname', '')}")
return message_recv
@@ -206,9 +203,8 @@ async def text_to_stream(
text: str,
stream_id: str,
typing: bool = False,
reply_to: str = "",
reply_to_message: Optional[Dict[str, Any]] = None,
set_reply: bool = False,
reply_message: Optional[Dict[str, Any]] = None,
storage_message: bool = True,
) -> bool:
"""向指定流发送文本消息
@@ -229,14 +225,13 @@ async def text_to_stream(
stream_id,
"",
typing,
reply_to,
set_reply=set_reply,
reply_to_message=reply_to_message,
reply_message=reply_message,
storage_message=storage_message,
)
async def emoji_to_stream(emoji_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = False,reply_to_message: Optional[Dict[str, Any]] = None) -> bool:
async def emoji_to_stream(emoji_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None) -> bool:
"""向指定流发送表情包
Args:
@@ -247,10 +242,10 @@ async def emoji_to_stream(emoji_base64: str, stream_id: str, storage_message: bo
Returns:
bool: 是否发送成功
"""
return await _send_to_target("emoji", emoji_base64, stream_id, "", typing=False, storage_message=storage_message, set_reply=set_reply,reply_to_message=reply_to_message)
return await _send_to_target("emoji", emoji_base64, stream_id, "", typing=False, storage_message=storage_message, set_reply=set_reply,reply_message=reply_message)
async def image_to_stream(image_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = False,reply_to_message: Optional[Dict[str, Any]] = None) -> bool:
async def image_to_stream(image_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None) -> bool:
"""向指定流发送图片
Args:
@@ -261,11 +256,11 @@ async def image_to_stream(image_base64: str, stream_id: str, storage_message: bo
Returns:
bool: 是否发送成功
"""
return await _send_to_target("image", image_base64, stream_id, "", typing=False, storage_message=storage_message, set_reply=set_reply,reply_to_message=reply_to_message)
return await _send_to_target("image", image_base64, stream_id, "", typing=False, storage_message=storage_message, set_reply=set_reply,reply_message=reply_message)
async def command_to_stream(
command: Union[str, dict], stream_id: str, storage_message: bool = True, display_message: str = "", set_reply: bool = False,reply_to_message: Optional[Dict[str, Any]] = None
command: Union[str, dict], stream_id: str, storage_message: bool = True, display_message: str = "", set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None
) -> bool:
"""向指定流发送命令
@@ -278,7 +273,7 @@ async def command_to_stream(
bool: 是否发送成功
"""
return await _send_to_target(
"command", command, stream_id, display_message, typing=False, storage_message=storage_message, set_reply=set_reply,reply_to_message=reply_to_message
"command", command, stream_id, display_message, typing=False, storage_message=storage_message, set_reply=set_reply,reply_message=reply_message
)
@@ -288,8 +283,7 @@ async def custom_to_stream(
stream_id: str,
display_message: str = "",
typing: bool = False,
reply_to: str = "",
reply_to_message: Optional[Dict[str, Any]] = None,
reply_message: Optional[Dict[str, Any]] = None,
set_reply: bool = False,
storage_message: bool = True,
show_log: bool = True,
@@ -314,8 +308,7 @@ async def custom_to_stream(
stream_id=stream_id,
display_message=display_message,
typing=typing,
reply_to=reply_to,
reply_to_message=reply_to_message,
reply_message=reply_message,
set_reply=set_reply,
storage_message=storage_message,
show_log=show_log,

View File

@@ -2,7 +2,7 @@ import time
import asyncio
from abc import ABC, abstractmethod
from typing import Tuple, Optional
from typing import Tuple, Optional, Dict, Any
from src.common.logger import get_logger
from src.chat.message_receive.chat_stream import ChatStream
@@ -208,7 +208,7 @@ class BaseAction(ABC):
return False, f"等待新消息失败: {str(e)}"
async def send_text(
self, content: str, reply_to: str = "", typing: bool = False
self, content: str, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None, typing: bool = False
) -> bool:
"""发送文本消息
@@ -226,12 +226,12 @@ class BaseAction(ABC):
return await send_api.text_to_stream(
text=content,
stream_id=self.chat_id,
reply_to=reply_to,
set_reply=set_reply,
reply_message=reply_message,
typing=typing,
reply_to_message=self.action_message,
)
async def send_emoji(self, emoji_base64: str) -> bool:
async def send_emoji(self, emoji_base64: str, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None) -> bool:
"""发送表情包
Args:
@@ -244,9 +244,9 @@ class BaseAction(ABC):
logger.error(f"{self.log_prefix} 缺少聊天ID")
return False
return await send_api.emoji_to_stream(emoji_base64, self.chat_id,reply_to_message=self.action_message)
return await send_api.emoji_to_stream(emoji_base64, self.chat_id,set_reply=set_reply,reply_message=reply_message)
async def send_image(self, image_base64: str) -> bool:
async def send_image(self, image_base64: str, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None) -> bool:
"""发送图片
Args:
@@ -259,9 +259,9 @@ class BaseAction(ABC):
logger.error(f"{self.log_prefix} 缺少聊天ID")
return False
return await send_api.image_to_stream(image_base64, self.chat_id,reply_to_message=self.action_message)
return await send_api.image_to_stream(image_base64, self.chat_id,set_reply=set_reply,reply_message=reply_message)
async def send_custom(self, message_type: str, content: str, typing: bool = False, reply_to: str = "") -> bool:
async def send_custom(self, message_type: str, content: str, typing: bool = False, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None) -> bool:
"""发送自定义类型消息
Args:
@@ -282,8 +282,8 @@ class BaseAction(ABC):
content=content,
stream_id=self.chat_id,
typing=typing,
reply_to=reply_to,
reply_to_message=self.action_message,
set_reply=set_reply,
reply_message=reply_message,
)
async def store_action_info(
@@ -310,7 +310,7 @@ class BaseAction(ABC):
)
async def send_command(
self, command_name: str, args: Optional[dict] = None, display_message: str = "", storage_message: bool = True
self, command_name: str, args: Optional[dict] = None, display_message: str = "", storage_message: bool = True,set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None
) -> bool:
"""发送命令消息
@@ -338,7 +338,8 @@ class BaseAction(ABC):
stream_id=self.chat_id,
storage_message=storage_message,
display_message=display_message,
reply_to_message=self.action_message,
set_reply=set_reply,
reply_message=reply_message,
)
if success:

View File

@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Dict, Tuple, Optional
from typing import Dict, Tuple, Optional, Any
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
@@ -84,7 +84,7 @@ class BaseCommand(ABC):
return current
async def send_text(self, content: str, reply_to: str = "") -> bool:
async def send_text(self, content: str, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None) -> bool:
"""发送回复消息
Args:
@@ -100,10 +100,10 @@ class BaseCommand(ABC):
logger.error(f"{self.log_prefix} 缺少聊天流或stream_id")
return False
return await send_api.text_to_stream(text=content, stream_id=chat_stream.stream_id, reply_to=reply_to,reply_to_message=self.message)
return await send_api.text_to_stream(text=content, stream_id=chat_stream.stream_id, set_reply=set_reply,reply_message=reply_message)
async def send_type(
self, message_type: str, content: str, display_message: str = "", typing: bool = False, reply_to: str = ""
self, message_type: str, content: str, display_message: str = "", typing: bool = False, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None
) -> bool:
"""发送指定类型的回复消息到当前聊天环境
@@ -129,12 +129,12 @@ class BaseCommand(ABC):
stream_id=chat_stream.stream_id,
display_message=display_message,
typing=typing,
reply_to=reply_to,
reply_to_message=self.message,
set_reply=set_reply,
reply_message=reply_message,
)
async def send_command(
self, command_name: str, args: Optional[dict] = None, display_message: str = "", storage_message: bool = True
self, command_name: str, args: Optional[dict] = None, display_message: str = "", storage_message: bool = True,set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None
) -> bool:
"""发送命令消息
@@ -162,7 +162,8 @@ class BaseCommand(ABC):
stream_id=chat_stream.stream_id,
storage_message=storage_message,
display_message=display_message,
reply_to_message=self.message,
set_reply=set_reply,
reply_message=reply_message,
)
if success:
@@ -176,7 +177,7 @@ class BaseCommand(ABC):
logger.error(f"{self.log_prefix} 发送命令时出错: {e}")
return False
async def send_emoji(self, emoji_base64: str) -> bool:
async def send_emoji(self, emoji_base64: str, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None) -> bool:
"""发送表情包
Args:
@@ -190,9 +191,9 @@ class BaseCommand(ABC):
logger.error(f"{self.log_prefix} 缺少聊天流或stream_id")
return False
return await send_api.emoji_to_stream(emoji_base64, chat_stream.stream_id,reply_to_message=self.message)
return await send_api.emoji_to_stream(emoji_base64, chat_stream.stream_id,set_reply=set_reply,reply_message=reply_message)
async def send_image(self, image_base64: str) -> bool:
async def send_image(self, image_base64: str, set_reply: bool = False,reply_message: Optional[Dict[str, Any]] = None) -> bool:
"""发送图片
Args:
@@ -206,7 +207,7 @@ class BaseCommand(ABC):
logger.error(f"{self.log_prefix} 缺少聊天流或stream_id")
return False
return await send_api.image_to_stream(image_base64, chat_stream.stream_id,reply_to_message=self.message)
return await send_api.image_to_stream(image_base64, chat_stream.stream_id,set_reply=set_reply,reply_message=reply_message)
@classmethod
def get_command_info(cls) -> "CommandInfo":