fix: 秘境结算通知修正
This commit is contained in:
@@ -24,8 +24,7 @@ namespace NapCatRobotClient.API.Controllers
|
||||
{
|
||||
using StreamReader reader = new(Request.Body);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
Log.Information($"接收到群消息:{body} \r\n");
|
||||
body = "{\"self_id\":3902582794,\"user_id\":3889001741,\"time\":1781882943,\"message_id\":650215683,\"message_seq\":650215683,\"real_id\":650215683,\"real_seq\":\"1698687\",\"message_type\":\"group\",\"sender\":{\"user_id\":3889001741,\"nickname\":\"小小\",\"card\":\"\",\"role\":\"member\"},\"raw_message\":\"[CQ:markdown,content=[](%7B%22version%22%3A2%7D)\\n道友的灵田还不能收取,下次收取时间为:44.77小时之后]道友的灵田还不能收取,下次收取时间为:44.77小时之后\",\"font\":14,\"sub_type\":\"normal\",\"message\":[{\"type\":\"markdown\",\"data\":{\"content\":\"[](%7B%22version%22%3A2%7D)\\n道友的灵田还不能收取,下次收取时间为:44.77小时之后\"}},{\"type\":\"text\",\"data\":{\"text\":\"道友的灵田还不能收取,下次收取时间为:44.77小时之后\"}}],\"message_format\":\"array\",\"post_type\":\"message\",\"group_id\":285855428,\"group_name\":\"??????颂我名者轮回得永生??????\"}";
|
||||
//Log.Information($"接收到群消息:{body} \r\n");
|
||||
bool result = await _dispatcherService.ReceiveMessageAndProcess(body);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
+57
-21
@@ -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
|
||||
JToken textMsg = 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;
|
||||
{
|
||||
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
|
||||
{
|
||||
ScheduleReminder(groupId, atData["data"]["qq"].ToString(), minutes);
|
||||
string markdown = messageArray
|
||||
.FirstOrDefault(o => o["type"]?.ToString() == "markdown")
|
||||
?["data"]?["content"]?.ToString();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(markdown))
|
||||
{
|
||||
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