feat: 新功能
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
using System.Globalization;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 秘境通知
|
||||
/// </summary>
|
||||
public class MiJingNotifyProcess
|
||||
{
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
var messageArray = JArray.Parse(json["message"].ToString());
|
||||
string groupMsg = messageArray.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;
|
||||
|
||||
var minutes = ParseMinutes(groupMsg);
|
||||
if (minutes > 0)
|
||||
{
|
||||
var atData = messageArray.FirstOrDefault(o => o["type"].ToString() == "at");
|
||||
if (atData is not null)
|
||||
{
|
||||
ScheduleReminder(groupId, atData["data"]["qq"].ToString(), minutes);
|
||||
}
|
||||
}
|
||||
}
|
||||
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 void ScheduleReminder(string groupId, string userId, double minutes)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
TimeSpan delay = TimeSpan.FromMinutes(minutes);
|
||||
|
||||
Log.Information($@"{now:yyyy-MM-dd HH:mm:ss} {userId} 触发秘境通知 {minutes}分钟 结束时间: {now.AddMinutes(minutes):yyyy-MM-dd HH:mm:ss}");
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(delay);
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = $"【秘境结算通知】\r\n探索已完成,该结算奖励了!({minutes} 分钟)"
|
||||
}
|
||||
},
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "at",
|
||||
Data = new()
|
||||
{
|
||||
QQ = userId
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(request);
|
||||
});
|
||||
}
|
||||
|
||||
private static double ParseMinutes(string content)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(content)) return 0;
|
||||
|
||||
var match = Regex.Match(content, @"(花费时间|探索耗时)[::]\s*(\d+(?:\.\d+)?)", RegexOptions.Compiled);
|
||||
if (!match.Success)
|
||||
{
|
||||
match = Regex.Match(content, @"(\d+(?:\.\d+)?)", RegexOptions.Compiled);
|
||||
}
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
if (double.TryParse(match.Groups[2].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out double val))
|
||||
{
|
||||
return (double)val;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user