public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; long groupId = Convert.ToInt64(routeMsg.GroupId); long userId = Convert.ToInt64(routeMsg.UserId); long discussId = Convert.ToInt64(routeMsg.DiscussId); var type = routeMsg.MessageType; string group, sender, message = routeMsg.Message.RawMessage; var data = CoolQDispatcher.Current.SessionList[(CoolQIdentity)routeMsg.Identity].GetDataAsync().Result; if (type == MessageType.Private) { group = "私聊"; sender = data.Name; } else if (type == MessageType.Discuss) { group = data.Name; sender = routeMsg.UserId; } else { var userInfo = data?.GroupInfo?.Members ?.FirstOrDefault(i => i.UserId == userId) ?? CoolQHttpApiClient.GetGroupMemberInfo(routeMsg.GroupId, routeMsg.UserId).Data; group = data?.Name; sender = string.IsNullOrEmpty(userInfo.Card) ? userInfo.Nickname : userInfo.Card; } Logger.Message($"({group}) {sender}:\r\n {CoolQCode.DecodeToString(message).Replace("\n", "\n ")}"); return(null); }
/// <summary> /// 确定字体是否为空或有效。若为空或无效,则用默认语句替代。 /// </summary> /// <returns></returns> private string GetRealWord(FontFamily font, string pandaPath) { string word = PandaWord; if (word == null || word.Replace("\n", "").Replace("\r", "").Trim() == "") { word = _blankReply[StaticRandom.Next(0, _blankReply.Length)]; return(word); } word = CoolQCode.DecodeToString(PandaWord.Replace("!", "!").Replace("?", "?")); if (!IsLengthValid(word, pandaPath, font)) { word = _invalidReply[StaticRandom.Next(0, _invalidReply.Length)]; } return(word); }
public static void Query() { while (MessageQueue.Count != 0) { if (!MessageQueue.TryDequeue(out var routeMsg)) continue; var cmd = routeMsg.CommandName; const long cabbageId = 1335734629; string uname; if (cmd == "statme" || cmd == "bpme" || cmd == "mybp" || cmd == "costme" || cmd == "mycost") { BllUserRole bllUserRole = new BllUserRole(); List<TableUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId)); if (userInfo.Count == 0) DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(DefaultReply.IdNotBound, true)); uname = userInfo[0].CurrentUname; } else uname = routeMsg.ArgString; using (Session session = new Session(25000, new CoolQIdentity(cabbageId, MessageType.Private), cabbageId)) { DaylilyCore.Current.MessageDispatcher?.SendMessageAsync( new CoolQRouteMessage($"!{cmd.Replace("my", "").Replace("me", "")} {uname}", new CoolQIdentity(cabbageId, MessageType.Private))); try { CoolQRouteMessage result = (CoolQRouteMessage)session.GetMessage(); session.Timeout = 600; CoolQRouteMessage result2 = null; try { result2 = (CoolQRouteMessage)session.GetMessage(); } catch { // ignored } ImageInfo[] imgList = CoolQCode.GetImageInfo(result.RawMessage) ?? CoolQCode.GetImageInfo(result2?.RawMessage); if (imgList == null) { DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(result.RawMessage)); if (result2 != null) DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(result2.RawMessage)); continue; } //throw new IndexOutOfRangeException("查询失败:" + result.Message); var message = CoolQCode.DecodeToString(result.RawMessage); foreach (var item in imgList) { var str = new FileImage(new Uri(item.Url)); StringFinder sf = new StringFinder(message); sf.FindNext("[图片]"); string str1 = sf.Cut(); if (sf.FindNext("[图片]", false) > message.Length - 1) { message = str1 + str; continue; } sf.FindToLast(); string str2 = sf.Cut(); message = str1 + str + str2; } DaylilyCore.Current.MessageDispatcher?.SendMessageAsync( routeMsg.ToSource(message + "\r\n(查询由白菜支持)")); } catch (IndexOutOfRangeException e) { string msg = e.Message; DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true)); } catch (TimeoutException) { string msg = "查询失败,白菜没有搭理人家.."; DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true)); } catch (Exception ex) { string msg = "查询失败,未知错误。"; Logger.Exception(ex); DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true)); } // catch } // using } // while }