You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}
}