feat: 添加自动任务群监听触发验证码
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "9.0.10",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
],
|
||||
"rollForward": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Furion.Logging;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NapCatRobotClient.Service.Dispatcher.Service;
|
||||
|
||||
@@ -15,7 +16,7 @@ namespace NapCatRobotClient.API.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ½ÓÊÕÏûÏ¢Èë¿Ú
|
||||
/// 接收消息入口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
@@ -23,6 +24,7 @@ namespace NapCatRobotClient.API.Controllers
|
||||
{
|
||||
using StreamReader reader = new(Request.Body);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
Log.Information($"接收到群消息:{body}");
|
||||
bool result = await _dispatcherService.ReceiveMessageAndProcess(body);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
"AccessToken": "123456", // NapCat HTTP服务端Token
|
||||
"RobotQQ": "3902582794", // 当前登录机器人QQ号
|
||||
"XiaoXiaoRobotQQ": "3889001741", // 小小机器人QQ号
|
||||
"XiuXianGroupId": [ 705807264 ] // 要监听的群号
|
||||
"XiuXianGroupId": [ 705807264 ], // 要监听的群号
|
||||
"AutoTaskGroupId": [ 1035078191 ], // 自动做任务的群,主要检查是否触发了验证码 给指定QQ发消息
|
||||
"SendMsgQQ": "123456789" // 发送私聊消息的QQ
|
||||
},
|
||||
"丹方": {
|
||||
"灭神古丸": "配方主药三尾风叶1药引血菩提1辅药混元果1丹炉寒铁铸心炉\r\n配方主药冰灵焰草1药引诱妖草1辅药混元果1丹炉寒铁铸心炉",
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
namespace NapCatRobotClient.Core.RobotAPI.Dto.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送私聊消息请求
|
||||
/// </summary>
|
||||
public class PrivateSendMessageRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// QQ号码
|
||||
/// </summary>
|
||||
[JsonProperty("user_id")]
|
||||
public string UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
[JsonProperty("message")]
|
||||
public List<MessageItem> Message { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Flurl.Http;
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Core.RobotAPI
|
||||
@@ -6,16 +7,25 @@ namespace NapCatRobotClient.Core.RobotAPI
|
||||
public class RobotAPI
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送群文本消息
|
||||
/// 发送群消息
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<string> SendGroupText(GroupSendMessageRequest request)
|
||||
{
|
||||
return await Post(JsonConvert.SerializeObject(request), "/send_group_msg");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送私聊消息
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<string> SendPrivateText(PrivateSendMessageRequest request)
|
||||
{
|
||||
return await Post(JsonConvert.SerializeObject(request), "/send_private_msg");
|
||||
}
|
||||
|
||||
private static async Task<string> Post(string parameters, string action)
|
||||
{
|
||||
string url = App.Configuration["QQConfig:SendApiUrl"] + action;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
+14
-3
@@ -14,10 +14,21 @@ 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("道友已踏入:"))
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -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