fix:planner和replyer正确处理拦截

This commit is contained in:
SengokuCola
2025-11-26 16:38:34 +08:00
parent 265d946ebd
commit 4a530a7bca
10 changed files with 36 additions and 5 deletions

View File

@@ -278,6 +278,7 @@ class BrainChatting:
chat_id=self.stream_id,
timestamp=time.time(),
limit=int(global_config.chat.max_context_size * 0.6),
filter_no_read_command=True,
)
chat_content_block, message_id_list = build_readable_messages_with_id(
messages=message_list_before_now,

View File

@@ -226,6 +226,7 @@ class BrainPlanner:
chat_id=self.chat_id,
timestamp=time.time(),
limit=int(global_config.chat.max_context_size * 0.6),
filter_no_read_command=True,
)
message_id_list: list[Tuple[str, "DatabaseMessages"]] = []
chat_content_block, message_id_list = build_readable_messages_with_id(

View File

@@ -484,6 +484,7 @@ class HeartFChatting:
chat_id=self.stream_id,
timestamp=time.time(),
limit=int(global_config.chat.max_context_size * 0.6),
filter_no_read_command=True,
)
chat_content_block, message_id_list = build_readable_messages_with_id(
messages=message_list_before_now,

View File

@@ -69,6 +69,7 @@ class ActionModifier:
chat_id=self.chat_stream.stream_id,
timestamp=time.time(),
limit=min(int(global_config.chat.max_context_size * 0.33), 10),
filter_no_read_command=True,
)
chat_content = build_readable_messages(

View File

@@ -293,6 +293,7 @@ class ActionPlanner:
chat_id=self.chat_id,
timestamp=time.time(),
limit=int(global_config.chat.max_context_size * 0.6),
filter_no_read_command=True,
)
message_id_list: list[Tuple[str, "DatabaseMessages"]] = []
chat_content_block, message_id_list = build_readable_messages_with_id(

View File

@@ -751,12 +751,14 @@ class DefaultReplyer:
chat_id=chat_id,
timestamp=reply_time_point,
limit=global_config.chat.max_context_size * 1,
filter_no_read_command=True,
)
message_list_before_short = get_raw_msg_before_timestamp_with_chat(
chat_id=chat_id,
timestamp=reply_time_point,
limit=int(global_config.chat.max_context_size * 0.33),
filter_no_read_command=True,
)
person_list_short: List[Person] = []
@@ -941,6 +943,7 @@ class DefaultReplyer:
chat_id=chat_id,
timestamp=time.time(),
limit=min(int(global_config.chat.max_context_size * 0.33), 15),
filter_no_read_command=True,
)
chat_talking_prompt_half = build_readable_messages(
message_list_before_now_half,

View File

@@ -663,6 +663,7 @@ class PrivateReplyer:
chat_id=chat_id,
timestamp=time.time(),
limit=global_config.chat.max_context_size,
filter_no_read_command=True,
)
dialogue_prompt = build_readable_messages(
@@ -677,6 +678,7 @@ class PrivateReplyer:
chat_id=chat_id,
timestamp=time.time(),
limit=int(global_config.chat.max_context_size * 0.33),
filter_no_read_command=True,
)
person_list_short: List[Person] = []
@@ -878,6 +880,7 @@ class PrivateReplyer:
chat_id=chat_id,
timestamp=time.time(),
limit=min(int(global_config.chat.max_context_size * 0.33), 15),
filter_no_read_command=True,
)
chat_talking_prompt_half = build_readable_messages(
message_list_before_now_half,

View File

@@ -302,13 +302,17 @@ def get_raw_msg_before_timestamp(timestamp: float, limit: int = 0) -> List[Datab
return find_messages(message_filter=filter_query, sort=sort_order, limit=limit)
def get_raw_msg_before_timestamp_with_chat(chat_id: str, timestamp: float, limit: int = 0) -> List[DatabaseMessages]:
def get_raw_msg_before_timestamp_with_chat(
chat_id: str, timestamp: float, limit: int = 0, filter_no_read_command: bool = False
) -> List[DatabaseMessages]:
"""获取指定时间戳之前的消息,按时间升序排序,返回消息列表
limit: 限制返回的消息数量0为不限制
"""
filter_query = {"chat_id": chat_id, "time": {"$lt": timestamp}}
sort_order = [("time", 1)]
return find_messages(message_filter=filter_query, sort=sort_order, limit=limit)
return find_messages(
message_filter=filter_query, sort=sort_order, limit=limit, filter_no_read_command=filter_no_read_command
)
def get_raw_msg_before_timestamp_with_users(
@@ -468,6 +472,8 @@ def _build_readable_messages_internal(
# 使用独立函数处理用户引用格式
if content := replace_user_references(content, platform, replace_bot_name=replace_bot_name):
if getattr(message, "is_command", False):
content = f"[is_command=True] {content}"
detailed_messages_raw.append((timestamp, person_name, content, False))
if not detailed_messages_raw: