feat: 坊市药材价格命令生成
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using Lagrange.Core.Message;
|
||||
using Lagrange.Core.Message.Entity;
|
||||
using RoBot.Start.Service.Impl;
|
||||
|
||||
namespace RoBot.Start.Cmd
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存或更新物品价格
|
||||
/// </summary>
|
||||
public class InertOrUpdateGoodsCmd
|
||||
{
|
||||
public static async Task<bool> Execute(MessageChain chain)
|
||||
{
|
||||
foreach (var item in chain)
|
||||
{
|
||||
if (item is TextEntity)
|
||||
{
|
||||
TextEntity txe = item as TextEntity;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(txe.Text) is false)
|
||||
{
|
||||
if (txe.Text.Contains("不鼓励不保障"))
|
||||
{
|
||||
GoodsService.AnalysisGoodsText(txe.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Lagrange.Core.Message;
|
||||
using Lagrange.Core.Message.Entity;
|
||||
using RoBot.Core;
|
||||
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 QueryGoodsUpShopPriceCmd
|
||||
{
|
||||
|
||||
public static async Task<bool> 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)
|
||||
{
|
||||
if (forward.TargetUin == (uint)systemConfig.XiaoXiaoQQ && mention.Uin == (uint)systemConfig.BotQQ && (text.Text.Contains("查上架") || text.Text.Contains("查价格")))
|
||||
{
|
||||
|
||||
var list = forward.Chain.Where(o => o is TextEntity);
|
||||
if (!list.Any()) return false;
|
||||
|
||||
List<TextEntity> convertList = list.Cast<TextEntity>().ToList();
|
||||
convertList = convertList.Where(o => string.IsNullOrWhiteSpace(o.Text) is false)
|
||||
.ToList();
|
||||
if (convertList.Count > 0)
|
||||
{
|
||||
string desc = convertList[0].Text;
|
||||
|
||||
if (desc.Contains("药材"))
|
||||
{
|
||||
_ = Herbal(desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算药材
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static async Task<bool> Herbal(string text)
|
||||
{
|
||||
List<GoodsInfo> results = [];
|
||||
|
||||
string currentGrade = "";
|
||||
var lines = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.StartsWith("品级:"))
|
||||
{
|
||||
currentGrade = line.Substring("品级:".Length).Trim();
|
||||
}
|
||||
else if (line.StartsWith("名字:"))
|
||||
{
|
||||
var name = line.Substring("名字:".Length).Trim();
|
||||
// 找到下一行的数量
|
||||
var index = Array.IndexOf(lines, line);
|
||||
if (index + 1 < lines.Length && lines[index + 1].StartsWith("拥有数量:"))
|
||||
{
|
||||
var quantityLine = lines[index + 1];
|
||||
var match = Regex.Match(quantityLine, @"拥有数量:(\d+)");
|
||||
if (match.Success)
|
||||
{
|
||||
var quantity = match.Groups[1].Value;
|
||||
results.Add(new() { Name = name, Num = Convert.ToInt32(quantity) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string msg = "";
|
||||
decimal totalPrice = 0;
|
||||
// 打印结果
|
||||
foreach (var item in results)
|
||||
{
|
||||
var current = RedisHelper.Client.HGet<GoodsInfo>(RedisPrefix.GoodsKey, item.Name);
|
||||
if (current is not null)
|
||||
{
|
||||
decimal nicePrice = current.Price - 100000;
|
||||
totalPrice += Convert.ToDecimal(nicePrice * item.Num);
|
||||
msg += $"确认坊市上架{item.Name} {(int)current.Price - 100000} {item.Num}\n";
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(msg) is false)
|
||||
{
|
||||
msg += "\r\n";
|
||||
msg += "使用前请先@小小查看坊市药材,过完一遍以获取最新价格\r\n当前价格为坊市价格-10w\r\n";
|
||||
msg += $"总价值约:{Utils.FormatNumberToChineseUnit(totalPrice)}";
|
||||
var systemConfig = GlobalConfig.ConfigSetting;
|
||||
var bot = GlobalConfig.BotContext;
|
||||
await bot.SendMsg((uint)systemConfig.GroupQQ, msg);
|
||||
}
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user