From 82aae20a9bc487392f857be344a65aaca799a286 Mon Sep 17 00:00:00 2001 From: LyMysterious Date: Sat, 25 Jul 2026 19:37:53 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20=E6=96=B0=E7=89=88=E8=8D=AF?= =?UTF-8?q?=E6=9D=90=E6=8F=90=E7=A4=BA"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c5b3b9661bc946aa3641b515eaf53024e9dcb087. --- .../Controllers/EntryController.cs | 2 +- .../Group/TextProcess/GoodsUpShopProcess.cs | 46 +++++++------------ 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs b/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs index 26a3540..7590666 100644 --- a/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs +++ b/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs @@ -24,7 +24,7 @@ namespace NapCatRobotClient.API.Controllers { using StreamReader reader = new(Request.Body); string body = await reader.ReadToEndAsync(); - Log.Information($"接收到群消息:{body} \r\n"); + //Log.Information($"接收到群消息:{body} \r\n"); bool result = await _dispatcherService.ReceiveMessageAndProcess(body); return Ok(result); } diff --git a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/GoodsUpShopProcess.cs b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/GoodsUpShopProcess.cs index 144860e..01e0f10 100644 --- a/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/GoodsUpShopProcess.cs +++ b/NapCatRobotClient/NapCatRobotClient.Service/Group/TextProcess/GoodsUpShopProcess.cs @@ -19,7 +19,7 @@ namespace NapCatRobotClient.Service.Group.TextProcess if (string.IsNullOrWhiteSpace(groupMsg)) return false; // 小小药材背包 - List keyWord = new() { "拥有药材", "坊市数据" }; + List keyWord = new() { "拥有数量", "坊市数据" }; if (keyWord.All(k => groupMsg.Contains(k))) { RedisHelper.Client.Set(json["message_id"].ToString(), groupMsg, 60 * 10); @@ -67,40 +67,28 @@ namespace NapCatRobotClient.Service.Group.TextProcess private static async Task Herbal(string groupId, string text, bool upCmd) { List results = []; - - var lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - + var lines = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { - var content = line.Trim(); - - // 跳过无用行 - if (content.StartsWith("鬼谷子的药材背包") || - content.StartsWith("☆拥有药材☆") || - content.StartsWith("第") || - content.StartsWith("下一页")) + if (line.StartsWith("品级:")) { - continue; + _ = line.Substring("品级:".Length).Trim(); } - - // 品级标题,例如:☆五品药材☆ - if (Regex.IsMatch(content, @"^☆.+品药材☆$")) + else if (line.StartsWith("名字:")) { - // 如果以后需要品级,可以在这里记录 - // currentLevel = ... - continue; - } - - // 药材行,例如:天灵果 - 数量:4 炼金 | 坊市数据 - var match = Regex.Match(content, @"^(.*?)\s*-\s*数量:(\d+)"); - - if (match.Success) - { - results.Add(new GoodsInfo + var name = line.Substring("名字:".Length).Trim(); + // 找到下一行的数量 + var index = Array.IndexOf(lines, line); + if (index + 1 < lines.Length && lines[index + 1].StartsWith("拥有数量:")) { - Name = match.Groups[1].Value.Trim(), - Num = int.Parse(match.Groups[2].Value) - }); + var quantityLine = lines[index + 1]; + var match = Regex.Match(quantityLine, @"拥有数量:(\d+)"); + if (match.Success) + { + var quantity = match.Groups[1].Value; + results.Add(new() { Name = name, Num = Convert.ToInt32(quantity) }); + } + } } }