Example #1
0
        private static JObject BuildFieldObject(Types.EmbedField field)
        {
            field.name  = RemoveReservedString(field.name);
            field.value = RemoveReservedString(field.value);
            if (field.name.Length == 0 || field.value.Length == 0)
            {
                return(null);
            }

            return(new JObject(
                       new JProperty("name", field.name),
                       new JProperty("value", field.value),
                       new JProperty("inline", field.inline)
                       ));
        }
Example #2
0
        private static JObject BuildEmbedObject(Types.EmbedArray embed)
        {
            JObject embedObject = new JObject();

            Types.EmbedAuthor embedAuthor = embed.author;
            Types.EmbedFields embedFields = embed.fields;
            Types.EmbedFooter embedFooter = embed.footer;

            // Adding the basics
            embed.title       = RemoveReservedString(embed.title);
            embed.description = RemoveReservedString(embed.description);
            embed.url         = RemoveReservedString(embed.url);
            embed.color       = RemoveReservedString(embed.color);
            embed.thumbnail   = RemoveReservedString(embed.thumbnail);
            embed.image       = RemoveReservedString(embed.image);
            if (embed.title.Length > 0)
            {
                embedObject.Add(new JProperty("title", embed.title));
            }
            if (embed.description.Length > 0)
            {
                embedObject.Add(new JProperty("description", embed.description));
            }
            if (embed.url.StartsWith("https://"))
            {
                embedObject.Add(new JProperty("url", embed.url));
            }
            if (embed.color.Length == 6)
            {
                embedObject.Add(new JProperty("color", Convert.ToInt32(embed.color, 16)));
            }
            if (embed.useTimestamp)
            {
                embedObject.Add(new JProperty("timestamp", DateTime.UtcNow.ToString("s")));
            }
            if (embed.thumbnail.StartsWith("https://"))
            {
                embedObject.Add(new JProperty("thumbnail", new JObject(new JProperty("url", embed.thumbnail))));
            }
            if (embed.image.StartsWith("https://"))
            {
                embedObject.Add(new JProperty("image", new JObject(new JProperty("url", embed.image))));
            }

            // Handle additional objects
            embedAuthor.name     = RemoveReservedString(embedAuthor.name);
            embedAuthor.url      = RemoveReservedString(embedAuthor.url);
            embedAuthor.icon_url = RemoveReservedString(embedAuthor.icon_url);
            if (embedAuthor.name.Length > 0)
            {
                JObject embedObjectAuthor = new JObject(new JProperty("name", embedAuthor.name));
                if (embedAuthor.url.StartsWith("https://"))
                {
                    embedObjectAuthor.Add(new JProperty("url", embedAuthor.url));
                }
                if (embedAuthor.icon_url.StartsWith("https://"))
                {
                    embedObjectAuthor.Add(new JProperty("icon_url", embedAuthor.icon_url));
                }

                embedObject.Add(new JProperty("author", embedObjectAuthor));
            }

            embedFooter.text     = RemoveReservedString(embedFooter.text);
            embedFooter.icon_url = RemoveReservedString(embedFooter.icon_url);
            if (embedFooter.text.Length > 0)
            {
                JObject embedObjectFooter = new JObject(new JProperty("text", embedFooter.text));
                if (embedFooter.icon_url.StartsWith("https://"))
                {
                    embedObjectFooter.Add(new JProperty("icon_url", embedFooter.icon_url));
                }

                embedObject.Add(new JProperty("footer", embedObjectFooter));
            }

            // Build fields array
            List <Types.EmbedField> fieldList = BuildFieldList(embedFields);
            JArray fieldProperty = new JArray();

            for (int i = 0; i < 25; i++)
            {
                Types.EmbedField field = fieldList.ElementAt(i);
                if (field == null)
                {
                    break;
                }
                JObject fieldObject = BuildFieldObject(field);
                if (fieldObject != null)
                {
                    fieldProperty.Add(fieldObject);
                }
            }
            if (fieldProperty.Count() > 0)
            {
                embedObject.Add(new JProperty("fields", fieldProperty));
            }

            return(embedObject);
        }