feat: 新增灵田 秘境结算持久化

This commit is contained in:
LyMysterious
2025-11-02 18:01:19 +08:00
parent ea73d594c5
commit 7c6b2580d6
10 changed files with 242 additions and 77 deletions
@@ -25,11 +25,49 @@ namespace NapCatRobotClient.Service.Group.TextProcess
}
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();
&& !string.IsNullOrWhiteSpace(o["data"]["text"].ToString()) && (o["data"]["text"].ToString().Contains("道友的灵田还不能收取") || 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("道友本次采集成果"))
if (groupMsg.Contains("道友的灵田还不能收取"))
{
double ts = ConvertLastTime(groupMsg);
if (ts > 0)
{
ts += 0.01;
var atData = JArray.Parse(json["message"].ToString()).FirstOrDefault(o => o["type"].ToString() == "at");
if (atData is not null)
{
string at = atData["data"]["qq"].ToString();
ScheduleNextNotify(groupId, at, ts);
GroupSendMessageRequest request = new()
{
GroupId = groupId,
Message = new()
{
new MessageItem()
{
Type = "text",
Data = new()
{
Text = $"灵田结算预计在 【{DateTime.Now.AddHours(ts):yyyy-MM-dd HH:mm:ss}】 提醒您收取"
}
},
new MessageItem()
{
Type = "at",
Data = new()
{
QQ = at
}
}
}
};
await RobotAPI.SendGroupText(request);
}
}
}
else if (groupMsg.Contains("道友本次采集成果"))
{
goods = await NewCmd(groupMsg);
}
@@ -91,7 +129,7 @@ namespace NapCatRobotClient.Service.Group.TextProcess
var atData = JArray.Parse(json["message"].ToString()).FirstOrDefault(o => o["type"].ToString() == "at");
if (atData is not null)
{
ScheduleNextNotify(groupId, atData["data"]["qq"].ToString());
ScheduleNextNotify(groupId, atData["data"]["qq"].ToString(), 47.01);
}
}
@@ -104,6 +142,17 @@ namespace NapCatRobotClient.Service.Group.TextProcess
return await Task.FromResult(true);
}
private static double ConvertLastTime(string text)
{
Match match = Regex.Match(text, @"([\d\.]+)\s*小时");
double hours = 0;
if (match.Success)
{
hours = double.Parse(match.Groups[1].Value);
}
return hours;
}
private static async Task<List<GoodsInfo>> OldCmd(string message)
{
List<GoodsInfo> goodsInfos = new();
@@ -134,41 +183,19 @@ namespace NapCatRobotClient.Service.Group.TextProcess
return await Task.FromResult(goodsInfos);
}
private static void ScheduleNextNotify(string groupId, string userId)
private static void ScheduleNextNotify(string groupId, string userId, double hours)
{
TimeSpan delay = TimeSpan.FromHours(47.01);
DateTime now = DateTime.Now.AddHours(hours);
TimeSpan delay = TimeSpan.FromHours(hours + 0.09);
Log.Information($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} {userId} 触发下次灵田结算通知 ");
Log.Information($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} {userId} 触发下次灵田结算通知 结算时间:{now} ");
_ = Task.Run(async () =>
RedisHelper.Client.Set($"{RedisPrefix.LingTianKey}{groupId}:{userId}", new TaskDetailInfo()
{
await Task.Delay(delay);
GroupSendMessageRequest request = new()
{
GroupId = groupId,
Message = new()
{
new MessageItem()
{
Type = "text",
Data = new()
{
Text = $"【灵田结算通知】\r\n该结算奖励了!"
}
},
new MessageItem()
{
Type = "at",
Data = new()
{
QQ = userId
}
}
}
};
await RobotAPI.SendGroupText(request);
});
GroupId = groupId,
UserId = userId,
TriggerTime = now
}, delay);
}
}
}