示例#1
0
 public CoolQRouteMessage(CoolQCode message, CoolQIdentity cqIdentity, string atId = null) :
     this(new CoolQMessage(message), cqIdentity, atId)
 {
 }
示例#2
0
 public CoolQRouteMessage ToSource(CoolQCode message, bool enableAt = false)
 {
     return(ToSource(new CoolQMessage(message), enableAt));
 }
示例#3
0
 public static string Compose(CoolQCode CoolQCode) => InnerCompose(CoolQCode);
示例#4
0
        private static string InnerCompose(CoolQCode CoolQCode)
        {
            switch (CoolQCode)
            {
            case Text text:
                return(text.Content);

            case At at:
                return($"[CQ:at,qq={at.UserId}]");

            case Face face:
                return($"[CQ:face,id={face.FaceId}]");

            case Emoji emoji:
                return($"[CQ:emoji,id={emoji.EmojiId}]");

            case Dice _:
                return("[CQ:dice]");

            case Rps _:
                return("[CQ:rps]");

            case BFace bFace:
                return($"[CQ:bface,id={bFace.BFaceId}]");

            case SFace sFace:
                return($"[CQ:sface,id={sFace.SFaceId}]");

            case CustomMusic music:
                return(string.Format("[CQ:music,type=custom,url={0},audio={1},title={2},content={3},image={4}]",
                                     music.LinkUrl, music.AudioUrl, music.Title, music.Content, music.ImageUrl));

            case Share share:
                return(string.Format("[CQ:share,url={0},title={1},content={2},image={3}]",
                                     share.LinkUrl, share.Title, share.Content, share.ImageUrl));

            case FileImage image:
            {
                switch (image.FileType)
                {
                case FileCoolQCode.FileTypeEnum.Local:
                    return(image.UseBase64
                                    ? $"[CQ:image,file=base64://{EncodeFileToBase64(image.Path)}]"
                                    : $"[CQ:image,file=file://{image.Path}]");

                // ReSharper disable once RedundantCaseLabel
                case FileCoolQCode.FileTypeEnum.Url:
                default:
                    if (!image.Url.StartsWith("http://") && !image.Url.StartsWith("https://"))
                    {
                        return($"[CQ:image,file=http://{image.Url}]");
                    }

                    return($"[CQ:image,file={image.Url}]");
                }
            }

            case FileRecord record:
            {
                switch (record.FileType)
                {
                case FileCoolQCode.FileTypeEnum.Local:
                    return(record.UseBase64
                                    ? $"[CQ:record,file=base64://{EncodeFileToBase64(record.Path)}]"
                                    : $"[CQ:record,file=file://{record.Path}]");

                // ReSharper disable once RedundantCaseLabel
                case FileCoolQCode.FileTypeEnum.Url:
                default:
                    return($"[CQ:record,file=http://{record.Url.Replace("http://", "")}]");
                }
            }

            case Assemblage assemblage:
                var           codes = assemblage.CoolQCodes;
                StringBuilder sb    = new StringBuilder();
                foreach (var code in codes)
                {
                    sb.Append(InnerCompose(code));
                }
                return(sb.ToString());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#5
0
 public CoolQMessage(params CoolQCode[] coolQCodes)
 {
     _assembledCoolQCodes = new Assemblage(coolQCodes);
 }