using Lagrange.Core.Message; using Lagrange.Core.Message.Entity; using RoBot.Core.Helper; using RoBot.Start.Global; using RoBot.Start.LogConfig; using RoBot.Start.Message; namespace RoBot.Start.Cmd { /// /// 查丹方 /// public class ImmortalElixirCmd { public static async Task Execute(MessageChain chain) { try { 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) { // 判断是否@了机器人 if (mention.Uin == systemConfig.BotQQ) { string inputText = text.Text?.Trim(); // 判断是否包含“查价格” if (!string.IsNullOrEmpty(inputText) && inputText.Contains("查丹方")) { // 提取物品名称 var goodsName = inputText .Split(' ', StringSplitOptions.RemoveEmptyEntries) .FirstOrDefault(word => word != "查丹方") ?.Replace("查丹方", "")?.Trim(); if (!string.IsNullOrWhiteSpace(goodsName)) { Dictionary dict = AppConfigHelper.GetSection>("丹方"); if (dict?.Count > 0) { dict.TryGetValue(goodsName, out string doc); if (string.IsNullOrWhiteSpace(doc) is false) { await bot.SendMsg((uint)systemConfig.GroupQQ, doc); } } } } } } } catch (Exception ex) { Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 查丹方命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true); } return await Task.FromResult(true); } } }