This commit is contained in:
Windpicker-owo
2025-09-21 18:02:28 +08:00
6 changed files with 32 additions and 37 deletions

View File

@@ -430,8 +430,6 @@ class ActionManager:
) )
# 根据新消息数量决定是否需要引用回复 # 根据新消息数量决定是否需要引用回复
need_reply = new_message_count >= random.randint(2, 4)
reply_text = "" reply_text = ""
is_proactive_thinking = (message_data.get("message_type") == "proactive_thinking") if message_data else True is_proactive_thinking = (message_data.get("message_type") == "proactive_thinking") if message_data else True
@@ -462,7 +460,7 @@ class ActionManager:
text=data, text=data,
stream_id=chat_stream.stream_id, stream_id=chat_stream.stream_id,
reply_to_message=message_data, reply_to_message=message_data,
set_reply=need_reply, set_reply=bool(message_data),
typing=False, typing=False,
) )
first_replied = True first_replied = True

View File

@@ -126,7 +126,13 @@ class PlanExecutor:
try: try:
logger.info(f"执行回复动作: {action_info.action_type}, 原因: {action_info.reasoning}") logger.info(f"执行回复动作: {action_info.action_type}, 原因: {action_info.reasoning}")
if action_info.action_message.get("user_id", "") == str(global_config.bot.qq_account): # 获取用户ID - 兼容对象和字典
if hasattr(action_info.action_message, "user_info"):
user_id = action_info.action_message.user_info.user_id
else:
user_id = action_info.action_message.get("user_info", {}).get("user_id")
if user_id == str(global_config.bot.qq_account):
logger.warning("尝试回复自己,跳过此动作以防止死循环。") logger.warning("尝试回复自己,跳过此动作以防止死循环。")
return { return {
"action_type": action_info.action_type, "action_type": action_info.action_type,
@@ -246,15 +252,17 @@ class PlanExecutor:
return return
# 获取用户信息 - 处理对象和字典两种情况 # 获取用户信息 - 处理对象和字典两种情况
if hasattr(action_info.action_message, "user_id"): if hasattr(action_info.action_message, "user_info"):
# 对象情况 # 对象情况
user_id = action_info.action_message.user_id user_info = action_info.action_message.user_info
user_name = getattr(action_info.action_message, "user_nickname", user_id) or user_id user_id = user_info.user_id
user_message = getattr(action_info.action_message, "content", "") user_name = user_info.user_nickname or user_id
user_message = action_info.action_message.content
else: else:
# 字典情况 # 字典情况
user_id = action_info.action_message.get("user_id", "") user_info = action_info.action_message.get("user_info", {})
user_name = action_info.action_message.get("user_nickname", user_id) or user_id user_id = user_info.get("user_id")
user_name = user_info.get("user_nickname") or user_id
user_message = action_info.action_message.get("content", "") user_message = action_info.action_message.get("content", "")
if not user_id: if not user_id:

View File

@@ -379,6 +379,11 @@ class PlanFilter:
if target_message_dict: if target_message_dict:
# 直接使用字典作为action_message避免DatabaseMessages对象创建失败 # 直接使用字典作为action_message避免DatabaseMessages对象创建失败
target_message_obj = target_message_dict target_message_obj = target_message_dict
# 替换action_data中的临时ID为真实ID
if "target_message_id" in action_data:
real_message_id = target_message_dict.get("message_id") or target_message_dict.get("id")
if real_message_id:
action_data["target_message_id"] = real_message_id
else: else:
# 如果找不到目标消息对于reply动作来说这是必需的应该记录警告 # 如果找不到目标消息对于reply动作来说这是必需的应该记录警告
if action == "reply": if action == "reply":

View File

@@ -695,25 +695,9 @@ def assign_message_ids(messages: List[Any]) -> List[Dict[str, Any]]:
""" """
result = [] result = []
used_ids = set() used_ids = set()
len_i = len(messages)
if len_i > 100:
a = 10
b = 99
else:
a = 1
b = 9
for i, message in enumerate(messages): for i, message in enumerate(messages):
# 生成唯一的简短ID # 使用简单的索引作为ID
while True: message_id = f"m{i + 1}"
# 使用索引+随机数生成简短ID
random_suffix = random.randint(a, b)
message_id = f"m{i + 1}{random_suffix}"
if message_id not in used_ids:
used_ids.add(message_id)
break
result.append({"id": message_id, "message": message}) result.append({"id": message_id, "message": message})
return result return result

View File

@@ -80,7 +80,7 @@ def message_dict_to_message_recv(message_dict: Dict[str, Any]) -> Optional[Messa
message_info = { message_info = {
"platform": message_dict.get("chat_info_platform", ""), "platform": message_dict.get("chat_info_platform", ""),
"message_id": message_dict.get("message_id"), "message_id": message_dict.get("message_id") or message_dict.get("chat_info_message_id"),
"time": message_dict.get("time"), "time": message_dict.get("time"),
"group_info": group_info, "group_info": group_info,
"user_info": user_info, "user_info": user_info,
@@ -89,13 +89,13 @@ def message_dict_to_message_recv(message_dict: Dict[str, Any]) -> Optional[Messa
"template_info": template_info, "template_info": template_info,
} }
message_dict = { new_message_dict = {
"message_info": message_info, "message_info": message_info,
"raw_message": message_dict.get("processed_plain_text"), "raw_message": message_dict.get("processed_plain_text"),
"processed_plain_text": message_dict.get("processed_plain_text"), "processed_plain_text": message_dict.get("processed_plain_text"),
} }
message_recv = MessageRecv(message_dict) message_recv = MessageRecv(new_message_dict)
logger.info(f"[SendAPI] 找到匹配的回复消息,发送者: {message_dict.get('user_nickname', '')}") logger.info(f"[SendAPI] 找到匹配的回复消息,发送者: {message_dict.get('user_nickname', '')}")
return message_recv return message_recv
@@ -246,7 +246,7 @@ async def text_to_stream(
typing: bool = False, typing: bool = False,
reply_to: str = "", reply_to: str = "",
reply_to_message: Optional[Dict[str, Any]] = None, reply_to_message: Optional[Dict[str, Any]] = None,
set_reply: bool = False, set_reply: bool = True,
storage_message: bool = True, storage_message: bool = True,
) -> bool: ) -> bool:
"""向指定流发送文本消息 """向指定流发送文本消息
@@ -275,7 +275,7 @@ async def text_to_stream(
async def emoji_to_stream( async def emoji_to_stream(
emoji_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = False emoji_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = True
) -> bool: ) -> bool:
"""向指定流发送表情包 """向指定流发送表情包
@@ -293,7 +293,7 @@ async def emoji_to_stream(
async def image_to_stream( async def image_to_stream(
image_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = False image_base64: str, stream_id: str, storage_message: bool = True, set_reply: bool = True
) -> bool: ) -> bool:
"""向指定流发送图片 """向指定流发送图片
@@ -315,7 +315,7 @@ async def command_to_stream(
stream_id: str, stream_id: str,
storage_message: bool = True, storage_message: bool = True,
display_message: str = "", display_message: str = "",
set_reply: bool = False, set_reply: bool = True,
) -> bool: ) -> bool:
"""向指定流发送命令 """向指定流发送命令
@@ -340,7 +340,7 @@ async def custom_to_stream(
typing: bool = False, typing: bool = False,
reply_to: str = "", reply_to: str = "",
reply_to_message: Optional[Dict[str, Any]] = None, reply_to_message: Optional[Dict[str, Any]] = None,
set_reply: bool = False, set_reply: bool = True,
storage_message: bool = True, storage_message: bool = True,
show_log: bool = True, show_log: bool = True,
) -> bool: ) -> bool:

View File

@@ -302,7 +302,7 @@ class SendHandler:
original_id = id.split("-")[1] original_id = id.split("-")[1]
msg_info_response = await self.send_message_to_napcat("get_msg", {"message_id": int(original_id)}) msg_info_response = await self.send_message_to_napcat("get_msg", {"message_id": int(original_id)})
else: else:
msg_info_response = await self.send_message_to_napcat("get_msg", {"message_id": int(id)}) msg_info_response = await self.send_message_to_napcat("get_msg", {"message_id": id})
replied_user_id = None replied_user_id = None
if msg_info_response and msg_info_response.get("status") == "ok": if msg_info_response and msg_info_response.get("status") == "ok":