mirror of https://github.com/Mai-with-u/MaiBot.git
新增只读群组功能,并且避免为只读群组创建和维护子心流,减少资源消耗
parent
0acad09dd7
commit
827945e604
|
|
@ -4,6 +4,7 @@ from src.plugins.moods.moods import MoodManager
|
||||||
from src.plugins.models.utils_model import LLM_request
|
from src.plugins.models.utils_model import LLM_request
|
||||||
from src.plugins.config.config import global_config
|
from src.plugins.config.config import global_config
|
||||||
from src.plugins.schedule.schedule_generator import bot_schedule
|
from src.plugins.schedule.schedule_generator import bot_schedule
|
||||||
|
from src.plugins.chat.chat_stream import chat_manager
|
||||||
import asyncio
|
import asyncio
|
||||||
from src.common.logger import get_module_logger, LogConfig, HEARTFLOW_STYLE_CONFIG # noqa: E402
|
from src.common.logger import get_module_logger, LogConfig, HEARTFLOW_STYLE_CONFIG # noqa: E402
|
||||||
import time
|
import time
|
||||||
|
|
@ -146,6 +147,16 @@ class Heartflow:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# 检查是否是只读群组的ID
|
||||||
|
# 正常情况下,只读群组在bot.py中已被过滤,不会执行到heartflow的相关方法
|
||||||
|
# 此检查确保即使有代码变更或异常路径,只读群组也不会创建子心流
|
||||||
|
chat_stream = chat_manager.get_stream(subheartflow_id)
|
||||||
|
if chat_stream and chat_stream.group_info and chat_stream.group_info.group_id:
|
||||||
|
group_id = chat_stream.group_info.group_id
|
||||||
|
if group_id in global_config.talk_read_only:
|
||||||
|
logger.info(f"群组 {group_id} 在只读模式中,跳过创建子心流")
|
||||||
|
return None
|
||||||
|
|
||||||
if subheartflow_id not in self._subheartflows:
|
if subheartflow_id not in self._subheartflows:
|
||||||
logger.debug(f"创建 subheartflow: {subheartflow_id}")
|
logger.debug(f"创建 subheartflow: {subheartflow_id}")
|
||||||
subheartflow = SubHeartflow(subheartflow_id)
|
subheartflow = SubHeartflow(subheartflow_id)
|
||||||
|
|
@ -169,6 +180,17 @@ class Heartflow:
|
||||||
|
|
||||||
def get_subheartflow(self, observe_chat_id):
|
def get_subheartflow(self, observe_chat_id):
|
||||||
"""获取指定ID的SubHeartflow实例"""
|
"""获取指定ID的SubHeartflow实例"""
|
||||||
|
# 检查是否是只读群组的ID
|
||||||
|
# 正常情况下,只读群组在bot.py中已被过滤,不会调用此方法
|
||||||
|
# 此检查防止系统在代码变更或异常情况下意外为只读群组创建或获取子心流
|
||||||
|
chat_stream = chat_manager.get_stream(observe_chat_id)
|
||||||
|
if chat_stream and chat_stream.group_info and chat_stream.group_info.group_id:
|
||||||
|
group_id = chat_stream.group_info.group_id
|
||||||
|
if group_id in global_config.talk_read_only:
|
||||||
|
logger.debug(f"群组 {group_id} 在只读模式中,跳过获取子心流")
|
||||||
|
# 返回None表示这是只读群组
|
||||||
|
return None
|
||||||
|
|
||||||
return self._subheartflows.get(observe_chat_id)
|
return self._subheartflows.get(observe_chat_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,12 +136,25 @@ class ChatBot:
|
||||||
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
||||||
else: # 群聊处理
|
else: # 群聊处理
|
||||||
if groupinfo.group_id in global_config.talk_allowed_groups:
|
if groupinfo.group_id in global_config.talk_allowed_groups:
|
||||||
if global_config.response_mode == "heart_flow":
|
# 检查是否在只读取不回复的群组列表中
|
||||||
await self.think_flow_chat.process_message(message_data)
|
if groupinfo.group_id in global_config.talk_read_only:
|
||||||
elif global_config.response_mode == "reasoning":
|
# 只读取消息,不回复
|
||||||
await self.reasoning_chat.process_message(message_data)
|
logger.info(f"群组 {groupinfo.group_id}({groupinfo.group_name}) 在只读模式中,只读取不回复消息")
|
||||||
|
# 创建聊天流
|
||||||
|
chat = await chat_manager.get_or_create_stream(
|
||||||
|
platform=message.message_info.platform,
|
||||||
|
user_info=userinfo,
|
||||||
|
group_info=groupinfo,
|
||||||
|
)
|
||||||
|
message.update_chat_stream(chat)
|
||||||
|
await self.only_process_chat.process_message(message)
|
||||||
else:
|
else:
|
||||||
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
if global_config.response_mode == "heart_flow":
|
||||||
|
await self.think_flow_chat.process_message(message_data)
|
||||||
|
elif global_config.response_mode == "reasoning":
|
||||||
|
await self.reasoning_chat.process_message(message_data)
|
||||||
|
else:
|
||||||
|
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"预处理消息失败: {e}")
|
logger.error(f"预处理消息失败: {e}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,16 @@ class ThinkFlowChat:
|
||||||
message.update_chat_stream(chat)
|
message.update_chat_stream(chat)
|
||||||
|
|
||||||
# 创建心流与chat的观察
|
# 创建心流与chat的观察
|
||||||
heartflow.create_subheartflow(chat.stream_id)
|
sub_heartflow = heartflow.create_subheartflow(chat.stream_id)
|
||||||
|
|
||||||
|
# 如果创建子心流返回None,表示这是只读群组,只读取消息但不回复
|
||||||
|
# 正常情况下,只读群组在bot.py中已被过滤,不会执行到这里
|
||||||
|
# 此检查防止由于代码路径变更或其他异常情况导致只读群组消息进入思维流处理流程
|
||||||
|
if sub_heartflow is None:
|
||||||
|
logger.info(f"群组 {groupinfo.group_id}({groupinfo.group_name}) 在只读模式中,只读取不回复消息")
|
||||||
|
await message.process()
|
||||||
|
await self.storage.store_message(message, chat)
|
||||||
|
return
|
||||||
|
|
||||||
await message.process()
|
await message.process()
|
||||||
logger.debug(f"消息处理成功{message.processed_plain_text}")
|
logger.debug(f"消息处理成功{message.processed_plain_text}")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[inner]
|
[inner]
|
||||||
version = "1.2.4"
|
version = "1.2.5"
|
||||||
|
|
||||||
|
|
||||||
#以下是给开发人员阅读的,一般用户不需要阅读
|
#以下是给开发人员阅读的,一般用户不需要阅读
|
||||||
|
|
@ -31,6 +31,7 @@ talk_allowed = [
|
||||||
123,
|
123,
|
||||||
] #可以回复消息的群号码
|
] #可以回复消息的群号码
|
||||||
talk_frequency_down = [] #降低回复频率的群号码
|
talk_frequency_down = [] #降低回复频率的群号码
|
||||||
|
talk_read_only = [] #只读取消息但不回复的群号码(心流)
|
||||||
ban_user_id = [] #禁止回复和读取消息的QQ号
|
ban_user_id = [] #禁止回复和读取消息的QQ号
|
||||||
|
|
||||||
[personality]
|
[personality]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue