feat:第一次提交
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
using Furion.Logging;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存或更新物品价格
|
||||
/// </summary>
|
||||
public class InertOrUpdateGoodsInfoProcess
|
||||
{
|
||||
private static Regex Regex = new Regex(@"价格[::](\d+(?:\.\d+)?[万亿])\s+([^\s]+)");
|
||||
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (message.Contains("不鼓励不保障"))
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
message = json["message"]?.ToString();
|
||||
message = JArray.Parse(message).FirstOrDefault(o => o["type"].ToString() == "text" && !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()))["data"]["text"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(message)) return false;
|
||||
|
||||
List<GoodsInfo> results = new();
|
||||
|
||||
MatchCollection matches = Regex.Matches(message);
|
||||
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
string price = match.Groups[1].Value;
|
||||
string name = match.Groups[2].Value.Replace("\u200b", "").Replace("\u200c", "").Replace("\u200d", ""); // 去除零宽字符
|
||||
GoodsInfo gds = new()
|
||||
{
|
||||
Name = name,
|
||||
Price = Utils.ParseChineseNumber(price),
|
||||
ShowPriceDesc = price,
|
||||
LastUpdateTime = DateTime.Now
|
||||
};
|
||||
results.Add(gds);
|
||||
}
|
||||
|
||||
foreach (GoodsInfo item in results)
|
||||
{
|
||||
RedisHelper.Client.HSet(RedisPrefix.GoodsKey, item.Name, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 保存或更新物品价格 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
public class LingTianProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 处理群消息
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
string groupMsg = JArray.Parse(json["message"].ToString()).FirstOrDefault(o => o["type"].ToString() == "text"
|
||||
&& !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()) && (o["data"]["text"].ToString().Contains("道友本次采集成果") || o["data"]["text"].ToString().Contains("道友成功收获药材")))?["data"]?["text"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(groupMsg)) return false;
|
||||
|
||||
List<GoodsInfo> goods = new();
|
||||
if (groupMsg.Contains("道友本次采集成果"))
|
||||
{
|
||||
goods = await NewCmd(groupMsg);
|
||||
}
|
||||
else if (groupMsg.Contains("道友成功收获药材"))
|
||||
{
|
||||
goods = await OldCmd(groupMsg);
|
||||
}
|
||||
if (goods.Count > 0)
|
||||
{
|
||||
string msg = "";
|
||||
decimal totalPrice = 0;
|
||||
decimal fee = 0;
|
||||
// 打印结果
|
||||
foreach (var good in goods)
|
||||
{
|
||||
var current = RedisHelper.Client.HGet<GoodsInfo>(RedisPrefix.GoodsKey, good.Name);
|
||||
if (current is not null)
|
||||
{
|
||||
int num = good.Num.Value > 10 ? 10 : good.Num.Value;
|
||||
decimal nicePrice = current.Price - 100000;
|
||||
totalPrice += Convert.ToDecimal(nicePrice * num);
|
||||
|
||||
fee += Math.Round(Utils.CalculateFee(nicePrice) * num, 0);
|
||||
}
|
||||
}
|
||||
if (totalPrice > 0)
|
||||
{
|
||||
msg = $"恭喜道友成功收取{goods.Sum(o => o.Num)}株药材\r\n";
|
||||
msg += $"总价值约:{Utils.FormatNumberToChineseUnit(totalPrice)}\r\n";
|
||||
msg += $"手续费约:{Utils.FormatNumberToChineseUnit(fee)}\r\n";
|
||||
msg += $"到账约:{Utils.FormatNumberToChineseUnit(totalPrice - fee)}";
|
||||
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = msg
|
||||
}
|
||||
},
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "reply",
|
||||
Data = new()
|
||||
{
|
||||
Id = json["message_id"].ToString()
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
}
|
||||
|
||||
var atData = JArray.Parse(message).FirstOrDefault(o => o["type"].ToString() == "at");
|
||||
if (atData is not null)
|
||||
{
|
||||
ScheduleNextNotify(groupId, atData["data"]["qq"].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 灵田结算查价格 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static async Task<List<GoodsInfo>> OldCmd(string message)
|
||||
{
|
||||
List<GoodsInfo> goodsInfos = new();
|
||||
var result = new List<(string Name, int Count)>();
|
||||
var regex = new Regex(@"道友成功收获药材:(.+?) (\d+) 个!");
|
||||
|
||||
foreach (Match match in regex.Matches(message))
|
||||
{
|
||||
string name = match.Groups[1].Value;
|
||||
int count = int.Parse(match.Groups[2].Value);
|
||||
goodsInfos.Add(new() { Name = name, Num = count });
|
||||
}
|
||||
return await Task.FromResult(goodsInfos);
|
||||
}
|
||||
|
||||
private static async Task<List<GoodsInfo>> NewCmd(string message)
|
||||
{
|
||||
List<GoodsInfo> goodsInfos = new();
|
||||
var result = new List<(string Name, int Count)>();
|
||||
var regex = new Regex(@"收获药材:(.+?) (\d+) 个!");
|
||||
|
||||
foreach (Match match in regex.Matches(message))
|
||||
{
|
||||
string name = match.Groups[1].Value;
|
||||
int count = int.Parse(match.Groups[2].Value);
|
||||
goodsInfos.Add(new() { Name = name, Num = count });
|
||||
}
|
||||
return await Task.FromResult(goodsInfos);
|
||||
}
|
||||
|
||||
private static void ScheduleNextNotify(string groupId, string userId)
|
||||
{
|
||||
TimeSpan delay = TimeSpan.FromHours(47.01);
|
||||
|
||||
Log.Information($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} {userId} 触发下次灵田结算通知 ");
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(delay);
|
||||
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = $"\r\n【灵田结算通知】\r\n该结算奖励了!"
|
||||
}
|
||||
},
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "at",
|
||||
Data = new()
|
||||
{
|
||||
QQ = userId
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 悬赏令
|
||||
/// </summary>
|
||||
public class WantedPriceProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 处理群消息
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
List<WantedTaskInfo> wantedTasks = new();
|
||||
JObject json = JObject.Parse(message);
|
||||
string groupMsg = JArray.Parse(json["message"].ToString()).FirstOrDefault(o => o["type"].ToString() == "text"
|
||||
&& !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()) && o["data"]["text"].ToString().Contains("悬赏"))?["data"]?["text"]?.ToString();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(groupMsg)) return false;
|
||||
|
||||
if (groupMsg.Contains("个人悬赏令"))
|
||||
{
|
||||
wantedTasks = await SingleWanted(groupMsg);
|
||||
}
|
||||
else if (groupMsg.Contains("天机悬赏令"))
|
||||
{
|
||||
wantedTasks = await SpecialWanted(groupMsg);
|
||||
}
|
||||
if (wantedTasks.Count > 0)
|
||||
{
|
||||
string msg = "";
|
||||
List<(int Id, decimal Price)> prices = new();
|
||||
foreach (var want in wantedTasks)
|
||||
{
|
||||
msg += $"✨悬赏令 {want.Id} 奖励:{want.ExtraReward.Item}\r\n";
|
||||
msg += $"🎁修为:{Utils.FormatNumberToChineseUnit(want.BaseReward)} ({want.SuccessRate})\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));
|
||||
}
|
||||
//msg += $"炼金价格:\r\n";
|
||||
msg += $"\r\n";
|
||||
}
|
||||
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)})";
|
||||
}
|
||||
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = msg
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
}
|
||||
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 个人悬赏令
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
private static async Task<List<WantedTaskInfo>> SingleWanted(string message)
|
||||
{
|
||||
List<WantedTaskInfo> result = new();
|
||||
|
||||
// 解析任务信息
|
||||
var taskRegex = new Regex(
|
||||
@"(?<id>\d+)、(?<name>.*?),
|
||||
完成几率(?<rate>\d+),
|
||||
基础报酬(?<reward>\d+)修为,
|
||||
预计需(?<duration>\d+分钟),
|
||||
可能额外获得:(?<grade>[^::]+):(?<item>[^!!]+)!?",
|
||||
RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
foreach (Match match in taskRegex.Matches(message))
|
||||
{
|
||||
result.Add(new()
|
||||
{
|
||||
Id = int.Parse(match.Groups[1].Value),
|
||||
Name = match.Groups[2].Value.Trim(),
|
||||
SuccessRate = match.Groups[3].Value + "%",
|
||||
BaseReward = long.Parse(match.Groups[4].Value),
|
||||
Duration = match.Groups[5].Value,
|
||||
ExtraReward = new ExtraReward
|
||||
{
|
||||
Grade = match.Groups[6].Value.Trim(),
|
||||
Item = match.Groups[7].Value.Trim()
|
||||
}
|
||||
});
|
||||
}
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 天机悬赏令
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
private static async Task<List<WantedTaskInfo>> SpecialWanted(string message)
|
||||
{
|
||||
List<WantedTaskInfo> result = new();
|
||||
|
||||
var blockRegex = new Regex(
|
||||
@"悬赏(?<idCN>[壹贰叁肆伍陆柒捌玖拾])·(?<name>[^\n\r]+)\s+" +
|
||||
@".*?成功率:(?<rate>\d+)%\s+" +
|
||||
@".*?预计耗时:(?<duration>[\d一二三四五六七八九十]+分钟)\s+" +
|
||||
@".*?基础奖励(?<reward>\d+)修为\s+" +
|
||||
@".*?额外机缘:(?<grade>[^「」]+)「(?<item>[^」]+)」",
|
||||
RegexOptions.Multiline);
|
||||
|
||||
foreach (Match match in blockRegex.Matches(message))
|
||||
{
|
||||
string idCN = match.Groups["idCN"].Value;
|
||||
result.Add(new()
|
||||
{
|
||||
Id = ChineseNumberMap.ContainsKey(idCN) ? ChineseNumberMap[idCN] : 0,
|
||||
Name = match.Groups["name"].Value.Trim(),
|
||||
SuccessRate = match.Groups["rate"].Value + "%",
|
||||
Duration = match.Groups["duration"].Value.Trim(),
|
||||
BaseReward = long.Parse(match.Groups["reward"].Value),
|
||||
ExtraReward = new ExtraReward
|
||||
{
|
||||
Grade = match.Groups["grade"].Value.Trim(),
|
||||
Item = match.Groups["item"].Value.Trim()
|
||||
}
|
||||
});
|
||||
}
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
private static readonly Dictionary<string, int> ChineseNumberMap = new()
|
||||
{
|
||||
{ "壹", 1 }, { "贰", 2 }, { "叁", 3 }, { "肆", 4 }, { "伍", 5 },
|
||||
{ "陆", 6 }, { "柒", 7 }, { "捌", 8 }, { "玖", 9 }, { "拾", 10 }
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user