feat: 命令异常拦截
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Lagrange.Core.Message;
|
||||
using Lagrange.Core.Message.Entity;
|
||||
using RoBot.Start.LogConfig;
|
||||
using RoBot.Start.Service.Impl;
|
||||
|
||||
namespace RoBot.Start.Cmd
|
||||
@@ -11,21 +12,29 @@ namespace RoBot.Start.Cmd
|
||||
{
|
||||
public static async Task<bool> Execute(MessageChain chain)
|
||||
{
|
||||
foreach (var item in chain)
|
||||
try
|
||||
{
|
||||
if (item is TextEntity)
|
||||
foreach (var item in chain)
|
||||
{
|
||||
TextEntity txe = item as TextEntity;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(txe.Text) is false)
|
||||
if (item is TextEntity)
|
||||
{
|
||||
if (txe.Text.Contains("不鼓励不保障"))
|
||||
TextEntity txe = item as TextEntity;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(txe.Text) is false)
|
||||
{
|
||||
GoodsService.AnalysisGoodsText(txe.Text);
|
||||
if (txe.Text.Contains("不鼓励不保障"))
|
||||
{
|
||||
GoodsService.AnalysisGoodsText(txe.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 保存或更新物品价格 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using Lagrange.Core.Message.Entity;
|
||||
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;
|
||||
|
||||
@@ -15,48 +16,55 @@ namespace RoBot.Start.Cmd
|
||||
{
|
||||
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)
|
||||
try
|
||||
{
|
||||
// 判断是否@了机器人
|
||||
if (mention.Uin == systemConfig.BotQQ)
|
||||
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)
|
||||
{
|
||||
string inputText = text.Text?.Trim();
|
||||
|
||||
// 判断是否包含“查价格”
|
||||
if (!string.IsNullOrEmpty(inputText) && inputText.Contains("查价格"))
|
||||
// 判断是否@了机器人
|
||||
if (mention.Uin == systemConfig.BotQQ)
|
||||
{
|
||||
// 提取物品名称
|
||||
var goodsName = inputText
|
||||
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
||||
.FirstOrDefault(word => word != "查价格")
|
||||
?.Replace("查价格", "")?.Trim();
|
||||
string inputText = text.Text?.Trim();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(goodsName))
|
||||
// 判断是否包含“查价格”
|
||||
if (!string.IsNullOrEmpty(inputText) && inputText.Contains("查价格"))
|
||||
{
|
||||
var goodsInfo = RedisHelper.Client.HGet<GoodsInfo>(RedisPrefix.GoodsKey, goodsName);
|
||||
// 提取物品名称
|
||||
var goodsName = inputText
|
||||
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
||||
.FirstOrDefault(word => word != "查价格")
|
||||
?.Replace("查价格", "")?.Trim();
|
||||
|
||||
if (goodsInfo is not null)
|
||||
if (!string.IsNullOrWhiteSpace(goodsName))
|
||||
{
|
||||
await bot.SendMsg((uint)systemConfig.GroupQQ,
|
||||
$"物品:{goodsInfo.Name}\n价格:{goodsInfo.ShowPriceDesc}\n收录时间:{goodsInfo.LastUpdateTime:yyyy-MM-dd HH:mm:ss}");
|
||||
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, "未收录");
|
||||
await bot.SendMsg((uint)systemConfig.GroupQQ, "请输入要查询的物品名称,例如:查价格 七星草");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await bot.SendMsg((uint)systemConfig.GroupQQ, "请输入要查询的物品名称,例如:查价格 七星草");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 查看物品信息命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using RoBot.Core;
|
||||
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;
|
||||
|
||||
@@ -18,36 +19,43 @@ namespace RoBot.Start.Cmd
|
||||
|
||||
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)
|
||||
try
|
||||
{
|
||||
if (forward.TargetUin == (uint)systemConfig.XiaoXiaoQQ && mention.Uin == (uint)systemConfig.BotQQ && (text.Text.Contains("查上架") || text.Text.Contains("查价格")))
|
||||
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)
|
||||
{
|
||||
|
||||
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)
|
||||
if (forward.TargetUin == (uint)systemConfig.XiaoXiaoQQ && mention.Uin == (uint)systemConfig.BotQQ && (text.Text.Contains("查上架") || text.Text.Contains("查价格")))
|
||||
{
|
||||
string desc = convertList[0].Text;
|
||||
|
||||
if (desc.Contains("拥有药材") ||
|
||||
desc.Contains("的丹药背包") ||
|
||||
(desc.Contains("名字") && desc.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)
|
||||
{
|
||||
_ = Herbal(desc);
|
||||
string desc = convertList[0].Text;
|
||||
|
||||
if (desc.Contains("拥有药材") ||
|
||||
desc.Contains("的丹药背包") ||
|
||||
(desc.Contains("名字") && desc.Contains("拥有数量"))
|
||||
)
|
||||
{
|
||||
_ = Herbal(desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 坊市上架命令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using RoBot.Core.ConstValue;
|
||||
using RoBot.Core.Helper;
|
||||
using RoBot.Start.Dto.Wanted;
|
||||
using RoBot.Start.Global;
|
||||
using RoBot.Start.LogConfig;
|
||||
using RoBot.Start.Message;
|
||||
using RoBot.Start.Service.Dto;
|
||||
|
||||
@@ -18,55 +19,61 @@ namespace RoBot.Start.Cmd
|
||||
{
|
||||
public static async Task<bool> Execute(MessageChain chain)
|
||||
{
|
||||
var textEntities = chain.Where(o => o is TextEntity).ToList();
|
||||
List<TextEntity> convertList = textEntities.Cast<TextEntity>().ToList().Where(o => o.Text.Contains("道友的个人悬赏令") || o.Text.Contains("天机悬赏令")).ToList();
|
||||
|
||||
foreach (var item in convertList)
|
||||
try
|
||||
{
|
||||
List<WantedTaskInfo> wantedTasks = new();
|
||||
if (item.Text.Contains("个人悬赏令"))
|
||||
{
|
||||
wantedTasks = await SingleWanted(item.Text);
|
||||
}
|
||||
else if (item.Text.Contains("天机悬赏令"))
|
||||
{
|
||||
wantedTasks = await SpecialWanted(item.Text);
|
||||
}
|
||||
if (wantedTasks.Count > 0)
|
||||
{
|
||||
var systemConfig = GlobalConfig.ConfigSetting;
|
||||
var bot = GlobalConfig.BotContext;
|
||||
var textEntities = chain.Where(o => o is TextEntity).ToList();
|
||||
List<TextEntity> convertList = textEntities.Cast<TextEntity>().ToList().Where(o => o.Text.Contains("道友的个人悬赏令") || o.Text.Contains("天机悬赏令")).ToList();
|
||||
|
||||
string msg = "";
|
||||
List<(int Id, decimal Price)> prices = new();
|
||||
foreach (var want in wantedTasks)
|
||||
foreach (var item in convertList)
|
||||
{
|
||||
List<WantedTaskInfo> wantedTasks = new();
|
||||
if (item.Text.Contains("个人悬赏令"))
|
||||
{
|
||||
msg += $"✨悬赏令 {want.Id} 奖励:{want.ExtraReward.Item}\r\n";
|
||||
msg += $"🎁修为:{Utils.FormatNumberToChineseUnit(want.BaseReward)}\r\n";
|
||||
var goodsInfo = RedisHelper.Client.HGet<GoodsInfo>(RedisPrefix.GoodsKey, want.ExtraReward.Item);
|
||||
if (goodsInfo is not null)
|
||||
wantedTasks = await SingleWanted(item.Text);
|
||||
}
|
||||
else if (item.Text.Contains("天机悬赏令"))
|
||||
{
|
||||
wantedTasks = await SpecialWanted(item.Text);
|
||||
}
|
||||
if (wantedTasks.Count > 0)
|
||||
{
|
||||
var systemConfig = GlobalConfig.ConfigSetting;
|
||||
var bot = GlobalConfig.BotContext;
|
||||
|
||||
string msg = "";
|
||||
List<(int Id, decimal Price)> prices = new();
|
||||
foreach (var want in wantedTasks)
|
||||
{
|
||||
msg += $"💵坊市价格:{goodsInfo.ShowPriceDesc}\r\n";
|
||||
msg += $"✨悬赏令 {want.Id} 奖励:{want.ExtraReward.Item}\r\n";
|
||||
msg += $"🎁修为:{Utils.FormatNumberToChineseUnit(want.BaseReward)}\r\n";
|
||||
var goodsInfo = RedisHelper.Client.HGet<GoodsInfo>(RedisPrefix.GoodsKey, want.ExtraReward.Item);
|
||||
if (goodsInfo is not null)
|
||||
{
|
||||
msg += $"💵坊市价格:{goodsInfo.ShowPriceDesc}\r\n";
|
||||
|
||||
prices.Add((want.Id, goodsInfo.Price));
|
||||
prices.Add((want.Id, goodsInfo.Price));
|
||||
}
|
||||
//msg += $"炼金价格:\r\n";
|
||||
msg += $"\r\n";
|
||||
}
|
||||
//msg += $"炼金价格:\r\n";
|
||||
msg += $"\r\n";
|
||||
}
|
||||
var maxWanted = wantedTasks.MaxBy(o => o.BaseReward);
|
||||
var maxWanted = wantedTasks.MaxBy(o => o.BaseReward);
|
||||
|
||||
msg += "━━━━━━━━━━━━━━━\r\n";
|
||||
msg += $"✨最高修为:悬赏令 {maxWanted.Id} ({Utils.FormatNumberToChineseUnit(maxWanted.BaseReward)})\r\n";
|
||||
if (prices.Count > 0)
|
||||
{
|
||||
var maxPrice = prices.MaxBy(o => o.Price);
|
||||
msg += $"💰最高价格:悬赏令 {maxPrice.Id} ({Utils.FormatNumberToChineseUnit(maxPrice.Price)})";
|
||||
msg += "━━━━━━━━━━━━━━━\r\n";
|
||||
msg += $"✨最高修为:悬赏令 {maxWanted.Id} ({Utils.FormatNumberToChineseUnit(maxWanted.BaseReward)})\r\n";
|
||||
if (prices.Count > 0)
|
||||
{
|
||||
var maxPrice = prices.MaxBy(o => o.Price);
|
||||
msg += $"💰最高价格:悬赏令 {maxPrice.Id} ({Utils.FormatNumberToChineseUnit(maxPrice.Price)})";
|
||||
}
|
||||
await bot.SendMsg((uint)systemConfig.GroupQQ, msg);
|
||||
}
|
||||
await bot.SendMsg((uint)systemConfig.GroupQQ, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 悬赏令 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}");
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user