From 17b7452ecc28d6ea7d4cd23406d1c14e6208f778 Mon Sep 17 00:00:00 2001 From: LyMysterious Date: Sat, 25 Jul 2026 19:55:25 +0800 Subject: [PATCH] =?UTF-8?q?Reapply=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 82aae20a9bc487392f857be344a65aaca799a286. --- .../Controllers/EntryController.cs | 2 +- .../Group/TextProcess/GoodsUpShopProcess.cs | 46 ++++++++++++------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs b/NapCatRobotClient/NapCatRobotClient.API/Controllers/EntryController.cs index 7590666..26a3540 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 01e0f10..144860e 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,28 +67,40 @@ namespace NapCatRobotClient.Service.Group.TextProcess private static async Task Herbal(string groupId, string text, bool upCmd) { List results = []; - var lines = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + + var lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var line in lines) { - if (line.StartsWith("品级:")) + var content = line.Trim(); + + // 跳过无用行 + if (content.StartsWith("鬼谷子的药材背包") || + content.StartsWith("☆拥有药材☆") || + content.StartsWith("第") || + content.StartsWith("下一页")) { - _ = line.Substring("品级:".Length).Trim(); + continue; } - else if (line.StartsWith("名字:")) + + // 品级标题,例如:☆五品药材☆ + if (Regex.IsMatch(content, @"^☆.+品药材☆$")) { - var name = line.Substring("名字:".Length).Trim(); - // 找到下一行的数量 - var index = Array.IndexOf(lines, line); - if (index + 1 < lines.Length && lines[index + 1].StartsWith("拥有数量:")) + // 如果以后需要品级,可以在这里记录 + // currentLevel = ... + continue; + } + + // 药材行,例如:天灵果 - 数量:4 炼金 | 坊市数据 + var match = Regex.Match(content, @"^(.*?)\s*-\s*数量:(\d+)"); + + if (match.Success) + { + results.Add(new GoodsInfo { - 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) }); - } - } + Name = match.Groups[1].Value.Trim(), + Num = int.Parse(match.Groups[2].Value) + }); } }