From 9f28d1943c5ad43da1ce9dc8203f4473bf1b04af Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Thu, 23 Oct 2025 00:24:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat):=20=E6=96=B0=E5=A2=9E=E7=BE=A4?= =?UTF-8?q?=E7=BB=84=E9=9D=99=E9=BB=98=E5=88=97=E8=A1=A8=E4=BB=A5=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=E9=9D=9E@=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 引入了 `mute_group_list` 配置项。对于被添加到此列表的群组,机器人将只在被明确@或回复时才处理消息,从而避免在活跃群组中造成不必要的打扰。 - 在 `MessageReceiveConfig` 中添加 `mute_group_list` 选项。 - 在消息接收逻辑中实现检查,如果消息来自静默群组且不是@或回复,则跳过消息管理器处理。 - 调整了 `is_mentioned` 的计算时机,移至消息内容处理之后,以确保静默判断的准确性。 - 附带修复了处理适配器响应时因数据非字典类型导致的潜在错误。 --- src/chat/message_receive/bot.py | 24 +++++++++++++++---- src/config/official_configs.py | 3 +++ .../tts_voice_plugin/actions/tts_action.py | 4 ++-- template/bot_config_template.toml | 5 +++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/chat/message_receive/bot.py b/src/chat/message_receive/bot.py index b8418b6e3..bef80d5f8 100644 --- a/src/chat/message_receive/bot.py +++ b/src/chat/message_receive/bot.py @@ -349,8 +349,12 @@ class ChatBot: from src.plugin_system.apis.send_api import put_adapter_response seg_data = message.message_segment.data - request_id = seg_data.get("request_id") - response_data = seg_data.get("response") + if isinstance(seg_data, dict): + request_id = seg_data.get("request_id") + response_data = seg_data.get("response") + else: + request_id = None + response_data = None if request_id and response_data: logger.debug(f"收到适配器响应: request_id={request_id}") @@ -432,7 +436,6 @@ class ChatBot: # logger.debug(str(message_data)) message = MessageRecv(message_data) - message.is_mentioned, _ = is_mentioned_bot_in_message(message) group_info = message.message_info.group_info user_info = message.message_info.user_info if message.message_info.additional_config: @@ -454,6 +457,8 @@ class ChatBot: # 处理消息内容,生成纯文本 await message.process() + message.is_mentioned, _ = is_mentioned_bot_in_message(message) + # 在这里打印[所见]日志,确保在所有处理和过滤之前记录 chat_name = chat.group_info.group_name if chat.group_info else "私聊" logger.info( @@ -689,8 +694,17 @@ class ChatBot: # 先交给消息管理器处理,计算兴趣度等衍生数据 try: - await message_manager.add_message(message.chat_stream.stream_id, db_message) - logger.debug(f"消息已添加到消息管理器: {message.chat_stream.stream_id}") + # 在将消息添加到管理器之前进行最终的静默检查 + should_process_in_manager = True + if group_info and group_info.group_id in global_config.message_receive.mute_group_list: + if not message.is_mentioned: + logger.debug(f"群组 {group_info.group_id} 在静默列表中,且消息不是@或回复,跳过消息管理器处理") + should_process_in_manager = False + + if should_process_in_manager: + await message_manager.add_message(message.chat_stream.stream_id, db_message) + logger.debug(f"消息已添加到消息管理器: {message.chat_stream.stream_id}") + except Exception as e: logger.error(f"消息添加到消息管理器失败: {e}") diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 8499071c0..4d3749b55 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -148,6 +148,9 @@ class MessageReceiveConfig(ValidatedConfigBase): ban_words: list[str] = Field(default_factory=lambda: [], description="禁用词列表") ban_msgs_regex: list[str] = Field(default_factory=lambda: [], description="禁用消息正则列表") + mute_group_list: list[str] = Field( + default_factory=list, description="静默群组列表,在这些群组中,只有在被@或回复时才会响应" + ) class NoticeConfig(ValidatedConfigBase): diff --git a/src/plugins/built_in/tts_voice_plugin/actions/tts_action.py b/src/plugins/built_in/tts_voice_plugin/actions/tts_action.py index 44de6d754..bd99e784b 100644 --- a/src/plugins/built_in/tts_voice_plugin/actions/tts_action.py +++ b/src/plugins/built_in/tts_voice_plugin/actions/tts_action.py @@ -45,8 +45,8 @@ class TTSVoiceAction(BaseAction): 3. LLM 判断当前场景适合发送语音 """ # 条件1: 随机激活 - if await self._random_activation(0.55): - logger.info(f"{self.log_prefix} 随机激活成功 (55%)") + if await self._random_activation(0.25): + logger.info(f"{self.log_prefix} 随机激活成功 (25%)") return True # 条件2: 关键词激活 diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index c66fa35c7..20844e4a5 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "7.3.4" +version = "7.3.5" #----以下是给开发人员阅读的,如果你只是部署了MoFox-Bot,不需要阅读---- #如果你想要修改配置文件,请递增version的值 @@ -148,6 +148,9 @@ ban_msgs_regex = [ #"https?://[^\\s]+", # 匹配https链接 #"\\d{4}-\\d{2}-\\d{2}", # 匹配日期 ] +# 静默群组列表,在这些群组中,只有在被@或回复时才会响应 +# 格式: ["group_id1", "group_id2"] +mute_group_list = [] [notice] # Notice消息配置 enable_notice_trigger_chat = false # 是否允许notice消息触发聊天流程(默认关闭,notice只会被记录但不会触发回复)