From a0b1b1f8d8c2e43f30f59e192a2c43127b837b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Wed, 16 Apr 2025 16:34:33 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9is=5Fmentioned=5Fbot?= =?UTF-8?q?=5Fin=5Fmessage=E5=87=BD=E6=95=B0=EF=BC=8C=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=94=B9=E4=B8=BA=E5=85=83=E7=BB=84=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9B=9E=E5=A4=8D=E6=A6=82=E7=8E=87=E4=B8=BA?= =?UTF-8?q?=E6=B5=AE=E7=82=B9=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index b223e87da..81c19af80 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -38,15 +38,18 @@ def db_message_to_str(message_dict: Dict) -> str: return result -def is_mentioned_bot_in_message(message: MessageRecv) -> bool: +def is_mentioned_bot_in_message(message: MessageRecv) -> tuple[bool, float]: """检查消息是否提到了机器人""" keywords = [global_config.BOT_NICKNAME] nicknames = global_config.BOT_ALIAS_NAMES - reply_probability = 0 + reply_probability = 0.0 is_at = False is_mentioned = False - if message.message_info.additional_config.get("is_mentioned") is not None: + if ( + message.message_info.additional_config is not None + and message.message_info.additional_config.get("is_mentioned") is not None + ): try: reply_probability = float(message.message_info.additional_config.get("is_mentioned")) is_mentioned = True @@ -63,7 +66,7 @@ def is_mentioned_bot_in_message(message: MessageRecv) -> bool: is_mentioned = True if is_at and global_config.at_bot_inevitable_reply: - reply_probability = 1 + reply_probability = 1.0 logger.info("被@,回复概率设置为100%") else: if not is_mentioned: @@ -81,7 +84,7 @@ def is_mentioned_bot_in_message(message: MessageRecv) -> bool: if nickname in message_content: is_mentioned = True if is_mentioned and global_config.mentioned_bot_inevitable_reply: - reply_probability = 1 + reply_probability = 1.0 logger.info("被提及,回复概率设置为100%") return is_mentioned, reply_probability