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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user