|
|
using Lagrange.Core.Message;
|
|
|
using Lagrange.Core.Message.Entity;
|
|
|
using RoBot.Core.ConstValue;
|
|
|
using RoBot.Core.Helper;
|
|
|
using RoBot.Start.Global;
|
|
|
using RoBot.Start.Message;
|
|
|
using RoBot.Start.Service.Dto;
|
|
|
|
|
|
namespace RoBot.Start.Cmd
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 查看物品信息命令 价格/数据更新时间
|
|
|
/// </summary>
|
|
|
public class QueryGoodsInfoPriceCmd
|
|
|
{
|
|
|
public static async Task<bool> 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)
|
|
|
{
|
|
|
// 判断是否@了机器人
|
|
|
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))
|
|
|
{
|
|
|
var goodsInfo = RedisHelper.Client.HGet<GoodsInfo>(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, "请输入要查询的物品名称,例如:查价格 七星草");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|