From 34bf5c4d61b59f8c409c6aa2ad84fec2574e9f2c Mon Sep 17 00:00:00 2001 From: LyMysterious Date: Fri, 19 Jun 2026 23:38:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=8F=E5=B0=8F=20=E8=8D=AF=E6=9D=90?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E6=9F=A5=E8=AF=A2=20=E7=A7=98=E5=A2=83?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/EntryController.cs | 3 ++- .../NapCatRobotClient.API/Dockerfile | 10 +++++++++ .../NapCatRobotClient.API.csproj | 15 ++++++------- .../NapCatRobotClient.API/docker-compose.yml | 21 +++++++++++++++++++ .../NapCatRobotClient.Core.csproj | 2 +- .../Group/TextProcess/GoodsUpShopProcess.cs | 2 +- .../InertOrUpdateGoodsInfoProcess.cs | 16 +++++++++----- .../Group/TextProcess/LingTianProcess.cs | 2 +- .../Group/TextProcess/MiJingNotifyProcess.cs | 11 +++++----- .../NapCatRobotClient.Service.csproj | 2 +- 10 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 NapCatRobotClient/NapCatRobotClient.API/Dockerfile create mode 100644 NapCatRobotClient/NapCatRobotClient.API/docker-compose.yml diff --git a/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs b/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs index 1b67c37..7fa2ee8 100644 --- a/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs +++ b/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs @@ -24,7 +24,8 @@ namespace NapCatRobotClient.API.Controllers { using StreamReader reader = new(Request.Body); string body = await reader.ReadToEndAsync(); - //Log.Information($"接收到群消息:{body}"); + Log.Information($"接收到群消息:{body} \r\n"); + body = "{\"self_id\":3902582794,\"user_id\":3889001741,\"time\":1781882943,\"message_id\":650215683,\"message_seq\":650215683,\"real_id\":650215683,\"real_seq\":\"1698687\",\"message_type\":\"group\",\"sender\":{\"user_id\":3889001741,\"nickname\":\"小小\",\"card\":\"\",\"role\":\"member\"},\"raw_message\":\"[CQ:markdown,content=[](%7B%22version%22%3A2%7D)\\n道友的灵田还不能收取,下次收取时间为:44.77小时之后]道友的灵田还不能收取,下次收取时间为:44.77小时之后\",\"font\":14,\"sub_type\":\"normal\",\"message\":[{\"type\":\"markdown\",\"data\":{\"content\":\"[](%7B%22version%22%3A2%7D)\\n道友的灵田还不能收取,下次收取时间为:44.77小时之后\"}},{\"type\":\"text\",\"data\":{\"text\":\"道友的灵田还不能收取,下次收取时间为:44.77小时之后\"}}],\"message_format\":\"array\",\"post_type\":\"message\",\"group_id\":285855428,\"group_name\":\"??????颂我名者轮回得永生??????\"}"; bool result = await _dispatcherService.ReceiveMessageAndProcess(body); return Ok(result); } diff --git a/NapCatRobotClient/NapCatRobotClient.API/Dockerfile b/NapCatRobotClient/NapCatRobotClient.API/Dockerfile new file mode 100644 index 0000000..04d8b84 --- /dev/null +++ b/NapCatRobotClient/NapCatRobotClient.API/Dockerfile @@ -0,0 +1,10 @@ + +FROM mcr.microsoft.com/dotnet/aspnet:10.0 + +# 设置环境变量 +ENV TZ=Asia/Shanghai +WORKDIR /app + +COPY . . + +ENTRYPOINT ["dotnet", "NapCatRobotClient.API.dll"] diff --git a/NapCatRobotClient/NapCatRobotClient.API/NapCatRobotClient.API.csproj b/NapCatRobotClient/NapCatRobotClient.API/NapCatRobotClient.API.csproj index 7a8ab45..a7030cb 100644 --- a/NapCatRobotClient/NapCatRobotClient.API/NapCatRobotClient.API.csproj +++ b/NapCatRobotClient/NapCatRobotClient.API/NapCatRobotClient.API.csproj @@ -1,12 +1,13 @@ - - net8.0 - enable - + + net10.0 + enable + zh-CN + - - - + + + diff --git a/NapCatRobotClient/NapCatRobotClient.API/docker-compose.yml b/NapCatRobotClient/NapCatRobotClient.API/docker-compose.yml new file mode 100644 index 0000000..bca0f54 --- /dev/null +++ b/NapCatRobotClient/NapCatRobotClient.API/docker-compose.yml @@ -0,0 +1,21 @@ +services: + xx_napcat_bot_image: + build: + context: . + dockerfile: Dockerfile + container_name: xx_napcat_bot + environment: + - REDIS_HOST=redis + - REDIS_PORT=6379 + volumes: + - /etc/localtime:/etc/localtime:ro + - /etc/timezone:/etc/timezone:ro + ports: + - "5000:5000" + restart: unless-stopped + networks: + - redis-server_default + +networks: + redis-server_default: + external: true diff --git a/NapCatRobotClient/NapCatRobotClient.Core/NapCatRobotClient.Core.csproj b/NapCatRobotClient/NapCatRobotClient.Core/NapCatRobotClient.Core.csproj index d214593..d11c172 100644 --- a/NapCatRobotClient/NapCatRobotClient.Core/NapCatRobotClient.Core.csproj +++ b/NapCatRobotClient/NapCatRobotClient.Core/NapCatRobotClient.Core.csproj @@ -1,7 +1,7 @@  - net8.0 + net10.0 enable diff --git a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/GoodsUpShopProcess.cs b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/GoodsUpShopProcess.cs index f0aaf0c..01e0f10 100644 --- a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/GoodsUpShopProcess.cs +++ b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/GoodsUpShopProcess.cs @@ -14,7 +14,7 @@ namespace NapCatRobotClient.Service.Group.TextProcess { JObject json = JObject.Parse(message); var messageArray = JArray.Parse(json["message"].ToString()); - string groupMsg = messageArray.FirstOrDefault(o => o["type"].ToString() == "text" + string groupMsg = messageArray.LastOrDefault(o => o["type"].ToString() == "text" && !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()))?["data"]?["text"]?.ToString(); if (string.IsNullOrWhiteSpace(groupMsg)) return false; diff --git a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/InertOrUpdateGoodsInfoProcess.cs b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/InertOrUpdateGoodsInfoProcess.cs index 78a707e..21d5daf 100644 --- a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/InertOrUpdateGoodsInfoProcess.cs +++ b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/InertOrUpdateGoodsInfoProcess.cs @@ -1,4 +1,5 @@ using Furion.Logging; +using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource; namespace NapCatRobotClient.Service.Group.TextProcess { @@ -16,18 +17,23 @@ namespace NapCatRobotClient.Service.Group.TextProcess if (message.Contains("不鼓励不保障")) { JObject json = JObject.Parse(message); - message = json["message"]?.ToString(); - message = JArray.Parse(message).FirstOrDefault(o => o["type"].ToString() == "text" && !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()))["data"]["text"]?.ToString(); - if (string.IsNullOrWhiteSpace(message)) return false; + string jsonMessage = json["message"]?.ToString(); + + jsonMessage = JArray.Parse(jsonMessage) + .Where(x => x?["type"]?.ToString() == "text") + .Select(x => x?["data"]?["text"]?.ToString()) + .FirstOrDefault(t => !string.IsNullOrWhiteSpace(t) && new string[] { "不鼓励不保障" }.All(k => t.Contains(k))); + + if (string.IsNullOrWhiteSpace(jsonMessage)) return false; List results = new(); - MatchCollection matches = Regex.Matches(message); + MatchCollection matches = Regex.Matches(jsonMessage); foreach (Match match in matches) { string price = match.Groups[1].Value; - string name = match.Groups[2].Value.Replace("\u200b", "").Replace("\u200c", "").Replace("\u200d", ""); // 去除零宽字符 + string name = match.Groups[2].Value.Replace("\u200b", "").Replace("\u200c", "").Replace("\u200d", "").Replace("?", ""); // 去除零宽字符 GoodsInfo gds = new() { Name = name, diff --git a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/LingTianProcess.cs b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/LingTianProcess.cs index e9bfa8a..d6e1073 100644 --- a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/LingTianProcess.cs +++ b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/LingTianProcess.cs @@ -46,7 +46,7 @@ namespace NapCatRobotClient.Service.Group.TextProcess if (string.IsNullOrWhiteSpace(groupMsg)) return false; List goods = new(); - if (groupMsg.Contains("道友的灵田还不能收取")|| groupMsg.Contains("道友的灵田灵气未满")) + if (groupMsg.Contains("道友的灵田还不能收取") || groupMsg.Contains("道友的灵田灵气未满")) { double ts = ConvertLastTime(groupMsg); if (ts > 0) diff --git a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/MiJingNotifyProcess.cs b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/MiJingNotifyProcess.cs index d376577..22373f5 100644 --- a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/MiJingNotifyProcess.cs +++ b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/MiJingNotifyProcess.cs @@ -1,5 +1,6 @@ using Furion.Logging; using System.Globalization; +using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource; namespace NapCatRobotClient.Service.Group.TextProcess { @@ -24,11 +25,11 @@ namespace NapCatRobotClient.Service.Group.TextProcess List keywords = new() { "进入秘境", "道友已踏入", "道友已破界", "道友已遁入", "道友已降临" }; string groupMsg = messageArray - .FirstOrDefault(o => - o["type"]?.ToString() == "text" - && !string.IsNullOrWhiteSpace(o["data"]?["text"]?.ToString()) - && keywords.Any(k => o["data"]["text"].ToString().Contains(k)) - )?["data"]?["text"]?.ToString(); + .FirstOrDefault(o => + o["type"]?.ToString() == "text" + && !string.IsNullOrWhiteSpace(o["data"]?["text"]?.ToString()) + && keywords.Any(k => o["data"]["text"].ToString().Contains(k)) + )?["data"]?["text"]?.ToString(); if (string.IsNullOrWhiteSpace(groupMsg)) return false; var minutes = ParseMinutes(groupMsg); diff --git a/NapCatRobotClient/NapCatRobotClient.Service/NapCatRobotClient.Service.csproj b/NapCatRobotClient/NapCatRobotClient.Service/NapCatRobotClient.Service.csproj index e7563b6..92f3425 100644 --- a/NapCatRobotClient/NapCatRobotClient.Service/NapCatRobotClient.Service.csproj +++ b/NapCatRobotClient/NapCatRobotClient.Service/NapCatRobotClient.Service.csproj @@ -1,7 +1,7 @@  - net8.0 + net10.0 enable