feat: 添加自动任务群监听触发验证码
This commit is contained in:
@@ -4,7 +4,15 @@ namespace NapCatRobotClient.Service.Group.Service
|
||||
{
|
||||
public class GroupService : IGroupService, IScoped
|
||||
{
|
||||
private static List<string> GroupQQ = App.GetConfig<List<string>>("QQConfig:XiuXianGroupId");
|
||||
/// <summary>
|
||||
/// 修仙大群
|
||||
/// </summary>
|
||||
private static List<string> XiuXianGroup = App.GetConfig<List<string>>("QQConfig:XiuXianGroupId");
|
||||
|
||||
/// <summary>
|
||||
/// 自动做任务群
|
||||
/// </summary>
|
||||
private static List<string> AutoTaskGroup = App.GetConfig<List<string>>("QQConfig:AutoTaskGroupId");
|
||||
|
||||
/// <summary>
|
||||
/// 处理群消息
|
||||
@@ -16,7 +24,7 @@ namespace NapCatRobotClient.Service.Group.Service
|
||||
JObject json = JObject.Parse(message);
|
||||
string groupId = json["group_id"]?.ToString() ?? string.Empty;
|
||||
string groupMsg = json["message"]?.ToString() ?? string.Empty;
|
||||
if (GroupQQ.Contains(groupId) && string.IsNullOrWhiteSpace(groupMsg) is false)
|
||||
if (XiuXianGroup.Contains(groupId) && string.IsNullOrWhiteSpace(groupMsg) is false)
|
||||
{
|
||||
_ = WantedPriceProcess.ProcessGroupRequest(groupId, message);
|
||||
|
||||
@@ -32,6 +40,10 @@ namespace NapCatRobotClient.Service.Group.Service
|
||||
|
||||
_ = ImmortalElixirProcess.ProcessGroupRequest(groupId, message);
|
||||
}
|
||||
if (AutoTaskGroup.Contains(groupId) && string.IsNullOrWhiteSpace(groupMsg) is false)
|
||||
{
|
||||
_= VerifyMsgProcess.ProcessGroupRequest(groupId, message);
|
||||
}
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> ProcessGroupRequest(string message);
|
||||
public Task<bool>ProcessGroupRequest(string message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,12 @@ namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
string xx = json["user_id"]?.ToString();
|
||||
if (xx != App.Configuration["QQConfig:XiaoXiaoRobotQQ"])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string groupMsg = JArray.Parse(json["message"].ToString()).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;
|
||||
|
||||
+15
-4
@@ -14,11 +14,22 @@ namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
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());
|
||||
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();
|
||||
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 自动做任务群触发验证消息给指定的QQ提示
|
||||
/// </summary>
|
||||
public class VerifyMsgProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 处理群消息
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
string groupName = json["group_name"]?.ToString();
|
||||
List<string> text = ["请先验证", "请验证", "深色文字"];
|
||||
if (text.Any(message.Contains))
|
||||
{
|
||||
PrivateSendMessageRequest request = new()
|
||||
{
|
||||
UserId = App.Configuration["QQConfig:SendMsgQQ"],
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = $"{DateTime.Now}\r\n触发小小验证消息\r\n群昵称:{groupName}\r\n群号:{groupId}"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendPrivateText(request);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 自动修炼群触发验证消息 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user