This commit is contained in:
Bakadax
2025-04-06 14:30:43 +08:00
parent 594c30ab74
commit 2dd44ec69c
5 changed files with 56 additions and 7 deletions

View File

@@ -42,11 +42,15 @@ def is_mentioned_bot_in_message(message: MessageRecv) -> bool:
"""检查消息是否提到了机器人"""
keywords = [global_config.BOT_NICKNAME]
nicknames = global_config.BOT_ALIAS_NAMES
if f"回复{global_config.BOT_NICKNAME}({global_config.BOT_QQ})的消息,说: " in 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.processed_plain_text:
if keyword in message_content:
return True
for nickname in nicknames:
if nickname in message.processed_plain_text:
if nickname in message_content:
return True
return False

View File

@@ -186,7 +186,23 @@ class ReasoningChat:
logger.info("触发缓冲,已炸飞消息列")
return
is_mentioned = is_mentioned_bot_in_message(message)
# 处理提及
reply_probability = 0
is_at = False
is_mentioned = False
if f"@{global_config.BOT_NICKNAME}({global_config.BOT_QQ})" in 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.metioned_bot_inevitable_reply:
reply_probability = 1
logger.info("被提及回复概率设置为100%")
# 计算回复意愿
current_willing = willing_manager.get_willing(chat_stream=chat)
@@ -194,7 +210,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 +218,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

View File

@@ -211,7 +211,23 @@ class ThinkFlowChat:
logger.info("触发缓冲,已炸飞消息列")
return
is_mentioned = is_mentioned_bot_in_message(message)
# 处理提及
reply_probability = 0
is_at = False
is_mentioned = False
if f"@{global_config.BOT_NICKNAME}({global_config.BOT_QQ})" in 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.metioned_bot_inevitable_reply:
reply_probability = 1
logger.info("被提及回复概率设置为100%")
# 计算回复意愿
@@ -226,7 +242,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 +250,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}")

View File

@@ -195,6 +195,8 @@ class BotConfig:
response_interested_rate_amplifier: float = 1.0 # 回复兴趣度放大系数
down_frequency_rate: float = 3 # 降低回复频率的群组回复意愿降低系数
emoji_response_penalty: float = 0.0 # 表情包回复惩罚
metioned_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.metioned_bot_inevitable_reply = willing_config.get(
"metioned_bot_inevitable_reply", config.metioned_bot_inevitable_reply
)
config.at_bot_inevitable_reply = willing_config.get(
"at_bot_inevitable_reply", config.at_bot_inevitable_reply
)
def model(parent: dict):
# 加载模型配置

View File

@@ -105,7 +105,8 @@ response_willing_amplifier = 1 # 麦麦回复意愿放大系数一般为1
response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数,听到记忆里的内容时放大系数
down_frequency_rate = 3 # 降低回复频率的群组回复意愿降低系数 除法
emoji_response_penalty = 0.1 # 表情包回复惩罚系数设为0为不回复单个表情包减少单独回复表情包的概率
metioned_bot_inevitable_reply = false # 提及 bot 必然回复
at_bot_inevitable_reply = false # @bot 必然回复
[emoji]
max_emoji_num = 120 # 表情包最大数量