feat: 新功能
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
using Furion.Logging;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Service.Group.TextProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 查丹方
|
||||
/// </summary>
|
||||
public class ImmortalElixirProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// 处理群消息
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> ProcessGroupRequest(string groupId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject json = JObject.Parse(message);
|
||||
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("查丹方")
|
||||
)?["data"]?["text"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(groupMsg)) return false;
|
||||
|
||||
var rbotQ = messageArray.FirstOrDefault(o => o["type"].ToString() == "at")?["data"]?["qq"]?.ToString();
|
||||
|
||||
// 判断是否@了机器人
|
||||
if (rbotQ == App.Configuration["QQConfig:RobotQQ"])
|
||||
{
|
||||
// 提取物品名称
|
||||
var goodsName = groupMsg
|
||||
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
||||
.FirstOrDefault(word => word != "查丹方")
|
||||
?.Replace("查丹方", "")?.Trim();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(goodsName))
|
||||
{
|
||||
Dictionary<string, string> dict = App.GetConfig<Dictionary<string, string>>("丹方");
|
||||
if (dict?.Count > 0)
|
||||
{
|
||||
dict.TryGetValue(goodsName, out string doc);
|
||||
if (string.IsNullOrWhiteSpace(doc) is false)
|
||||
{
|
||||
GroupSendMessageRequest request = new()
|
||||
{
|
||||
GroupId = groupId,
|
||||
Message = new()
|
||||
{
|
||||
new MessageItem()
|
||||
{
|
||||
Type = "text",
|
||||
Data = new()
|
||||
{
|
||||
Text = doc
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
await RobotAPI.SendGroupText(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