From fda07587a97f5c9431f439680d62312f85c20777 Mon Sep 17 00:00:00 2001 From: Bakadax Date: Sun, 6 Apr 2025 15:26:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/utils.py | 43 ++++++++++++++----- .../reasoning_chat/reasoning_chat.py | 17 +------- .../think_flow_chat/think_flow_chat.py | 17 +------- 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index 4eae47263..1b9196e14 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -42,17 +42,38 @@ def is_mentioned_bot_in_message(message: MessageRecv) -> bool: """检查消息是否提到了机器人""" keywords = [global_config.BOT_NICKNAME] nicknames = global_config.BOT_ALIAS_NAMES - if re.match(f"回复[\s\S]*?\({global_config.BOT_QQ}\)的消息,说:", message.processed_plain_text): - return True - message_content = re.sub(r'\@[\s\S]*?((\d+))','', message.processed_plain_text) - message_content = re.sub(r'回复[\s\S]*?\((\d+)\)的消息,说: ','', message_content) - for keyword in keywords: - if keyword in message_content: - return True - for nickname in nicknames: - if nickname in message_content: - return True - return False + reply_probability = 0 + is_at = False + is_mentioned = False + + # 判断是否被@ + if re.search(f"@[\s\S]*?(id:{global_config.BOT_QQ})", message.processed_plain_text): + is_at = True + is_mentioned = True + + if is_at and global_config.at_bot_inevitable_reply: + reply_probability = 1 + logger.info("被@,回复概率设置为100%") + else: + if not is_mentioned: + + # 判断是否被回复 + if re.match(f"回复[\s\S]*?\({global_config.BOT_QQ}\)的消息,说:", message.processed_plain_text): + is_mentioned = True + + # 判断内容中是否被提及 + message_content = re.sub(r'\@[\s\S]*?((\d+))','', message.processed_plain_text) + message_content = re.sub(r'回复[\s\S]*?\((\d+)\)的消息,说: ','', message_content) + for keyword in keywords: + if keyword in message_content: + is_mentioned = True + for nickname in nicknames: + if nickname in message_content: + is_mentioned = True + if is_mentioned and global_config.mentioned_bot_inevitable_reply: + reply_probability = 1 + logger.info("被提及,回复概率设置为100%") + return is_mentioned, reply_probability async def get_embedding(text, request_type="embedding"): diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py index a95358152..aa00992a6 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -187,22 +187,7 @@ class ReasoningChat: return # 处理提及 - reply_probability = 0 - is_at = False - is_mentioned = False - if re.search(f"@[\s\S]*?(id:{global_config.BOT_QQ})", message.processed_plain_text): - is_at = True - is_mentioned = True - - if is_at and global_config.at_bot_inevitable_reply: - reply_probability = 1 - logger.info("被@,回复概率设置为100%") - else: - if not is_mentioned: - is_mentioned = is_mentioned_bot_in_message(message) - if is_mentioned and global_config.mentioned_bot_inevitable_reply: - reply_probability = 1 - logger.info("被提及,回复概率设置为100%") + is_mentioned, reply_probability = is_mentioned_bot_in_message(message) # 计算回复意愿 current_willing = willing_manager.get_willing(chat_stream=chat) diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index 6cf796e5d..c0af9d6b5 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -212,22 +212,7 @@ class ThinkFlowChat: return # 处理提及 - reply_probability = 0 - is_at = False - is_mentioned = False - if re.search(f"@[\s\S]*?(id:{global_config.BOT_QQ})", message.processed_plain_text): - is_at = True - is_mentioned = True - - if is_at and global_config.at_bot_inevitable_reply: - reply_probability = 1 - logger.info("被@,回复概率设置为100%") - else: - if not is_mentioned: - is_mentioned = is_mentioned_bot_in_message(message) - if is_mentioned and global_config.mentioned_bot_inevitable_reply: - reply_probability = 1 - logger.info("被提及,回复概率设置为100%") + is_mentioned, reply_probability = is_mentioned_bot_in_message(message) # 计算回复意愿