feat:noreply不考虑command
This commit is contained in:
@@ -10,8 +10,7 @@
|
||||
"license": "GPL-v3.0-or-later",
|
||||
|
||||
"host_application": {
|
||||
"min_version": "0.8.0",
|
||||
"max_version": "0.8.0"
|
||||
"min_version": "0.9.0"
|
||||
},
|
||||
"homepage_url": "https://github.com/MaiM-with-u/maibot",
|
||||
"repository_url": "https://github.com/MaiM-with-u/maibot",
|
||||
|
||||
@@ -98,6 +98,7 @@ class ChatBot:
|
||||
# 使用新的组件注册中心查找命令
|
||||
command_result = component_registry.find_command_by_text(text)
|
||||
if command_result:
|
||||
message.is_command = True
|
||||
command_class, matched_groups, intercept_message, plugin_name = command_result
|
||||
|
||||
# 获取插件配置
|
||||
|
||||
@@ -107,6 +107,9 @@ class MessageRecv(Message):
|
||||
self.is_picid = False
|
||||
self.has_picid = False
|
||||
self.is_mentioned = None
|
||||
|
||||
self.is_command = False
|
||||
|
||||
self.priority_mode = "interest"
|
||||
self.priority_info = None
|
||||
self.interest_value: float = None # type: ignore
|
||||
|
||||
@@ -43,6 +43,7 @@ class MessageStorage:
|
||||
priority_info = {}
|
||||
is_emoji = False
|
||||
is_picid = False
|
||||
is_command = False
|
||||
else:
|
||||
filtered_display_message = ""
|
||||
interest_value = message.interest_value
|
||||
@@ -52,6 +53,7 @@ class MessageStorage:
|
||||
priority_info = message.priority_info
|
||||
is_emoji = message.is_emoji
|
||||
is_picid = message.is_picid
|
||||
is_command = message.is_command
|
||||
|
||||
chat_info_dict = chat_stream.to_dict()
|
||||
user_info_dict = message.message_info.user_info.to_dict() # type: ignore
|
||||
@@ -96,6 +98,7 @@ class MessageStorage:
|
||||
priority_info=priority_info,
|
||||
is_emoji=is_emoji,
|
||||
is_picid=is_picid,
|
||||
is_command=is_command,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("存储消息失败")
|
||||
|
||||
@@ -36,6 +36,7 @@ def get_raw_msg_by_timestamp_with_chat(
|
||||
limit: int = 0,
|
||||
limit_mode: str = "latest",
|
||||
filter_bot=False,
|
||||
filter_command=False,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""获取在特定聊天从指定时间戳到指定时间戳的消息,按时间升序排序,返回消息列表
|
||||
limit: 限制返回的消息数量,0为不限制
|
||||
@@ -46,7 +47,12 @@ def get_raw_msg_by_timestamp_with_chat(
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ class Messages(BaseModel):
|
||||
additional_config = TextField(null=True)
|
||||
is_emoji = BooleanField(default=False)
|
||||
is_picid = BooleanField(default=False)
|
||||
|
||||
is_command = BooleanField(default=False)
|
||||
class Meta:
|
||||
# database = db # 继承自 BaseModel
|
||||
table_name = "messages"
|
||||
|
||||
@@ -23,6 +23,7 @@ def find_messages(
|
||||
limit: int = 0,
|
||||
limit_mode: str = "latest",
|
||||
filter_bot=False,
|
||||
filter_command=False,
|
||||
) -> List[dict[str, Any]]:
|
||||
"""
|
||||
根据提供的过滤器、排序和限制条件查找消息。
|
||||
@@ -75,6 +76,9 @@ def find_messages(
|
||||
if filter_bot:
|
||||
query = query.where(Messages.user_id != global_config.bot.qq_account)
|
||||
|
||||
if filter_command:
|
||||
query = query.where(Messages.is_command == False)
|
||||
|
||||
if limit > 0:
|
||||
if limit_mode == "earliest":
|
||||
# 获取时间最早的 limit 条记录,已经是正序
|
||||
|
||||
@@ -69,6 +69,7 @@ def get_messages_by_time_in_chat(
|
||||
limit: int = 0,
|
||||
limit_mode: str = "latest",
|
||||
filter_mai: bool = False,
|
||||
filter_command: bool = False,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
获取指定聊天中指定时间范围内的消息
|
||||
@@ -80,7 +81,7 @@ def get_messages_by_time_in_chat(
|
||||
limit: 限制返回的消息数量,0为不限制
|
||||
limit_mode: 当limit>0时生效,'earliest'表示获取最早的记录,'latest'表示获取最新的记录
|
||||
filter_mai: 是否过滤麦麦自身的消息,默认为False
|
||||
|
||||
filter_command: 是否过滤命令消息,默认为False
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 消息列表
|
||||
|
||||
@@ -96,8 +97,8 @@ def get_messages_by_time_in_chat(
|
||||
if not isinstance(chat_id, str):
|
||||
raise ValueError("chat_id 必须是字符串类型")
|
||||
if filter_mai:
|
||||
return filter_mai_messages(get_raw_msg_by_timestamp_with_chat(chat_id, start_time, end_time, limit, limit_mode))
|
||||
return get_raw_msg_by_timestamp_with_chat(chat_id, start_time, end_time, limit, limit_mode)
|
||||
return filter_mai_messages(get_raw_msg_by_timestamp_with_chat(chat_id, start_time, end_time, limit, limit_mode, filter_command))
|
||||
return get_raw_msg_by_timestamp_with_chat(chat_id, start_time, end_time, limit, limit_mode, filter_command)
|
||||
|
||||
|
||||
def get_messages_by_time_in_chat_inclusive(
|
||||
@@ -107,6 +108,7 @@ def get_messages_by_time_in_chat_inclusive(
|
||||
limit: int = 0,
|
||||
limit_mode: str = "latest",
|
||||
filter_mai: bool = False,
|
||||
filter_command: bool = False,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
获取指定聊天中指定时间范围内的消息(包含边界)
|
||||
@@ -135,9 +137,9 @@ def get_messages_by_time_in_chat_inclusive(
|
||||
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)
|
||||
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)
|
||||
return get_raw_msg_by_timestamp_with_chat_inclusive(chat_id, start_time, end_time, limit, limit_mode, filter_command)
|
||||
|
||||
|
||||
def get_messages_by_time_in_chat_for_users(
|
||||
|
||||
@@ -79,7 +79,11 @@ class NoReplyAction(BaseAction):
|
||||
|
||||
# 1. 检查新消息
|
||||
recent_messages_dict = message_api.get_messages_by_time_in_chat(
|
||||
chat_id=self.chat_id, start_time=start_time, end_time=current_time
|
||||
chat_id=self.chat_id,
|
||||
start_time=start_time,
|
||||
end_time=current_time,
|
||||
filter_mai=True,
|
||||
filter_command=True,
|
||||
)
|
||||
new_message_count = len(recent_messages_dict)
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ expression_groups = [
|
||||
enable_relationship = true # 是否启用关系系统
|
||||
relation_frequency = 1 # 关系频率,麦麦构建关系的频率
|
||||
|
||||
|
||||
[chat] #麦麦的聊天通用设置
|
||||
focus_value = 1
|
||||
# 麦麦的专注思考能力,越低越容易专注,消耗token也越多
|
||||
|
||||
Reference in New Issue
Block a user