using NapCatRobotClient.Core.RobotAPI.Dto.Request; namespace NapCatRobotClient.Service.Group.TextProcess { /// /// 悬赏令 /// public class WantedPriceProcess { /// /// 处理群消息 /// /// /// public static async Task ProcessGroupRequest(string groupId, string message) { List wantedTasks = new(); JObject json = JObject.Parse(message); string groupMsg = JArray.Parse(json["message"].ToString()).FirstOrDefault(o => o["type"].ToString() == "text" && !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()) && o["data"]["text"].ToString().Contains("悬赏"))?["data"]?["text"]?.ToString(); if (string.IsNullOrWhiteSpace(groupMsg)) return false; if (groupMsg.Contains("个人悬赏令")) { wantedTasks = await SingleWanted(groupMsg); } else if (groupMsg.Contains("天机悬赏令")) { wantedTasks = await SpecialWanted(groupMsg); } if (wantedTasks.Count > 0) { string msg = ""; List<(int Id, decimal Price)> prices = new(); foreach (var want in wantedTasks) { msg += $"✨悬赏令 {want.Id} 奖励:{want.ExtraReward.Item}\r\n"; msg += $"🎁修为:{Utils.FormatNumberToChineseUnit(want.BaseReward)} ({want.SuccessRate})\r\n"; var goodsInfo = RedisHelper.Client.HGet(RedisPrefix.GoodsKey, want.ExtraReward.Item); if (goodsInfo is not null) { msg += $"💵坊市价格:{goodsInfo.ShowPriceDesc}\r\n"; prices.Add((want.Id, goodsInfo.Price)); } //msg += $"炼金价格:\r\n"; msg += $"\r\n"; } var maxWanted = wantedTasks.MaxBy(o => o.BaseReward); msg += "━━━━━━━━━━━━━━━\r\n"; msg += $"✨最高修为:悬赏令 {maxWanted.Id} ({Utils.FormatNumberToChineseUnit(maxWanted.BaseReward)})\r\n"; if (prices.Count > 0) { var maxPrice = prices.MaxBy(o => o.Price); msg += $"💰最高价格:悬赏令 {maxPrice.Id} ({Utils.FormatNumberToChineseUnit(maxPrice.Price)})"; } GroupSendMessageRequest request = new() { GroupId = groupId, Message = new() { new MessageItem() { Type = "text", Data = new() { Text = msg } } } }; await RobotAPI.SendGroupText(request); } return await Task.FromResult(true); } /// /// 个人悬赏令 /// /// /// private static async Task> SingleWanted(string message) { List result = new(); // 解析任务信息 var taskRegex = new Regex( @"(?\d+)、(?.*?), 完成几率(?\d+), 基础报酬(?\d+)修为, 预计需(?\d+分钟), 可能额外获得:(?[^::]+):(?[^!!]+)!?", RegexOptions.IgnorePatternWhitespace); foreach (Match match in taskRegex.Matches(message)) { result.Add(new() { Id = int.Parse(match.Groups[1].Value), Name = match.Groups[2].Value.Trim(), SuccessRate = match.Groups[3].Value + "%", BaseReward = long.Parse(match.Groups[4].Value), Duration = match.Groups[5].Value, ExtraReward = new ExtraReward { Grade = match.Groups[6].Value.Trim(), Item = match.Groups[7].Value.Trim() } }); } return await Task.FromResult(result); } /// /// 天机悬赏令 /// /// /// private static async Task> SpecialWanted(string message) { List result = new(); var blockRegex = new Regex( @"悬赏(?[壹贰叁肆伍陆柒捌玖拾])·(?[^\n\r]+)\s+" + @".*?成功率:(?\d+)%\s+" + @".*?预计耗时:(?[\d一二三四五六七八九十]+分钟)\s+" + @".*?基础奖励(?\d+)修为\s+" + @".*?额外机缘:(?[^「」]+)「(?[^」]+)」", RegexOptions.Multiline); foreach (Match match in blockRegex.Matches(message)) { string idCN = match.Groups["idCN"].Value; result.Add(new() { Id = ChineseNumberMap.ContainsKey(idCN) ? ChineseNumberMap[idCN] : 0, Name = match.Groups["name"].Value.Trim(), SuccessRate = match.Groups["rate"].Value + "%", Duration = match.Groups["duration"].Value.Trim(), BaseReward = long.Parse(match.Groups["reward"].Value), ExtraReward = new ExtraReward { Grade = match.Groups["grade"].Value.Trim(), Item = match.Groups["item"].Value.Trim() } }); } return await Task.FromResult(result); } private static readonly Dictionary ChineseNumberMap = new() { { "壹", 1 }, { "贰", 2 }, { "叁", 3 }, { "肆", 4 }, { "伍", 5 }, { "陆", 6 }, { "柒", 7 }, { "捌", 8 }, { "玖", 9 }, { "拾", 10 } }; } }