fix:全面移除reply_to,并且非必须
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user