using Furion.Logging; using NapCatRobotClient.Core.RobotAPI.Dto.Request; namespace NapCatRobotClient.Service.Group.TextProcess { /// /// 猜成语 /// public class ChineseIdiomsProcess { /// /// 处理群消息 /// /// /// public static async Task 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 dict = App.GetConfig>("猜成语"); 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); } } }