From b362c355aa98dbd1a355cea1e40fa11d0e90f38e Mon Sep 17 00:00:00 2001 From: Rikki Date: Tue, 11 Mar 2025 22:17:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20flake.nix=20?= =?UTF-8?q?=EF=BC=8C=E9=87=87=E7=94=A8=20venv=20=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E7=94=9F=E6=88=90=E7=8E=AF=E5=A2=83=EF=BC=8Cnixos?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B9=9F=E5=8F=AF=E4=BB=A5=E6=9C=AC=E6=9C=BA?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E9=A1=B9=E7=9B=AE=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.lock | 56 +++++++++++++++++------------------ flake.nix | 85 +++++++++++++++++++----------------------------------- 2 files changed, 56 insertions(+), 85 deletions(-) diff --git a/flake.lock b/flake.lock index dd215f1c6..894acd486 100644 --- a/flake.lock +++ b/flake.lock @@ -1,43 +1,21 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1741196730, - "narHash": "sha256-0Sj6ZKjCpQMfWnN0NURqRCQn2ob7YtXTAOTwCuz7fkA=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "48913d8f9127ea6530a2a2f1bd4daa1b8685d8a3", - "type": "github" + "lastModified": 0, + "narHash": "sha256-nJj8f78AYAxl/zqLiFGXn5Im1qjFKU8yBPKoWEeZN5M=", + "path": "/nix/store/f30jn7l0bf7a01qj029fq55i466vmnkh-source", + "type": "path" }, "original": { - "owner": "NixOS", - "ref": "nixos-24.11", - "repo": "nixpkgs", - "type": "github" + "id": "nixpkgs", + "type": "indirect" } }, "root": { "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "utils": "utils" } }, "systems": { @@ -54,6 +32,24 @@ "repo": "default", "type": "github" } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 3586857f0..7022dd68e 100644 --- a/flake.nix +++ b/flake.nix @@ -1,62 +1,37 @@ { description = "MaiMBot Nix Dev Env"; - # 本配置仅方便用于开发,但是因为 nb-cli 上游打包中并未包含 nonebot2,因此目前本配置并不能用于运行和调试 inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; - flake-utils.url = "github:numtide/flake-utils"; + utils.url = "github:numtide/flake-utils"; }; - outputs = - { - self, - nixpkgs, - flake-utils, - }: - flake-utils.lib.eachDefaultSystem ( - system: - let - pkgs = import nixpkgs { - inherit system; - }; + outputs = { + self, + nixpkgs, + utils, + ... + }: + utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs {inherit system;}; + pythonPackages = pkgs.python3Packages; + in { + devShells.default = pkgs.mkShell { + name = "python-venv"; + venvDir = "./.venv"; + buildInputs = [ + pythonPackages.python + pythonPackages.venvShellHook + ]; - pythonEnv = pkgs.python3.withPackages ( - ps: with ps; [ - ruff - pymongo - python-dotenv - pydantic - jieba - openai - aiohttp - requests - urllib3 - numpy - pandas - matplotlib - networkx - python-dateutil - APScheduler - loguru - tomli - customtkinter - colorama - pypinyin - pillow - setuptools - ] - ); - in - { - devShell = pkgs.mkShell { - buildInputs = [ - pythonEnv - pkgs.nb-cli - ]; - - shellHook = '' - ''; - }; - } - ); -} + postVenvCreation = '' + unset SOURCE_DATE_EPOCH + pip install -r requirements.txt + ''; + + postShellHook = '' + # allow pip to install wheels + unset SOURCE_DATE_EPOCH + ''; + }; + }); +} \ No newline at end of file From 2688a96986702d0368f378c230f144360446a9fb Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Tue, 11 Mar 2025 22:47:23 +0800 Subject: [PATCH 2/3] =?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 3/3] =?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', {}))