You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.5 KiB
C#

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
{
/// <summary>
/// 查丹方
/// </summary>
public class ImmortalElixirCmd
{
public static async Task<bool> 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<string, string> dict = AppConfigHelper.GetSection<Dictionary<string, string>>("丹方");
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);
}
}
}