合并条件更严格,增加配置选项

This commit is contained in:
meng_xi_pan
2025-04-05 01:00:05 +08:00
parent 9ba6c8dacd
commit 02643d729e
4 changed files with 21 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ from typing import Dict
from collections import OrderedDict from collections import OrderedDict
import random import random
import time import time
from ..config.config import global_config
logger = get_module_logger("message_buffer") logger = get_module_logger("message_buffer")
@@ -32,6 +33,11 @@ class MessageBuffer:
async def start_caching_messages(self, message:MessageRecv): async def start_caching_messages(self, message:MessageRecv):
"""添加消息,启动缓冲""" """添加消息,启动缓冲"""
if not global_config.message_buffer:
person_id = person_info_manager.get_person_id(message.message_info.user_info.platform,
message.message_info.user_info.user_id)
asyncio.create_task(self.save_message_interval(person_id, message.message_info))
return
person_id_ = self.get_person_id_(message.message_info.platform, person_id_ = self.get_person_id_(message.message_info.platform,
message.message_info.user_info.user_id, message.message_info.user_info.user_id,
message.message_info.group_info.group_id) message.message_info.group_info.group_id)
@@ -98,6 +104,8 @@ class MessageBuffer:
async def query_buffer_result(self, message:MessageRecv) -> bool: async def query_buffer_result(self, message:MessageRecv) -> bool:
"""查询缓冲结果,并清理""" """查询缓冲结果,并清理"""
if not global_config.message_buffer:
return True
person_id_ = self.get_person_id_(message.message_info.platform, person_id_ = self.get_person_id_(message.message_info.platform,
message.message_info.user_info.user_id, message.message_info.user_info.user_id,
message.message_info.group_info.group_id) message.message_info.group_info.group_id)
@@ -122,6 +130,7 @@ class MessageBuffer:
combined_text = [] combined_text = []
found = False found = False
type = "text" type = "text"
is_update = True
for msg_id, msg in self.buffer_pool[person_id_].items(): for msg_id, msg in self.buffer_pool[person_id_].items():
if msg_id == message.message_info.message_id: if msg_id == message.message_info.message_id:
found = True found = True
@@ -133,14 +142,16 @@ class MessageBuffer:
elif msg.result == "F": elif msg.result == "F":
# 收集F消息的文本内容 # 收集F消息的文本内容
if (hasattr(msg.message, 'processed_plain_text') if (hasattr(msg.message, 'processed_plain_text')
and msg.message.message_segment.type == "text"
and msg.message.processed_plain_text): and msg.message.processed_plain_text):
if msg.message.message_segment.type == "text":
combined_text.append(msg.message.processed_plain_text) combined_text.append(msg.message.processed_plain_text)
elif msg.message.message_segment.type != "text":
is_update = False
elif msg.result == "U": elif msg.result == "U":
logger.debug(f"异常未处理信息id {msg.message.message_info.message_id}") logger.debug(f"异常未处理信息id {msg.message.message_info.message_id}")
# 更新当前消息的processed_plain_text # 更新当前消息的processed_plain_text
if combined_text and combined_text[0] != message.processed_plain_text: if combined_text and combined_text[0] != message.processed_plain_text and is_update:
if type == "text": if type == "text":
message.processed_plain_text = "".join(combined_text) message.processed_plain_text = "".join(combined_text)
logger.debug(f"整合了{len(combined_text)-1}条F消息的内容到当前消息") logger.debug(f"整合了{len(combined_text)-1}条F消息的内容到当前消息")

View File

@@ -159,6 +159,7 @@ class BotConfig:
emoji_chance: float = 0.2 # 发送表情包的基础概率 emoji_chance: float = 0.2 # 发送表情包的基础概率
thinking_timeout: int = 120 # 思考时间 thinking_timeout: int = 120 # 思考时间
max_response_length: int = 1024 # 最大回复长度 max_response_length: int = 1024 # 最大回复长度
message_buffer: bool = True # 消息缓冲器
ban_words = set() ban_words = set()
ban_msgs_regex = set() ban_msgs_regex = set()
@@ -502,6 +503,8 @@ class BotConfig:
if config.INNER_VERSION in SpecifierSet(">=0.0.11"): if config.INNER_VERSION in SpecifierSet(">=0.0.11"):
config.max_response_length = msg_config.get("max_response_length", config.max_response_length) config.max_response_length = msg_config.get("max_response_length", config.max_response_length)
if config.INNER_VERSION in SpecifierSet(">=1.1.4"):
config.message_buffer = msg_config.get("message_buffer", config.message_buffer)
def memory(parent: dict): def memory(parent: dict):
memory_config = parent["memory"] memory_config = parent["memory"]

View File

@@ -242,7 +242,7 @@ class PersonInfoManager:
time_interval = [] time_interval = []
for t1, t2 in zip(msg_interval_list_, msg_interval_list_[1:]): for t1, t2 in zip(msg_interval_list_, msg_interval_list_[1:]):
delta = t2 - t1 delta = t2 - t1
if delta < 6000 and delta > 0: # 小于6 if delta < 8000 and delta > 0: # 小于8
time_interval.append(delta) time_interval.append(delta)
if len(time_interval) > 30: if len(time_interval) > 30:
@@ -263,7 +263,7 @@ class PersonInfoManager:
time_series.plot(kind='kde', color='mediumpurple', linewidth=1, label='Density') time_series.plot(kind='kde', color='mediumpurple', linewidth=1, label='Density')
plt.grid(True, alpha=0.2) plt.grid(True, alpha=0.2)
plt.xlim(0, 6000) plt.xlim(0, 8000)
plt.title(f"Message Interval Distribution (User: {person_id[:8]}...)") plt.title(f"Message Interval Distribution (User: {person_id[:8]}...)")
plt.xlabel("Interval (ms)") plt.xlabel("Interval (ms)")
plt.ylabel("Density") plt.ylabel("Density")

View File

@@ -1,5 +1,5 @@
[inner] [inner]
version = "1.1.3" version = "1.1.4"
#以下是给开发人员阅读的,一般用户不需要阅读 #以下是给开发人员阅读的,一般用户不需要阅读
@@ -72,6 +72,7 @@ max_context_size = 12 # 麦麦获得的上文数量建议12太短太长都
emoji_chance = 0.2 # 麦麦使用表情包的概率 emoji_chance = 0.2 # 麦麦使用表情包的概率
thinking_timeout = 60 # 麦麦最长思考时间,超过这个时间的思考会放弃 thinking_timeout = 60 # 麦麦最长思考时间,超过这个时间的思考会放弃
max_response_length = 256 # 麦麦回答的最大token数 max_response_length = 256 # 麦麦回答的最大token数
message_buffer = true # 启用消息缓冲器?
ban_words = [ ban_words = [
# "403","张三" # "403","张三"
] ]