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.0 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;
using Microsoft.Extensions.Hosting;
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
namespace NapCatRobotClient.Service.BackGround
{
/// <summary>
/// 秘境结算通知
/// </summary>
public class MijingBackGroundWorker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
string[] keys = RedisHelper.Client.Keys($"{RedisPrefix.MiJingKey}*");
foreach (string key in keys)
{
string json = RedisHelper.Client.Get(key);
if (string.IsNullOrEmpty(json)) continue;
TaskDetailInfo task = JsonConvert.DeserializeObject<TaskDetailInfo>(json);
if (task.TriggerTime <= DateTime.Now)
{
GroupSendMessageRequest request = new ()
{
GroupId = task.GroupId,
Message =
[
new MessageItem
{
Type = "text",
Data = new() { Text = $"【秘境结算通知】\r\n探索已完成该结算奖励了{task.Minutes} 分钟)" }
},
new MessageItem
{
Type = "at",
Data = new() { QQ = task.UserId }
}
]
};
_ = RobotAPI.SendGroupText(request);
RedisHelper.Client.Del(key);
}
}
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
}
}