Exemplo n.º 1
0
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Embed exceeds its limit.
        /// </exception>
        public Embed(EmbedBuilder builder)
        {
            Contract.AssertNotNull(builder, nameof(builder));

            int totalLength = builder.GetStringBuilder().Length +
                              builder.GetFields().Sum(field => field.Value.Length + field.Name.Length) +
                              (builder.Footer?.Text.Length ?? 0) + (builder.Author?.Name?.Length ?? 0);

            if (totalLength > WebhookProvider.MAX_EMBED_DATA_LENGTH)
            {
                throw new ArgumentOutOfRangeException($"Embed exceed the embed limit of {WebhookProvider.MAX_EMBED_DATA_LENGTH} in length, see https://discord.com/developers/docs/resources/channel#embed-limits-limits");
            }

            _title       = builder.Title;
            _type        = builder.Type;
            _description = builder.GetStringBuilder().ToString();
            _url         = builder.Url;
            _timestamp   = builder.Timestamp;
            _color       = builder.Color;
            _footer      = builder.Footer;
            _image       = builder.Image;
            _thumbnail   = builder.Thumbnail;
            _video       = builder.Video;
            _provider    = builder.Provider;
            _author      = builder.Author;
            _fields      = builder._fields?.ToArray().ToReadOnlyCollection();
        }