feat: 新版药材提示

This commit is contained in:
LyMysterious
2026-07-25 19:36:37 +08:00
parent c9d78bd832
commit c5b3b9661b
2 changed files with 30 additions and 18 deletions
@@ -24,7 +24,7 @@ namespace NapCatRobotClient.API.Controllers
{ {
using StreamReader reader = new(Request.Body); using StreamReader reader = new(Request.Body);
string body = await reader.ReadToEndAsync(); string body = await reader.ReadToEndAsync();
//Log.Information($"接收到群消息:{body} \r\n"); Log.Information($"接收到群消息:{body} \r\n");
bool result = await _dispatcherService.ReceiveMessageAndProcess(body); bool result = await _dispatcherService.ReceiveMessageAndProcess(body);
return Ok(result); return Ok(result);
} }
@@ -19,7 +19,7 @@ namespace NapCatRobotClient.Service.Group.TextProcess
if (string.IsNullOrWhiteSpace(groupMsg)) return false; if (string.IsNullOrWhiteSpace(groupMsg)) return false;
// 小小药材背包 // 小小药材背包
List<string> keyWord = new() { "拥有数量", "坊市数据" }; List<string> keyWord = new() { "拥有药材", "坊市数据" };
if (keyWord.All(k => groupMsg.Contains(k))) if (keyWord.All(k => groupMsg.Contains(k)))
{ {
RedisHelper.Client.Set(json["message_id"].ToString(), groupMsg, 60 * 10); RedisHelper.Client.Set(json["message_id"].ToString(), groupMsg, 60 * 10);
@@ -67,28 +67,40 @@ namespace NapCatRobotClient.Service.Group.TextProcess
private static async Task<bool> Herbal(string groupId, string text, bool upCmd) private static async Task<bool> Herbal(string groupId, string text, bool upCmd)
{ {
List<GoodsInfo> results = []; List<GoodsInfo> results = [];
var lines = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
var lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines) 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(); // 如果以后需要品级,可以在这里记录
// 找到下一行的数量 // currentLevel = ...
var index = Array.IndexOf(lines, line); continue;
if (index + 1 < lines.Length && lines[index + 1].StartsWith("拥有数量:")) }
{
var quantityLine = lines[index + 1]; // 药材行,例如:天灵果 - 数量:4 炼金 | 坊市数据
var match = Regex.Match(quantityLine, @"拥有数量:(\d+)"); var match = Regex.Match(content, @"^(.*?)\s*-\s*数量(\d+)");
if (match.Success) if (match.Success)
{ {
var quantity = match.Groups[1].Value; results.Add(new GoodsInfo
results.Add(new() { Name = name, Num = Convert.ToInt32(quantity) }); {
} Name = match.Groups[1].Value.Trim(),
} Num = int.Parse(match.Groups[2].Value)
});
} }
} }