Revert "feat(chat): 通过动作参数实现专用的 @用户 功能"

This reverts commit e5117720c6.
This commit is contained in:
tt-P607
2025-11-28 08:21:06 +08:00
parent e5117720c6
commit 655e535d96
8 changed files with 152 additions and 257 deletions

View File

@@ -30,16 +30,16 @@ from __future__ import annotations
import os
import re
import traceback
from typing import TYPE_CHECKING, Any, cast
from typing import TYPE_CHECKING, Any
from mofox_wire import MessageEnvelope
from mofox_wire import MessageEnvelope, MessageRuntime
from src.chat.message_manager import message_manager
from src.chat.message_receive.storage import MessageStorage
from src.chat.utils.utils import is_mentioned_bot_in_message
from src.common.data_models.database_data_model import DatabaseGroupInfo, DatabaseMessages, DatabaseUserInfo
from src.common.logger import get_logger
from src.config.config import Config, global_config
from src.config.config import global_config
from src.mood.mood_manager import mood_manager
from src.plugin_system.base import BaseCommand, EventType
from src.plugin_system.core import component_registry, event_manager, global_announcement_manager
@@ -48,10 +48,6 @@ if TYPE_CHECKING:
from src.chat.message_receive.chat_stream import ChatStream
from src.common.core_sink_manager import CoreSinkManager
if TYPE_CHECKING:
from mofox_wire import MessageRuntime
global_config: Config | None
logger = get_logger("message_handler")
# 项目根目录
@@ -59,13 +55,7 @@ PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
def _check_ban_words(text: str, chat: "ChatStream", userinfo) -> bool:
"""检查消息是否包含过滤词"""
if global_config:
for word in global_config.message_receive.ban_words:
if word in text:
chat_name = chat.group_info.group_name if chat.group_info else "私聊"
logger.info(f"[{chat_name}]{userinfo.user_nickname}:{text}")
logger.info(f"[过滤词识别]消息中含有{word}filtered")
return True
for word in global_config.message_receive.ban_words:
if word in text:
chat_name = chat.group_info.group_name if chat.group_info else "私聊"
logger.info(f"[{chat_name}]{userinfo.user_nickname}:{text}")
@@ -76,13 +66,7 @@ def _check_ban_words(text: str, chat: "ChatStream", userinfo) -> bool:
def _check_ban_regex(text: str, chat: "ChatStream", userinfo) -> bool:
"""检查消息是否匹配过滤正则表达式"""
if global_config:
for pattern in global_config.message_receive.ban_msgs_regex:
if re.search(pattern, text):
chat_name = chat.group_info.group_name if chat.group_info else "私聊"
logger.info(f"[{chat_name}]{userinfo.user_nickname}:{text}")
logger.info(f"[正则表达式过滤]消息匹配到{pattern}filtered")
return True
for pattern in global_config.message_receive.ban_msgs_regex:
if re.search(pattern, text):
chat_name = chat.group_info.group_name if chat.group_info else "私聊"
logger.info(f"[{chat_name}]{userinfo.user_nickname}:{text}")
@@ -116,13 +100,13 @@ class MessageHandler:
self._message_manager_started = False
self._core_sink_manager: CoreSinkManager | None = None
self._shutting_down = False
self._runtime: "MessageRuntime | None" = None
self._runtime: MessageRuntime | None = None
def set_core_sink_manager(self, manager: "CoreSinkManager") -> None:
"""设置 CoreSinkManager 引用"""
self._core_sink_manager = manager
def register_handlers(self, runtime: "MessageRuntime") -> None:
def register_handlers(self, runtime: MessageRuntime) -> None:
"""
向 MessageRuntime 注册消息处理器和钩子
@@ -297,7 +281,7 @@ class MessageHandler:
chat = await get_chat_manager().get_or_create_stream(
platform=platform,
user_info=DatabaseUserInfo.from_dict(user_info) if user_info else None, # type: ignore
group_info=DatabaseGroupInfo.from_dict(cast(dict, group_info)) if group_info else None,
group_info=DatabaseGroupInfo.from_dict(group_info) if group_info else None,
)
# 将消息信封转换为 DatabaseMessages
@@ -447,7 +431,7 @@ class MessageHandler:
chat = await get_chat_manager().get_or_create_stream(
platform=platform,
user_info=DatabaseUserInfo.from_dict(user_info) if user_info else None, # type: ignore
group_info=DatabaseGroupInfo.from_dict(cast(dict, group_info)) if group_info else None,
group_info=DatabaseGroupInfo.from_dict(group_info) if group_info else None,
)
# 将消息信封转换为 DatabaseMessages
@@ -551,7 +535,7 @@ class MessageHandler:
text = message.processed_plain_text or ""
# 获取配置的命令前缀
prefixes = global_config.command.command_prefixes if global_config else []
prefixes = global_config.command.command_prefixes
# 检查是否以任何前缀开头
matched_prefix = None
@@ -723,7 +707,7 @@ class MessageHandler:
# 检查是否需要处理消息
should_process_in_manager = True
if global_config and group_info and str(group_info.group_id) in global_config.message_receive.mute_group_list:
if group_info and str(group_info.group_id) in global_config.message_receive.mute_group_list:
is_image_or_emoji = message.is_picid or message.is_emoji
if not message.is_mentioned and not is_image_or_emoji:
logger.debug(
@@ -747,7 +731,7 @@ class MessageHandler:
# 情绪系统更新
try:
if global_config and global_config.mood.enable_mood:
if global_config.mood.enable_mood:
interest_rate = message.interest_value or 0.0
logger.debug(f"开始更新情绪状态,兴趣度: {interest_rate:.2f}")

View File

@@ -104,7 +104,7 @@ class ChatterActionManager:
log_prefix=log_prefix,
shutting_down=shutting_down,
plugin_config=plugin_config,
action_message=action_message.flatten() if action_message else None,
action_message=action_message,
)
logger.debug(f"创建Action实例成功: {action_name}")
@@ -252,7 +252,7 @@ class ChatterActionManager:
# 检查目标消息是否为表情包消息以及配置是否允许回复表情包
if target_message and getattr(target_message, "is_emoji", False):
# 如果是表情包消息且配置不允许回复表情包,则跳过回复
if global_config and not getattr(global_config.chat, "allow_reply_to_emoji", True):
if not getattr(global_config.chat, "allow_reply_to_emoji", True):
logger.info(f"{log_prefix} 目标消息为表情包且配置不允许回复表情包,跳过回复")
return {"action_type": action_name, "success": True, "reply_text": "", "skip_reason": "emoji_not_allowed"}
@@ -288,7 +288,7 @@ class ChatterActionManager:
reply_message=target_message,
action_data=action_data_with_mode,
available_actions=current_actions, # type: ignore
enable_tool=global_config.tool.enable_tool if global_config else False,
enable_tool=global_config.tool.enable_tool,
request_type="chat.replyer",
from_plugin=False,
)
@@ -325,7 +325,6 @@ class ChatterActionManager:
thinking_id,
[], # actions
should_quote_reply, # 传递should_quote_reply参数
action_data=action_data or {}
)
# 记录回复动作到目标消息
@@ -493,7 +492,6 @@ class ChatterActionManager:
thinking_id,
actions,
should_quote_reply: bool | None = None,
action_data: dict | None = None
) -> tuple[str, dict[str, float]]:
"""
发送并存储回复信息
@@ -511,39 +509,11 @@ class ChatterActionManager:
Returns:
Tuple[Dict[str, Any], str, Dict[str, float]]: 循环信息, 回复文本, 循环计时器
"""
# 提取回复文本
reply_text = ""
for reply_seg in response_set:
if isinstance(reply_seg, tuple) and len(reply_seg) >= 2:
_, data = reply_seg
else:
data = str(reply_seg)
if isinstance(data, list):
data = "".join(map(str, data))
reply_text += data
# 检查是否需要@用户
at_user_id = action_data.get("at_user_id") if action_data else None
if at_user_id and chat_stream.group_info:
logger.info(f"检测到需要@用户: {at_user_id},将使用 SEND_AT_MESSAGE 命令发送")
from src.plugins.built_in.napcat_adapter.src.event_models import CommandType
command_payload = {
"name": CommandType.SEND_AT_MESSAGE.name,
"args": {
"qq_id": str(at_user_id),
"text": reply_text
}
}
await send_api.command_to_stream(
command=command_payload,
stream_id=chat_stream.stream_id
# 发送回复
with Timer("回复发送", cycle_timers):
reply_text = await self.send_response(
chat_stream, response_set, loop_start_time, action_message, should_quote_reply
)
else:
# 正常发送回复
with Timer("回复发送", cycle_timers):
reply_text = await self.send_response(
chat_stream, response_set, loop_start_time, action_message, should_quote_reply, action_data
)
# 存储reply action信息
person_info_manager = get_person_info_manager()
@@ -588,7 +558,7 @@ class ChatterActionManager:
return reply_text, cycle_timers
async def send_response(
self, chat_stream, reply_set, thinking_start_time, message_data, should_quote_reply: bool | None = None, action_data: dict | None = None
self, chat_stream, reply_set, thinking_start_time, message_data, should_quote_reply: bool | None = None
) -> str:
"""
发送回复内容的具体实现
@@ -599,7 +569,6 @@ class ChatterActionManager:
thinking_start_time: 思考开始时间
message_data: 消息数据
should_quote_reply: 是否应该引用回复原消息None表示自动决定
action_data: 动作数据,用于检查是否需要@
Returns:
str: 完整的回复文本
@@ -628,7 +597,6 @@ class ChatterActionManager:
logger.debug(f"[send_response] message_data: {message_data}")
first_replied = False
for reply_seg in reply_set:
# 调试日志验证reply_seg的格式
logger.debug(f"Processing reply_seg type: {type(reply_seg)}, content: {reply_seg}")

View File

@@ -38,10 +38,6 @@ from src.plugin_system.base.component_types import ActionInfo, EventType
if TYPE_CHECKING:
from src.chat.message_receive.chat_stream import ChatStream
from src.config.config import APIAdapterConfig, Config
global_config: "Config"
model_config: "APIAdapterConfig"
logger = get_logger("replyer")
@@ -123,10 +119,6 @@ def init_prompt():
{action_descriptions}
- **关于@功能的重要说明**
- 如果你需要在一个回复中`@`某个用户,**请不要**在你的回复内容中直接输出`@`符号或`艾特`等文字。
- 你应该使用`reply`或`respond`动作中的`at_user_id`参数。只需要将目标的QQ号填入该参数系统就会自动为你完成`@`操作。
## 任务
*{chat_scene}*