|
|
using Lagrange.Core.Message;
|
|
|
using Lagrange.Core.Message.Entity;
|
|
|
using RoBot.Start.Global;
|
|
|
using RoBot.Start.LogConfig;
|
|
|
using RoBot.Start.Message;
|
|
|
using System.Globalization;
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
namespace RoBot.Start.Cmd
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 秘境结束通知
|
|
|
/// </summary>
|
|
|
public class MiJingNotify
|
|
|
{
|
|
|
public static async Task<bool> Execute(MessageChain chain)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
MarkdownEntity miJingEntity = chain.Where(o => o is MarkdownEntity)
|
|
|
.Cast<MarkdownEntity>()
|
|
|
.Where(o => o.Data.Content.Contains("进入秘境"))
|
|
|
.FirstOrDefault();
|
|
|
if (miJingEntity is not null)
|
|
|
{
|
|
|
MentionEntity callQQMember = chain.Where(o => o is MentionEntity).Cast<MentionEntity>().FirstOrDefault();
|
|
|
if (callQQMember is not null)
|
|
|
{
|
|
|
string miJingContent = miJingEntity.Data.Content;
|
|
|
var minutes = ParseMinutes(miJingContent);
|
|
|
if (minutes > 0)
|
|
|
{
|
|
|
uint qqNumber = callQQMember.Uin;
|
|
|
ScheduleReminder(qqNumber, minutes);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 秘境结束通知 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
|
|
}
|
|
|
return await Task.FromResult(true);
|
|
|
}
|
|
|
|
|
|
private static void ScheduleReminder(uint userId, int minutes)
|
|
|
{
|
|
|
TimeSpan delay = TimeSpan.FromMinutes(minutes);
|
|
|
|
|
|
Logs.Write($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} {userId} 秘境通知 {minutes}分钟");
|
|
|
|
|
|
_ = Task.Run(async () =>
|
|
|
{
|
|
|
await Task.Delay(delay);
|
|
|
Dto.ConfigDto.ConfigSetting systemConfig = GlobalConfig.ConfigSetting;
|
|
|
Lagrange.Core.BotContext bot = GlobalConfig.BotContext;
|
|
|
await bot.SendMentionMsg((uint)systemConfig.GroupQQ, userId, $"秘境结算通知,该结算奖励了!({minutes} 分钟)");
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private static int 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[1].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out double val))
|
|
|
{
|
|
|
return (int)Math.Ceiling(val);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
}
|