Example #1
0
        public static MessageBody ToCqHttpMessages(this IGreenOnionsMessages greenOnionsMessage, int?RelpyId)
        {
            MessageBody cqHttpMessages = new MessageBody();

            if (greenOnionsMessage.Reply && RelpyId != null)
            {
                cqHttpMessages.Add(SoraSegment.Reply(RelpyId.Value));
            }

            for (int i = 0; i < greenOnionsMessage.Count; i++)
            {
                if (greenOnionsMessage[i] is IGreenOnionsTextMessage txtMsg)
                {
                    cqHttpMessages.Add(SoraSegment.Text(txtMsg.Text));
                }
                else if (greenOnionsMessage[i] is IGreenOnionsImageMessage imgMsg)
                {
                    string data = string.IsNullOrEmpty(imgMsg.Url) ? ("base64://" + imgMsg.Base64Str) : imgMsg.Url;
                    cqHttpMessages.Add(SoraSegment.Image(data));
                }
                else if (greenOnionsMessage[i] is IGreenOnionsAtMessage atMsg)
                {
                    if (atMsg.AtId == -1)
                    {
                        cqHttpMessages.Add(SoraSegment.AtAll());
                    }
                    else
                    {
                        cqHttpMessages.Add(SoraSegment.At(atMsg.AtId));
                    }
                }
                else if (greenOnionsMessage[i] is IGreenOnionsForwardMessage forwardMsg)
                {
                    for (int j = 0; j < forwardMsg.ItemMessages.Count; j++)
                    {
                        cqHttpMessages.AddRange(ToCqHttpMessages(forwardMsg.ItemMessages[i].itemMessage, RelpyId));
                    }
                }
            }
            return(cqHttpMessages);
        }
Example #2
0
 /// <summary>
 /// 生成AT 消息段
 /// </summary>
 /// <param name="uid">uid</param>
 public static SoraSegment ToAt(this int uid)
 {
     return(SoraSegment.At(uid));
 }
Example #3
0
 /// <summary>
 /// 获取At消息段
 /// </summary>
 /// <returns>
 /// <see cref="SoraSegment"/> AT
 /// </returns>
 public SoraSegment At()
 {
     return(SoraSegment.At(Id));
 }