Ejemplo n.º 1
0
        public static EmbedBuilder CreateEmbedBuilder(this EmbedData embedData)
        {
            var embedBuilder = new EmbedBuilder
            {
                Title        = embedData.Title?.SubstringUpTo(256),
                ThumbnailUrl = embedData.ThumbnailUrl,
                Description  = embedData.Description,
                Url          = Uri.IsWellFormedUriString(embedData.Url, UriKind.Absolute) ? embedData.Url : null,
                ImageUrl     = embedData.ImageUrl,
            };

            if (!string.IsNullOrEmpty(embedData.Author))
            {
                embedBuilder.Author = new EmbedAuthorBuilder
                {
                    Name    = embedData.Author,
                    Url     = embedData.AuthorUrl,
                    IconUrl = embedData.AuthorIconUrl,
                };
            }

            if (!string.IsNullOrEmpty(embedData.Color))
            {
                var red   = Convert.ToInt32(embedData.Color.Substring(0, 2), 16);
                var green = Convert.ToInt32(embedData.Color.Substring(2, 2), 16);
                var blue  = Convert.ToInt32(embedData.Color.Substring(4, 2), 16);

                embedBuilder.Color = new Color(red / 255.0f, green / 255.0f, blue / 255.0f);
            }

            if (!string.IsNullOrEmpty(embedData.Footer))
            {
                embedBuilder.Footer = new EmbedFooterBuilder
                {
                    Text    = embedData.Footer,
                    IconUrl = embedData.FooterIconUrl,
                };
            }

            if (embedData.EmbedFields != null)
            {
                foreach (var embedField in embedData.EmbedFields)
                {
                    if (!string.IsNullOrEmpty(embedField.Name) && !string.IsNullOrEmpty(embedField.Value))
                    {
                        embedBuilder.AddField((field) =>
                        {
                            field.IsInline = embedField.IsInline;
                            field.Name     = embedField.Name;
                            field.Value    = embedField.Value;
                        });
                    }
                }
            }

            return(embedBuilder);
        }
Ejemplo n.º 2
0
        public static GuildedEmbed CreateGuildedEmbed(this EmbedData embedData)
        {
            var embed = new GuildedEmbed
            {
                Title       = embedData.Title,
                Description = embedData.Description,
            };

            if (!string.IsNullOrEmpty(embedData.Author))
            {
                embed.SetAuthor(embedData.Author, new Uri(embedData.AuthorUrl), new Uri(embedData.AuthorIconUrl));
            }

            if (!string.IsNullOrEmpty(embedData.ThumbnailUrl))
            {
                embed.SetThumbnail(embedData.ThumbnailUrl);
            }

            if (!string.IsNullOrEmpty(embedData.ImageUrl))
            {
                embed.SetImage(embedData.ImageUrl);
            }

            if (!string.IsNullOrEmpty(embedData.Url))
            {
                embed.SetUrl(embedData.Url);
            }

            if (!string.IsNullOrEmpty(embedData.Color))
            {
                var red   = Convert.ToInt32(embedData.Color.Substring(0, 2), 16);
                var green = Convert.ToInt32(embedData.Color.Substring(2, 2), 16);
                var blue  = Convert.ToInt32(embedData.Color.Substring(4, 2), 16);

                embed.SetColor(red, green, blue);
            }

            if (!string.IsNullOrEmpty(embedData.Footer))
            {
                embed.SetFooter(embedData.Footer, embedData.FooterIconUrl);
            }

            if (embedData.EmbedFields != null)
            {
                foreach (var embedField in embedData.EmbedFields)
                {
                    if (!string.IsNullOrEmpty(embedField.Name) && !string.IsNullOrEmpty(embedField.Value))
                    {
                        embed.AddField(embedField.Name, embedField.Value, embedField.IsInline);
                    }
                }
            }

            return(embed);
        }