diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index 26bd3a171..1b9196e14 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -42,13 +42,38 @@ def is_mentioned_bot_in_message(message: MessageRecv) -> bool: """检查消息是否提到了机器人""" keywords = [global_config.BOT_NICKNAME] nicknames = global_config.BOT_ALIAS_NAMES - for keyword in keywords: - if keyword in message.processed_plain_text: - return True - for nickname in nicknames: - if nickname in message.processed_plain_text: - 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 13f055185..aa00992a6 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -186,7 +186,8 @@ class ReasoningChat: logger.info("触发缓冲,已炸飞消息列") return - is_mentioned = is_mentioned_bot_in_message(message) + # 处理提及 + is_mentioned, reply_probability = is_mentioned_bot_in_message(message) # 计算回复意愿 current_willing = willing_manager.get_willing(chat_stream=chat) @@ -194,7 +195,7 @@ class ReasoningChat: # 意愿激活 timer1 = time.time() - reply_probability = await willing_manager.change_reply_willing_received( + real_reply_probability = await willing_manager.change_reply_willing_received( chat_stream=chat, is_mentioned_bot=is_mentioned, config=global_config, @@ -202,6 +203,8 @@ class ReasoningChat: interested_rate=interested_rate, sender_id=str(message.message_info.user_info.user_id), ) + if reply_probability != 1 or (groupinfo and (groupinfo.group_id not in global_config.talk_allowed_groups)): + reply_probability = real_reply_probability timer2 = time.time() timing_results["意愿激活"] = timer2 - timer1 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 9c2eebd94..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 @@ -211,7 +211,8 @@ class ThinkFlowChat: logger.info("触发缓冲,已炸飞消息列") return - is_mentioned = is_mentioned_bot_in_message(message) + # 处理提及 + is_mentioned, reply_probability = is_mentioned_bot_in_message(message) # 计算回复意愿 @@ -226,7 +227,7 @@ class ThinkFlowChat: # 意愿激活 timer1 = time.time() - reply_probability = await willing_manager.change_reply_willing_received( + real_reply_probability = await willing_manager.change_reply_willing_received( chat_stream=chat, is_mentioned_bot=is_mentioned, config=global_config, @@ -234,6 +235,8 @@ class ThinkFlowChat: interested_rate=interested_rate, sender_id=str(message.message_info.user_info.user_id), ) + if reply_probability != 1 or (groupinfo and (groupinfo.group_id not in global_config.talk_allowed_groups)): + reply_probability = real_reply_probability timer2 = time.time() timing_results["意愿激活"] = timer2 - timer1 logger.debug(f"意愿激活: {reply_probability}") diff --git a/src/plugins/config/config.py b/src/plugins/config/config.py index 46fc44920..46f549374 100644 --- a/src/plugins/config/config.py +++ b/src/plugins/config/config.py @@ -195,6 +195,8 @@ class BotConfig: response_interested_rate_amplifier: float = 1.0 # 回复兴趣度放大系数 down_frequency_rate: float = 3 # 降低回复频率的群组回复意愿降低系数 emoji_response_penalty: float = 0.0 # 表情包回复惩罚 + mentioned_bot_inevitable_reply: bool = False # 提及 bot 必然回复 + at_bot_inevitable_reply: bool = False # @bot 必然回复 # response response_mode: str = "heart_flow" # 回复策略 @@ -439,6 +441,12 @@ class BotConfig: config.emoji_response_penalty = willing_config.get( "emoji_response_penalty", config.emoji_response_penalty ) + config.mentioned_bot_inevitable_reply = willing_config.get( + "mentioned_bot_inevitable_reply", config.mentioned_bot_inevitable_reply + ) + config.at_bot_inevitable_reply = willing_config.get( + "at_bot_inevitable_reply", config.at_bot_inevitable_reply + ) def model(parent: dict): # 加载模型配置 diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index acc089d49..d7a5cdaea 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -105,7 +105,8 @@ response_willing_amplifier = 1 # 麦麦回复意愿放大系数,一般为1 response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数,听到记忆里的内容时放大系数 down_frequency_rate = 3 # 降低回复频率的群组回复意愿降低系数 除法 emoji_response_penalty = 0.1 # 表情包回复惩罚系数,设为0为不回复单个表情包,减少单独回复表情包的概率 - +mentioned_bot_inevitable_reply = false # 提及 bot 必然回复 +at_bot_inevitable_reply = false # @bot 必然回复 [emoji] max_emoji_num = 120 # 表情包最大数量