feat:坊市上架命令判断修改

main
LyMysterious 11 months ago
parent b050aa3208
commit 66c2b5b70a

@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Message;
using Lagrange.Core.Message.Entity;
using RoBot.Core;
@ -6,7 +7,6 @@ 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;
namespace RoBot.Start.Cmd
@ -14,26 +14,24 @@ namespace RoBot.Start.Cmd
/// <summary>
/// 坊市上架命令
/// </summary>
public class QueryGoodsUpShopPriceCmd
public class GoodsUpShopCmd
{
public static async Task<bool> Execute(MessageChain chain)
{
try
{
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)
List<IMessageEntity> forwardEntities = chain.Where(o => o is ForwardEntity).ToList();
List<IMessageEntity> textEntities = chain.Where(o => o is TextEntity).ToList();
if (chain.Count is 3 or 5 && forwardEntities.Count > 0 && textEntities.Count > 0)
{
if ((text.Text.Contains("查上架") || text.Text.Contains("查价格")))
bool any = textEntities.Cast<TextEntity>().ToList().Where(o => o.Text.Contains("查上架") || o.Text.Contains("查价格")).Any();
if (any)
{
if (textEntities.Count == 0) return false;
var list = forward.Chain.Where(o => o is TextEntity);
if (!list.Any()) return false;
ForwardEntity currentF = (ForwardEntity)forwardEntities[0];
List<TextEntity> convertList = list.Cast<TextEntity>().ToList();
List<TextEntity> convertList = currentF.Chain.Where(o => o is TextEntity).Cast<TextEntity>().ToList();
convertList = convertList.Where(o => string.IsNullOrWhiteSpace(o.Text) is false)
.ToList();
if (convertList.Count > 0)
@ -45,7 +43,7 @@ namespace RoBot.Start.Cmd
(desc.Contains("名字") && desc.Contains("拥有数量"))
)
{
_ = Herbal(desc);
_ = Herbal(chain, desc);
}
}
}
@ -63,17 +61,15 @@ namespace RoBot.Start.Cmd
/// 计算药材
/// </summary>
/// <returns></returns>
private static async Task<bool> Herbal(string text)
private static async Task<bool> Herbal(MessageChain chain, 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();
_ = line.Substring("品级:".Length).Trim();
}
else if (line.StartsWith("名字:"))
{
@ -120,7 +116,9 @@ namespace RoBot.Start.Cmd
msg += $"到账约:{Utils.FormatNumberToChineseUnit(totalPrice - fee)}";
var systemConfig = GlobalConfig.ConfigSetting;
var bot = GlobalConfig.BotContext;
await bot.SendMsg((uint)systemConfig.GroupQQ, msg);
var groupMessageChain = MessageBuilder.Group((uint)systemConfig.GroupQQ).Forward(chain).Text(msg);
await bot.SendMessage(groupMessageChain.Build());
}
return await Task.FromResult(true);

@ -8,7 +8,7 @@ namespace RoBot.Start.Cmd
/// <summary>
/// 保存或更新物品价格
/// </summary>
public class InertOrUpdateGoodsCmd
public class InertOrUpdateGoodsInfoCmd
{
public static async Task<bool> Execute(MessageChain chain)
{

@ -12,7 +12,7 @@ namespace RoBot.Start.Cmd
/// <summary>
/// 查看物品信息命令 价格/数据更新时间
/// </summary>
public class QueryGoodsInfoPriceCmd
public class QueryGoodsPriceCmd
{
public static async Task<bool> Execute(MessageChain chain)
{

@ -90,13 +90,13 @@ async Task<bool> HandleGroupMessage(MessageChain chain)
await WantedPriceCmd.Execute(chain);
// 坊市生成上架命令
await QueryGoodsUpShopPriceCmd.Execute(chain);
await GoodsUpShopCmd.Execute(chain);
// 保存或更新物品价格
await InertOrUpdateGoodsCmd.Execute(chain);
await InertOrUpdateGoodsInfoCmd.Execute(chain);
// 查看物品信息命令 价格/数据更新时间
await QueryGoodsInfoPriceCmd.Execute(chain);
await QueryGoodsPriceCmd.Execute(chain);
// 灵田结算价格
await LingTianCmd.Execute(chain);

Loading…
Cancel
Save