feat:第一次提交
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user