fix: 秘境结算通知修正
This commit is contained in:
+58
-22
@@ -1,6 +1,5 @@
|
||||
using Furion.Logging;
|
||||
using System.Globalization;
|
||||
using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
@@ -14,41 +13,78 @@ namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
string xx = json["user_id"]?.ToString();
|
||||
if (xx != App.Configuration["QQConfig:XiaoXiaoRobotQQ"])
|
||||
{
|
||||
|
||||
string userId = json["user_id"]?.ToString();
|
||||
|
||||
string robotId = App.Configuration["QQConfig:XiaoXiaoRobotQQ"];
|
||||
|
||||
if (userId != robotId)
|
||||
return false;
|
||||
}
|
||||
|
||||
var messageArray = JArray.Parse(json["message"].ToString());
|
||||
if (json["message"] is not JArray messageArray || messageArray.Count == 0)
|
||||
return false;
|
||||
|
||||
List<string> keywords = new() { "进入秘境", "道友已踏入", "道友已破界", "道友已遁入", "道友已降临" };
|
||||
string[] keywords = { "进入秘境", "道友已踏入", "道友已破界", "道友已遁入", "道友已降临" };
|
||||
|
||||
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;
|
||||
JToken textMsg = messageArray
|
||||
.FirstOrDefault(o =>
|
||||
{
|
||||
string type = o["type"]?.ToString();
|
||||
string text = o["data"]?["text"]?.ToString();
|
||||
|
||||
return type == "text"
|
||||
&& !string.IsNullOrWhiteSpace(text)
|
||||
&& keywords.Any(k => text.Contains(k));
|
||||
});
|
||||
|
||||
string groupMsg = textMsg?["data"]?["text"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(groupMsg))
|
||||
return false;
|
||||
|
||||
var minutes = ParseMinutes(groupMsg);
|
||||
if (minutes > 0)
|
||||
if (minutes <= 0)
|
||||
return true;
|
||||
|
||||
JToken atData = messageArray.FirstOrDefault(o => o["type"]?.ToString() == "at");
|
||||
|
||||
string targetQQ = null;
|
||||
|
||||
if (atData != null)
|
||||
{
|
||||
var atData = messageArray.FirstOrDefault(o => o["type"].ToString() == "at");
|
||||
if (atData is not null)
|
||||
targetQQ = atData["data"]?["qq"]?.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
string markdown = messageArray
|
||||
.FirstOrDefault(o => o["type"]?.ToString() == "markdown")
|
||||
?["data"]?["content"]?.ToString();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(markdown))
|
||||
{
|
||||
ScheduleReminder(groupId, atData["data"]["qq"].ToString(), minutes);
|
||||
var match = Regex.Match(markdown, @"at_tinyid=(\d+)");
|
||||
if (match.Success)
|
||||
{
|
||||
targetQQ = match.Groups[1].Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(targetQQ))
|
||||
{
|
||||
ScheduleReminder(groupId, targetQQ, minutes);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 秘境结束通知 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
Log.Error(
|
||||
$"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 秘境结束通知 发生异常:{ex.Message}\n{ex.StackTrace}",
|
||||
true);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static void ScheduleReminder(string groupId, string userId, double minutes)
|
||||
{
|
||||
DateTime now = DateTime.Now.AddMinutes(minutes);
|
||||
|
||||
Reference in New Issue
Block a user