feat(chat): 引入专注模式安静群组功能
新增 `focus_mode_quiet_groups` 配置项,允许用户指定在专注模式下需要保持安静的群组列表。 在此列表中的群组,机器人只有在被明确提及(艾特)时才会做出回应。这有助于在某些活跃度高但不需要机器人持续参与的群组中减少打扰。 该功能兼容了不同QQ适配器(如 `qq` 和 `napcat`)的平台名称。
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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形式
|
||||
|
||||
|
||||
Reference in New Issue
Block a user