From 3522cc965f5fe952cd5e5ebccc93a79b078b6e52 Mon Sep 17 00:00:00 2001 From: LyMysterious Date: Fri, 30 May 2025 11:16:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=91=BD=E4=BB=A4=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XiaoXiaoRoBot/Cmd/InertOrUpdateGoodsCmd.cs | 23 +++-- XiaoXiaoRoBot/Cmd/QueryGoodsInfoPriceCmd.cs | 62 ++++++++------ XiaoXiaoRoBot/Cmd/QueryGoodsUpShopPriceCmd.cs | 48 ++++++----- XiaoXiaoRoBot/Cmd/WantedPriceCmd.cs | 83 ++++++++++--------- 4 files changed, 124 insertions(+), 92 deletions(-) diff --git a/XiaoXiaoRoBot/Cmd/InertOrUpdateGoodsCmd.cs b/XiaoXiaoRoBot/Cmd/InertOrUpdateGoodsCmd.cs index afd34ca..daadd19 100644 --- a/XiaoXiaoRoBot/Cmd/InertOrUpdateGoodsCmd.cs +++ b/XiaoXiaoRoBot/Cmd/InertOrUpdateGoodsCmd.cs @@ -1,5 +1,6 @@ using Lagrange.Core.Message; using Lagrange.Core.Message.Entity; +using RoBot.Start.LogConfig; using RoBot.Start.Service.Impl; namespace RoBot.Start.Cmd @@ -11,21 +12,29 @@ namespace RoBot.Start.Cmd { public static async Task Execute(MessageChain chain) { - foreach (var item in chain) + try { - if (item is TextEntity) + foreach (var item in chain) { - TextEntity txe = item as TextEntity; - - if (string.IsNullOrWhiteSpace(txe.Text) is false) + if (item is TextEntity) { - if (txe.Text.Contains("不鼓励不保障")) + TextEntity txe = item as TextEntity; + + if (string.IsNullOrWhiteSpace(txe.Text) is false) { - GoodsService.AnalysisGoodsText(txe.Text); + if (txe.Text.Contains("不鼓励不保障")) + { + GoodsService.AnalysisGoodsText(txe.Text); + } } } } } + catch (Exception ex) + { + Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 保存或更新物品价格 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}"); + + } return await Task.FromResult(true); } } diff --git a/XiaoXiaoRoBot/Cmd/QueryGoodsInfoPriceCmd.cs b/XiaoXiaoRoBot/Cmd/QueryGoodsInfoPriceCmd.cs index fcb88ed..b9d7624 100644 --- a/XiaoXiaoRoBot/Cmd/QueryGoodsInfoPriceCmd.cs +++ b/XiaoXiaoRoBot/Cmd/QueryGoodsInfoPriceCmd.cs @@ -3,6 +3,7 @@ using Lagrange.Core.Message.Entity; using RoBot.Core.ConstValue; using RoBot.Core.Helper; using RoBot.Start.Global; +using RoBot.Start.LogConfig; using RoBot.Start.Message; using RoBot.Start.Service.Dto; @@ -15,48 +16,55 @@ namespace RoBot.Start.Cmd { public static async Task Execute(MessageChain chain) { - var systemConfig = GlobalConfig.ConfigSetting; - var bot = GlobalConfig.BotContext; - - if (chain.Count == 2 && - chain.FirstOrDefault(e => e is MentionEntity) is MentionEntity mention && - chain.FirstOrDefault(e => e is TextEntity) is TextEntity text) + try { - // 判断是否@了机器人 - if (mention.Uin == systemConfig.BotQQ) - { - string inputText = text.Text?.Trim(); + var systemConfig = GlobalConfig.ConfigSetting; + var bot = GlobalConfig.BotContext; - // 判断是否包含“查价格” - if (!string.IsNullOrEmpty(inputText) && inputText.Contains("查价格")) + if (chain.Count == 2 && + chain.FirstOrDefault(e => e is MentionEntity) is MentionEntity mention && + chain.FirstOrDefault(e => e is TextEntity) is TextEntity text) + { + // 判断是否@了机器人 + if (mention.Uin == systemConfig.BotQQ) { - // 提取物品名称 - var goodsName = inputText - .Split(' ', StringSplitOptions.RemoveEmptyEntries) - .FirstOrDefault(word => word != "查价格") - ?.Replace("查价格", "")?.Trim(); + string inputText = text.Text?.Trim(); - if (!string.IsNullOrWhiteSpace(goodsName)) + // 判断是否包含“查价格” + if (!string.IsNullOrEmpty(inputText) && inputText.Contains("查价格")) { - var goodsInfo = RedisHelper.Client.HGet(RedisPrefix.GoodsKey, goodsName); + // 提取物品名称 + var goodsName = inputText + .Split(' ', StringSplitOptions.RemoveEmptyEntries) + .FirstOrDefault(word => word != "查价格") + ?.Replace("查价格", "")?.Trim(); - if (goodsInfo is not null) + if (!string.IsNullOrWhiteSpace(goodsName)) { - await bot.SendMsg((uint)systemConfig.GroupQQ, - $"物品:{goodsInfo.Name}\n价格:{goodsInfo.ShowPriceDesc}\n收录时间:{goodsInfo.LastUpdateTime:yyyy-MM-dd HH:mm:ss}"); + var goodsInfo = RedisHelper.Client.HGet(RedisPrefix.GoodsKey, goodsName); + + if (goodsInfo is not null) + { + await bot.SendMsg((uint)systemConfig.GroupQQ, + $"物品:{goodsInfo.Name}\n价格:{goodsInfo.ShowPriceDesc}\n收录时间:{goodsInfo.LastUpdateTime:yyyy-MM-dd HH:mm:ss}"); + } + else + { + await bot.SendMsg((uint)systemConfig.GroupQQ, "未收录"); + } } else { - await bot.SendMsg((uint)systemConfig.GroupQQ, "未收录"); + await bot.SendMsg((uint)systemConfig.GroupQQ, "请输入要查询的物品名称,例如:查价格 七星草"); } } - else - { - await bot.SendMsg((uint)systemConfig.GroupQQ, "请输入要查询的物品名称,例如:查价格 七星草"); - } } } } + catch (Exception ex) + { + Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 查看物品信息命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}"); + } return await Task.FromResult(true); } } diff --git a/XiaoXiaoRoBot/Cmd/QueryGoodsUpShopPriceCmd.cs b/XiaoXiaoRoBot/Cmd/QueryGoodsUpShopPriceCmd.cs index 536ae6a..c9f1844 100644 --- a/XiaoXiaoRoBot/Cmd/QueryGoodsUpShopPriceCmd.cs +++ b/XiaoXiaoRoBot/Cmd/QueryGoodsUpShopPriceCmd.cs @@ -5,6 +5,7 @@ using RoBot.Core; using RoBot.Core.ConstValue; using RoBot.Core.Helper; using RoBot.Start.Global; +using RoBot.Start.LogConfig; using RoBot.Start.Message; using RoBot.Start.Service.Dto; @@ -18,36 +19,43 @@ namespace RoBot.Start.Cmd public static async Task Execute(MessageChain chain) { - var systemConfig = GlobalConfig.ConfigSetting; - if (chain.Count == 3 && - chain.FirstOrDefault(e => e is ForwardEntity) is ForwardEntity forward && - chain.FirstOrDefault(e => e is MentionEntity) is MentionEntity mention && - chain.FirstOrDefault(e => e is TextEntity) is TextEntity text) + try { - if (forward.TargetUin == (uint)systemConfig.XiaoXiaoQQ && mention.Uin == (uint)systemConfig.BotQQ && (text.Text.Contains("查上架") || text.Text.Contains("查价格"))) + var systemConfig = GlobalConfig.ConfigSetting; + if (chain.Count == 3 && + chain.FirstOrDefault(e => e is ForwardEntity) is ForwardEntity forward && + chain.FirstOrDefault(e => e is MentionEntity) is MentionEntity mention && + chain.FirstOrDefault(e => e is TextEntity) is TextEntity text) { - - var list = forward.Chain.Where(o => o is TextEntity); - if (!list.Any()) return false; - - List convertList = list.Cast().ToList(); - convertList = convertList.Where(o => string.IsNullOrWhiteSpace(o.Text) is false) - .ToList(); - if (convertList.Count > 0) + if (forward.TargetUin == (uint)systemConfig.XiaoXiaoQQ && mention.Uin == (uint)systemConfig.BotQQ && (text.Text.Contains("查上架") || text.Text.Contains("查价格"))) { - string desc = convertList[0].Text; - if (desc.Contains("拥有药材") || - desc.Contains("的丹药背包") || - (desc.Contains("名字") && desc.Contains("拥有数量")) - ) + var list = forward.Chain.Where(o => o is TextEntity); + if (!list.Any()) return false; + + List convertList = list.Cast().ToList(); + convertList = convertList.Where(o => string.IsNullOrWhiteSpace(o.Text) is false) + .ToList(); + if (convertList.Count > 0) { - _ = Herbal(desc); + string desc = convertList[0].Text; + + if (desc.Contains("拥有药材") || + desc.Contains("的丹药背包") || + (desc.Contains("名字") && desc.Contains("拥有数量")) + ) + { + _ = Herbal(desc); + } } } } } + catch (Exception ex) + { + Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 坊市上架命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}"); + } return await Task.FromResult(true); } diff --git a/XiaoXiaoRoBot/Cmd/WantedPriceCmd.cs b/XiaoXiaoRoBot/Cmd/WantedPriceCmd.cs index 0b2ad1f..ff80688 100644 --- a/XiaoXiaoRoBot/Cmd/WantedPriceCmd.cs +++ b/XiaoXiaoRoBot/Cmd/WantedPriceCmd.cs @@ -6,6 +6,7 @@ using RoBot.Core.ConstValue; using RoBot.Core.Helper; using RoBot.Start.Dto.Wanted; using RoBot.Start.Global; +using RoBot.Start.LogConfig; using RoBot.Start.Message; using RoBot.Start.Service.Dto; @@ -18,55 +19,61 @@ namespace RoBot.Start.Cmd { public static async Task Execute(MessageChain chain) { - var textEntities = chain.Where(o => o is TextEntity).ToList(); - List convertList = textEntities.Cast().ToList().Where(o => o.Text.Contains("道友的个人悬赏令") || o.Text.Contains("天机悬赏令")).ToList(); - foreach (var item in convertList) + try { - List wantedTasks = new(); - if (item.Text.Contains("个人悬赏令")) - { - wantedTasks = await SingleWanted(item.Text); - } - else if (item.Text.Contains("天机悬赏令")) - { - wantedTasks = await SpecialWanted(item.Text); - } - if (wantedTasks.Count > 0) - { - var systemConfig = GlobalConfig.ConfigSetting; - var bot = GlobalConfig.BotContext; + var textEntities = chain.Where(o => o is TextEntity).ToList(); + List convertList = textEntities.Cast().ToList().Where(o => o.Text.Contains("道友的个人悬赏令") || o.Text.Contains("天机悬赏令")).ToList(); - string msg = ""; - List<(int Id, decimal Price)> prices = new(); - foreach (var want in wantedTasks) + foreach (var item in convertList) + { + List wantedTasks = new(); + if (item.Text.Contains("个人悬赏令")) + { + wantedTasks = await SingleWanted(item.Text); + } + else if (item.Text.Contains("天机悬赏令")) + { + wantedTasks = await SpecialWanted(item.Text); + } + if (wantedTasks.Count > 0) { - msg += $"✨悬赏令 {want.Id} 奖励:{want.ExtraReward.Item}\r\n"; - msg += $"🎁修为:{Utils.FormatNumberToChineseUnit(want.BaseReward)}\r\n"; - var goodsInfo = RedisHelper.Client.HGet(RedisPrefix.GoodsKey, want.ExtraReward.Item); - if (goodsInfo is not null) + var systemConfig = GlobalConfig.ConfigSetting; + var bot = GlobalConfig.BotContext; + + string msg = ""; + List<(int Id, decimal Price)> prices = new(); + foreach (var want in wantedTasks) { - msg += $"💵坊市价格:{goodsInfo.ShowPriceDesc}\r\n"; + msg += $"✨悬赏令 {want.Id} 奖励:{want.ExtraReward.Item}\r\n"; + msg += $"🎁修为:{Utils.FormatNumberToChineseUnit(want.BaseReward)}\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)); + prices.Add((want.Id, goodsInfo.Price)); + } + //msg += $"炼金价格:\r\n"; + msg += $"\r\n"; } - //msg += $"炼金价格:\r\n"; - msg += $"\r\n"; - } - var maxWanted = wantedTasks.MaxBy(o => o.BaseReward); + 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)})"; + 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)})"; + } + await bot.SendMsg((uint)systemConfig.GroupQQ, msg); } - await bot.SendMsg((uint)systemConfig.GroupQQ, msg); } } - - + catch (Exception ex) + { + Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 悬赏令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}"); + } return await Task.FromResult(true); }