From 8f65953b9d1dd37551e75bcae9f108e963619139 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Thu, 11 Sep 2025 08:50:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat):=20=E5=BC=95=E5=85=A5=E4=B8=93?= =?UTF-8?q?=E6=B3=A8=E6=A8=A1=E5=BC=8F=E5=AE=89=E9=9D=99=E7=BE=A4=E7=BB=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 `focus_mode_quiet_groups` 配置项,允许用户指定在专注模式下需要保持安静的群组列表。 在此列表中的群组,机器人只有在被明确提及(艾特)时才会做出回应。这有助于在某些活跃度高但不需要机器人持续参与的群组中减少打扰。 该功能兼容了不同QQ适配器(如 `qq` 和 `napcat`)的平台名称。 --- src/chat/chat_loop/heartFC_chat.py | 31 ++++++++++++++++++++++++++++++ src/config/official_configs.py | 3 +++ template/bot_config_template.toml | 8 +++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/chat/chat_loop/heartFC_chat.py b/src/chat/chat_loop/heartFC_chat.py index b93931cbb..6f63cff1b 100644 --- a/src/chat/chat_loop/heartFC_chat.py +++ b/src/chat/chat_loop/heartFC_chat.py @@ -379,6 +379,37 @@ class HeartFChatting: self.context.last_message_time = time.time() self.context.last_read_time = time.time() + # --- 专注模式安静群组检查 --- + quiet_groups = global_config.chat.focus_mode_quiet_groups + if quiet_groups and self.context.chat_stream: + is_group_chat = self.context.chat_stream.group_info is not None + if is_group_chat: + try: + platform = self.context.chat_stream.platform + group_id = self.context.chat_stream.group_info.group_id + + # 兼容不同QQ适配器的平台名称 + is_qq_platform = platform in ["qq", "napcat"] + + current_chat_identifier = f"{platform}:{group_id}" + config_identifier_for_qq = f"qq:{group_id}" + + is_in_quiet_list = (current_chat_identifier in quiet_groups or + (is_qq_platform and config_identifier_for_qq in quiet_groups)) + + if is_in_quiet_list: + is_mentioned_in_batch = False + for msg in recent_messages: + if msg.get("is_mentioned"): + is_mentioned_in_batch = True + break + + if not is_mentioned_in_batch: + logger.info(f"{self.context.log_prefix} 在专注安静模式下,因未被提及而忽略了消息。") + return True # 消耗消息但不做回复 + except Exception as e: + logger.error(f"{self.context.log_prefix} 检查专注安静群组时出错: {e}") + # 处理唤醒度逻辑 if current_sleep_state in [SleepState.SLEEPING, SleepState.PREPARING_SLEEP, SleepState.INSOMNIA]: self._handle_wakeup_messages(recent_messages) diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 97facecc3..3230888b9 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -75,6 +75,9 @@ class ChatConfig(ValidatedConfigBase): at_bot_inevitable_reply: bool = Field(default=False, description="@机器人的必然回复") talk_frequency_adjust: list[list[str]] = Field(default_factory=lambda: [], description="聊天频率调整") focus_value: float = Field(default=1.0, description="专注值") + focus_mode_quiet_groups: List[str] = Field( + default_factory=list, description='专注模式下需要保持安静的群组列表, 格式: ["platform:group_id1", "platform:group_id2"]' + ) force_reply_private: bool = Field(default=False, description="强制回复私聊") group_chat_mode: Literal["auto", "normal", "focus"] = Field(default="auto", description="群聊模式") timestamp_display_mode: Literal["normal", "normal_no_YMD", "relative"] = Field( diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 73fdebd32..07c791c6b 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "6.8.0" +version = "6.8.1" #----以下是给开发人员阅读的,如果你只是部署了MoFox-Bot,不需要阅读---- #如果你想要修改配置文件,请递增version的值 @@ -111,6 +111,12 @@ talk_frequency = 1 focus_value = 1 # MoFox-Bot的专注思考能力,越高越容易持续连续对话 +# 在专注模式下,只在被艾特或提及时才回复的群组列表 +# 这可以让你在某些群里保持“高冷”,只在被需要时才发言 +# 格式为: ["platform:group_id1", "platform:group_id2"] +# 例如: ["qq:123456789", "qq:987654321"] +focus_mode_quiet_groups = [] + # breaking模式配置 enable_breaking_mode = true # 是否启用自动进入breaking模式,关闭后不会自动进入breaking形式