From 2688a96986702d0368f378c230f144360446a9fb Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Tue, 11 Mar 2025 22:47:23 +0800 Subject: [PATCH 1/6] =?UTF-8?q?close=20SengokuCola/MaiMBot#225=20=E8=AE=A9?= =?UTF-8?q?=E9=BA=A6=E9=BA=A6=E5=8F=AF=E4=BB=A5=E6=AD=A3=E7=A1=AE=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=88=86=E4=BA=AB=E5=8D=A1=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/message.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plugins/chat/message.py b/src/plugins/chat/message.py index c777e7273..20b9869f6 100644 --- a/src/plugins/chat/message.py +++ b/src/plugins/chat/message.py @@ -1,4 +1,7 @@ import time +import html +import re +import json from dataclasses import dataclass from typing import Dict, ForwardRef, List, Optional, Union @@ -69,6 +72,17 @@ class MessageRecv(Message): message_dict: MessageCQ序列化后的字典 """ self.message_info = BaseMessageInfo.from_dict(message_dict.get('message_info', {})) + + message_segment = message_dict.get('message_segment', {}) + + if message_segment.get('data','') == '[json]': + # 提取json消息中的展示信息 + pattern = r'\[CQ:json,data=(?P.+?)\]' + match = re.search(pattern, message_dict.get('raw_message','')) + raw_json = html.unescape(match.group('json_data')) + json_message = json.loads(raw_json) + message_segment['data'] = json_message.get('prompt','') + self.message_segment = Seg.from_dict(message_dict.get('message_segment', {})) self.raw_message = message_dict.get('raw_message') From 8c346377cbb221fab0550a325c3137dae2c37605 Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Tue, 11 Mar 2025 22:58:07 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=81=A5=E5=A3=AE?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/message.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/chat/message.py b/src/plugins/chat/message.py index 20b9869f6..0505c05a6 100644 --- a/src/plugins/chat/message.py +++ b/src/plugins/chat/message.py @@ -80,7 +80,10 @@ class MessageRecv(Message): pattern = r'\[CQ:json,data=(?P.+?)\]' match = re.search(pattern, message_dict.get('raw_message','')) raw_json = html.unescape(match.group('json_data')) - json_message = json.loads(raw_json) + try: + json_message = json.loads(raw_json) + except json.JSONDecodeError: + json_message = {} message_segment['data'] = json_message.get('prompt','') self.message_segment = Seg.from_dict(message_dict.get('message_segment', {})) From 26782c9181917fb7fb06f30588fc44ff2cd4fb79 Mon Sep 17 00:00:00 2001 From: Rikki Date: Tue, 11 Mar 2025 22:58:40 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20ENVIRONMENT=20?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=9C=A8=E5=90=8C=E4=B8=80=E7=BB=88=E7=AB=AF?= =?UTF-8?q?=E4=B8=8B=E4=B8=8D=E8=83=BD=E8=A2=AB=E8=A6=86=E7=9B=96=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 68068a9f9..f6db08dca 100644 --- a/bot.py +++ b/bot.py @@ -63,7 +63,8 @@ def init_env(): # 首先加载基础环境变量.env if os.path.exists(".env"): - load_dotenv(".env") + load_dotenv(".env",override=True) + print(os.getenv("ENVIRONMENT")) logger.success("成功加载基础环境变量配置") From e54038f3d086c254213e9f85dd2a09edc7edf737 Mon Sep 17 00:00:00 2001 From: Rikki Date: Tue, 11 Mar 2025 22:59:56 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=E4=BB=8E=20nixpkgs=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20numpy=20=E4=BE=9D=E8=B5=96=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=87=BA=E7=8E=B0=20libc++.so=20=E6=89=BE?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 7022dd68e..404f7555c 100644 --- a/flake.nix +++ b/flake.nix @@ -21,13 +21,14 @@ buildInputs = [ pythonPackages.python pythonPackages.venvShellHook + pythonPackages.numpy ]; postVenvCreation = '' unset SOURCE_DATE_EPOCH pip install -r requirements.txt ''; - + postShellHook = '' # allow pip to install wheels unset SOURCE_DATE_EPOCH From c681a827f1127cfdd2f4c5773041b7d73e926f00 Mon Sep 17 00:00:00 2001 From: UnCLAS-Prommer Date: Tue, 11 Mar 2025 23:21:57 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E5=90=8D?= =?UTF-8?q?=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index 55fb9eb43..7c658fbf7 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -39,9 +39,13 @@ def db_message_to_str(message_dict: Dict) -> str: 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 From 80ed56835cb1ca7b310f3c81bcc276dd9cca1a65 Mon Sep 17 00:00:00 2001 From: Rikki Date: Tue, 11 Mar 2025 23:39:25 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4print=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot.py b/bot.py index f6db08dca..36d621a6e 100644 --- a/bot.py +++ b/bot.py @@ -64,7 +64,6 @@ def init_env(): # 首先加载基础环境变量.env if os.path.exists(".env"): load_dotenv(".env",override=True) - print(os.getenv("ENVIRONMENT")) logger.success("成功加载基础环境变量配置")