mirror of https://github.com/Mai-with-u/MaiBot.git
feat:正确拦截消息
parent
0baa73aaf5
commit
265d946ebd
|
|
@ -164,7 +164,8 @@ class BrainChatting:
|
|||
limit=20,
|
||||
limit_mode="latest",
|
||||
filter_mai=True,
|
||||
filter_command=True,
|
||||
filter_command=False,
|
||||
filter_no_read_command=True,
|
||||
)
|
||||
|
||||
if len(recent_messages_list) >= 1:
|
||||
|
|
|
|||
|
|
@ -189,7 +189,8 @@ class HeartFChatting:
|
|||
limit=20,
|
||||
limit_mode="latest",
|
||||
filter_mai=True,
|
||||
filter_command=True,
|
||||
filter_command=False,
|
||||
filter_no_read_command=True,
|
||||
)
|
||||
|
||||
# 根据连续 no_reply 次数动态调整阈值
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ class ChatBot:
|
|||
try:
|
||||
# 执行命令
|
||||
success, response, intercept_message = await command_instance.execute()
|
||||
message.is_no_read_command = bool(intercept_message)
|
||||
|
||||
# 记录命令执行结果
|
||||
if success:
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ class MessageRecv(Message):
|
|||
self.is_notify = False
|
||||
|
||||
self.is_command = False
|
||||
self.is_no_read_command = False
|
||||
|
||||
self.priority_mode = "interest"
|
||||
self.priority_info = None
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ class MessageStorage:
|
|||
key_words = ""
|
||||
key_words_lite = ""
|
||||
selected_expressions = message.selected_expressions
|
||||
is_no_read_command = False
|
||||
else:
|
||||
filtered_display_message = ""
|
||||
interest_value = message.interest_value
|
||||
|
|
@ -80,6 +81,7 @@ class MessageStorage:
|
|||
is_picid = message.is_picid
|
||||
is_notify = message.is_notify
|
||||
is_command = message.is_command
|
||||
is_no_read_command = getattr(message, "is_no_read_command", False)
|
||||
# 序列化关键词列表为JSON字符串
|
||||
key_words = MessageStorage._serialize_keywords(message.key_words)
|
||||
key_words_lite = MessageStorage._serialize_keywords(message.key_words_lite)
|
||||
|
|
@ -131,6 +133,7 @@ class MessageStorage:
|
|||
is_picid=is_picid,
|
||||
is_notify=is_notify,
|
||||
is_command=is_command,
|
||||
is_no_read_command=is_no_read_command,
|
||||
key_words=key_words,
|
||||
key_words_lite=key_words_lite,
|
||||
selected_expressions=selected_expressions,
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ def get_raw_msg_by_timestamp_with_chat(
|
|||
limit_mode: str = "latest",
|
||||
filter_bot=False,
|
||||
filter_command=False,
|
||||
filter_no_read_command=False,
|
||||
) -> List[DatabaseMessages]:
|
||||
"""获取在特定聊天从指定时间戳到指定时间戳的消息,按时间升序排序,返回消息列表
|
||||
limit: 限制返回的消息数量,0为不限制
|
||||
|
|
@ -137,6 +138,7 @@ def get_raw_msg_by_timestamp_with_chat(
|
|||
limit_mode=limit_mode,
|
||||
filter_bot=filter_bot,
|
||||
filter_command=filter_command,
|
||||
filter_no_read_command=filter_no_read_command,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -147,6 +149,8 @@ def get_raw_msg_by_timestamp_with_chat_inclusive(
|
|||
limit: int = 0,
|
||||
limit_mode: str = "latest",
|
||||
filter_bot=False,
|
||||
filter_command=False,
|
||||
filter_no_read_command=False,
|
||||
) -> List[DatabaseMessages]:
|
||||
"""获取在特定聊天从指定时间戳到指定时间戳的消息(包含边界),按时间升序排序,返回消息列表
|
||||
limit: 限制返回的消息数量,0为不限制
|
||||
|
|
@ -157,7 +161,13 @@ def get_raw_msg_by_timestamp_with_chat_inclusive(
|
|||
sort_order = [("time", 1)] if limit == 0 else None
|
||||
# 直接将 limit_mode 传递给 find_messages
|
||||
return find_messages(
|
||||
message_filter=filter_query, sort=sort_order, limit=limit, limit_mode=limit_mode, filter_bot=filter_bot
|
||||
message_filter=filter_query,
|
||||
sort=sort_order,
|
||||
limit=limit,
|
||||
limit_mode=limit_mode,
|
||||
filter_bot=filter_bot,
|
||||
filter_command=filter_command,
|
||||
filter_no_read_command=filter_no_read_command,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ class DatabaseMessages(BaseDataModel):
|
|||
is_emoji: bool = False,
|
||||
is_picid: bool = False,
|
||||
is_command: bool = False,
|
||||
is_no_read_command: bool = False,
|
||||
is_notify: bool = False,
|
||||
selected_expressions: Optional[str] = None,
|
||||
user_id: str = "",
|
||||
|
|
@ -119,6 +120,7 @@ class DatabaseMessages(BaseDataModel):
|
|||
self.is_emoji = is_emoji
|
||||
self.is_picid = is_picid
|
||||
self.is_command = is_command
|
||||
self.is_no_read_command = is_no_read_command
|
||||
self.is_notify = is_notify
|
||||
|
||||
self.selected_expressions = selected_expressions
|
||||
|
|
@ -186,6 +188,7 @@ class DatabaseMessages(BaseDataModel):
|
|||
"is_emoji": self.is_emoji,
|
||||
"is_picid": self.is_picid,
|
||||
"is_command": self.is_command,
|
||||
"is_no_read_command": self.is_no_read_command,
|
||||
"is_notify": self.is_notify,
|
||||
"selected_expressions": self.selected_expressions,
|
||||
"user_id": self.user_info.user_id,
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ class Messages(BaseModel):
|
|||
is_emoji = BooleanField(default=False)
|
||||
is_picid = BooleanField(default=False)
|
||||
is_command = BooleanField(default=False)
|
||||
is_no_read_command = BooleanField(default=False)
|
||||
is_notify = BooleanField(default=False)
|
||||
|
||||
selected_expressions = TextField(null=True)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ def find_messages(
|
|||
limit_mode: str = "latest",
|
||||
filter_bot=False,
|
||||
filter_command=False,
|
||||
filter_no_read_command=False,
|
||||
) -> List[DatabaseMessages]:
|
||||
"""
|
||||
根据提供的过滤器、排序和限制条件查找消息。
|
||||
|
|
@ -84,6 +85,9 @@ def find_messages(
|
|||
# 使用按位取反构造 Peewee 的 NOT 条件,避免直接与 False 比较
|
||||
query = query.where(~Messages.is_command)
|
||||
|
||||
if filter_no_read_command:
|
||||
query = query.where(~Messages.is_no_read_command)
|
||||
|
||||
if limit > 0:
|
||||
if limit_mode == "earliest":
|
||||
# 获取时间最早的 limit 条记录,已经是正序
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ def get_messages_by_time_in_chat(
|
|||
limit_mode: str = "latest",
|
||||
filter_mai: bool = False,
|
||||
filter_command: bool = False,
|
||||
filter_no_read_command: bool = False,
|
||||
) -> List[DatabaseMessages]:
|
||||
"""
|
||||
获取指定聊天中指定时间范围内的消息
|
||||
|
|
@ -110,6 +111,7 @@ def get_messages_by_time_in_chat(
|
|||
limit_mode=limit_mode,
|
||||
filter_bot=filter_mai,
|
||||
filter_command=filter_command,
|
||||
filter_no_read_command=filter_no_read_command,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -121,6 +123,7 @@ def get_messages_by_time_in_chat_inclusive(
|
|||
limit_mode: str = "latest",
|
||||
filter_mai: bool = False,
|
||||
filter_command: bool = False,
|
||||
filter_no_read_command: bool = False,
|
||||
) -> List[DatabaseMessages]:
|
||||
"""
|
||||
获取指定聊天中指定时间范围内的消息(包含边界)
|
||||
|
|
@ -147,15 +150,19 @@ def get_messages_by_time_in_chat_inclusive(
|
|||
raise ValueError("chat_id 不能为空")
|
||||
if not isinstance(chat_id, str):
|
||||
raise ValueError("chat_id 必须是字符串类型")
|
||||
if filter_mai:
|
||||
return filter_mai_messages(
|
||||
get_raw_msg_by_timestamp_with_chat_inclusive(
|
||||
chat_id, start_time, end_time, limit, limit_mode, filter_command
|
||||
)
|
||||
)
|
||||
return get_raw_msg_by_timestamp_with_chat_inclusive(
|
||||
chat_id, start_time, end_time, limit, limit_mode, filter_command
|
||||
messages = get_raw_msg_by_timestamp_with_chat_inclusive(
|
||||
chat_id=chat_id,
|
||||
timestamp_start=start_time,
|
||||
timestamp_end=end_time,
|
||||
limit=limit,
|
||||
limit_mode=limit_mode,
|
||||
filter_bot=filter_mai,
|
||||
filter_command=filter_command,
|
||||
filter_no_read_command=filter_no_read_command,
|
||||
)
|
||||
if filter_mai:
|
||||
return filter_mai_messages(messages)
|
||||
return messages
|
||||
|
||||
|
||||
def get_messages_by_time_in_chat_for_users(
|
||||
|
|
|
|||
Loading…
Reference in New Issue