mirror of https://github.com/Mai-with-u/MaiBot.git
fix:planner和replyer正确处理拦截
parent
265d946ebd
commit
4a530a7bca
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ class MessageAndActionModel(BaseDataModel):
|
|||
chat_info_platform: str = field(default_factory=str)
|
||||
is_action_record: bool = field(default=False)
|
||||
action_name: Optional[str] = None
|
||||
is_command: bool = field(default=False)
|
||||
is_no_read_command: bool = field(default=False)
|
||||
|
||||
@classmethod
|
||||
def from_DatabaseMessages(cls, message: "DatabaseMessages"):
|
||||
|
|
@ -34,6 +36,8 @@ class MessageAndActionModel(BaseDataModel):
|
|||
processed_plain_text=message.processed_plain_text,
|
||||
display_message=message.display_message,
|
||||
chat_info_platform=message.chat_info.platform,
|
||||
is_command=message.is_command,
|
||||
is_no_read_command=getattr(message, "is_no_read_command", False),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -280,7 +280,11 @@ def get_messages_before_time(timestamp: float, limit: int = 0, filter_mai: bool
|
|||
|
||||
|
||||
def get_messages_before_time_in_chat(
|
||||
chat_id: str, timestamp: float, limit: int = 0, filter_mai: bool = False
|
||||
chat_id: str,
|
||||
timestamp: float,
|
||||
limit: int = 0,
|
||||
filter_mai: bool = False,
|
||||
filter_no_read_command: bool = False,
|
||||
) -> List[DatabaseMessages]:
|
||||
"""
|
||||
获取指定聊天中指定时间戳之前的消息
|
||||
|
|
@ -305,9 +309,15 @@ def get_messages_before_time_in_chat(
|
|||
raise ValueError("chat_id 不能为空")
|
||||
if not isinstance(chat_id, str):
|
||||
raise ValueError("chat_id 必须是字符串类型")
|
||||
messages = get_raw_msg_before_timestamp_with_chat(
|
||||
chat_id=chat_id,
|
||||
timestamp=timestamp,
|
||||
limit=limit,
|
||||
filter_no_read_command=filter_no_read_command,
|
||||
)
|
||||
if filter_mai:
|
||||
return filter_mai_messages(get_raw_msg_before_timestamp_with_chat(chat_id, timestamp, limit))
|
||||
return get_raw_msg_before_timestamp_with_chat(chat_id, timestamp, limit)
|
||||
return filter_mai_messages(messages)
|
||||
return messages
|
||||
|
||||
|
||||
def get_messages_before_time_for_users(
|
||||
|
|
|
|||
Loading…
Reference in New Issue