|
|
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);
|
|
|
string xx = json["user_id"]?.ToString();
|
|
|
if (xx != App.Configuration["QQConfig:XiaoXiaoRobotQQ"])
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
var messageArray = JArray.Parse(json["message"].ToString());
|
|
|
|
|
|
List<string> keywords = new() { "进入秘境", "道友已踏入", "道友已破界", "道友已遁入", "道友已降临" };
|
|
|
|
|
|
string groupMsg = messageArray
|
|
|
.FirstOrDefault(o =>
|
|
|
o["type"]?.ToString() == "text"
|
|
|
&& !string.IsNullOrWhiteSpace(o["data"]?["text"]?.ToString())
|
|
|
&& keywords.Any(k => o["data"]["text"].ToString().Contains(k))
|
|
|
)?["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;
|
|
|
}
|
|
|
}
|
|
|
}
|