You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
3.2 KiB
C#
76 lines
3.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|