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

main
LyMysterious 11 months ago
parent b050aa3208
commit 66c2b5b70a

@ -1,4 +1,5 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Message; using Lagrange.Core.Message;
using Lagrange.Core.Message.Entity; using Lagrange.Core.Message.Entity;
using RoBot.Core; using RoBot.Core;
@ -6,7 +7,6 @@ using RoBot.Core.ConstValue;
using RoBot.Core.Helper; using RoBot.Core.Helper;
using RoBot.Start.Global; using RoBot.Start.Global;
using RoBot.Start.LogConfig; using RoBot.Start.LogConfig;
using RoBot.Start.Message;
using RoBot.Start.Service.Dto; using RoBot.Start.Service.Dto;
namespace RoBot.Start.Cmd namespace RoBot.Start.Cmd
@ -14,26 +14,24 @@ namespace RoBot.Start.Cmd
/// <summary> /// <summary>
/// 坊市上架命令 /// 坊市上架命令
/// </summary> /// </summary>
public class QueryGoodsUpShopPriceCmd public class GoodsUpShopCmd
{ {
public static async Task<bool> Execute(MessageChain chain) public static async Task<bool> Execute(MessageChain chain)
{ {
try try
{ {
var systemConfig = GlobalConfig.ConfigSetting; List<IMessageEntity> forwardEntities = chain.Where(o => o is ForwardEntity).ToList();
if (chain.Count == 3 && List<IMessageEntity> textEntities = chain.Where(o => o is TextEntity).ToList();
chain.FirstOrDefault(e => e is ForwardEntity) is ForwardEntity forward && if (chain.Count is 3 or 5 && forwardEntities.Count > 0 && textEntities.Count > 0)
chain.FirstOrDefault(e => e is MentionEntity) is MentionEntity mention &&
chain.FirstOrDefault(e => e is TextEntity) is TextEntity text)
{ {
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); ForwardEntity currentF = (ForwardEntity)forwardEntities[0];
if (!list.Any()) return false;
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) convertList = convertList.Where(o => string.IsNullOrWhiteSpace(o.Text) is false)
.ToList(); .ToList();
if (convertList.Count > 0) if (convertList.Count > 0)
@ -45,7 +43,7 @@ namespace RoBot.Start.Cmd
(desc.Contains("名字") && desc.Contains("拥有数量")) (desc.Contains("名字") && desc.Contains("拥有数量"))
) )
{ {
_ = Herbal(desc); _ = Herbal(chain, desc);
} }
} }
} }
@ -63,17 +61,15 @@ namespace RoBot.Start.Cmd
/// 计算药材 /// 计算药材
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private static async Task<bool> Herbal(string text) private static async Task<bool> Herbal(MessageChain chain, string text)
{ {
List<GoodsInfo> results = []; List<GoodsInfo> results = [];
string currentGrade = "";
var lines = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var lines = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines) foreach (var line in lines)
{ {
if (line.StartsWith("品级:")) if (line.StartsWith("品级:"))
{ {
currentGrade = line.Substring("品级:".Length).Trim(); _ = line.Substring("品级:".Length).Trim();
} }
else if (line.StartsWith("名字:")) else if (line.StartsWith("名字:"))
{ {
@ -120,7 +116,9 @@ namespace RoBot.Start.Cmd
msg += $"到账约:{Utils.FormatNumberToChineseUnit(totalPrice - fee)}"; msg += $"到账约:{Utils.FormatNumberToChineseUnit(totalPrice - fee)}";
var systemConfig = GlobalConfig.ConfigSetting; var systemConfig = GlobalConfig.ConfigSetting;
var bot = GlobalConfig.BotContext; 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); return await Task.FromResult(true);

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

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

@ -90,13 +90,13 @@ async Task<bool> HandleGroupMessage(MessageChain chain)
await WantedPriceCmd.Execute(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); await LingTianCmd.Execute(chain);

Loading…
Cancel
Save