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.
77 lines
3.2 KiB
C#
77 lines
3.2 KiB
C#
using Furion.Logging;
|
|
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
|
|
|
namespace NapCatRobotClient.Service.Group.TextProcess
|
|
{
|
|
/// <summary>
|
|
/// 猜成语
|
|
/// </summary>
|
|
public class ChineseIdiomsProcess
|
|
{
|
|
/// <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 groupMsg = JArray.Parse(json["message"].ToString()).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;
|
|
|
|
string pattern = @"题目:(.+)";
|
|
Match match = Regex.Match(groupMsg, pattern);
|
|
if (match.Success)
|
|
{
|
|
string emojiString = match.Groups[1].Value.Trim();
|
|
Dictionary<string, string> dict = App.GetConfig<Dictionary<string, string>>("猜成语");
|
|
if (dict?.Count > 0)
|
|
{
|
|
foreach (var item in dict)
|
|
{
|
|
if (emojiString.Contains(item.Key))
|
|
{
|
|
GroupSendMessageRequest request = new()
|
|
{
|
|
GroupId = groupId,
|
|
Message = new()
|
|
{
|
|
new MessageItem()
|
|
{
|
|
Type = "reply",
|
|
Data = new()
|
|
{
|
|
Id = json["message_id"].ToString()
|
|
}
|
|
},
|
|
new MessageItem()
|
|
{
|
|
Type = "text",
|
|
Data = new()
|
|
{
|
|
Text = item.Value
|
|
}
|
|
},
|
|
}
|
|
};
|
|
await RobotAPI.SendGroupText(request);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error($@"{DateTime.Now:yyyy-MM-dd HH:mm:ss} 猜成语 发生异常,异常信息:{ex.Message},异常堆栈:{ex.StackTrace}", true);
|
|
}
|
|
return await Task.FromResult(true);
|
|
}
|
|
|
|
}
|
|
}
|