feat(chat): 新增群组静默列表以忽略非@消息
引入了 `mute_group_list` 配置项。对于被添加到此列表的群组,机器人将只在被明确@或回复时才处理消息,从而避免在活跃群组中造成不必要的打扰。 - 在 `MessageReceiveConfig` 中添加 `mute_group_list` 选项。 - 在消息接收逻辑中实现检查,如果消息来自静默群组且不是@或回复,则跳过消息管理器处理。 - 调整了 `is_mentioned` 的计算时机,移至消息内容处理之后,以确保静默判断的准确性。 - 附带修复了处理适配器响应时因数据非字典类型导致的潜在错误。
This commit is contained in:
@@ -349,8 +349,12 @@ class ChatBot:
|
||||
from src.plugin_system.apis.send_api import put_adapter_response
|
||||
|
||||
seg_data = message.message_segment.data
|
||||
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:
|
||||
# 在将消息添加到管理器之前进行最终的静默检查
|
||||
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}")
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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: 关键词激活
|
||||
|
||||
@@ -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只会被记录但不会触发回复)
|
||||
|
||||
Reference in New Issue
Block a user