private static List <Types.EmbedField> BuildFieldList(Types.EmbedFields input) { return(new List <Types.EmbedField>() { input.field1, input.field2, input.field3, input.field4, input.field5, input.field6, input.field7, input.field8, input.field9, input.field10, input.field11, input.field12, input.field13, input.field14, input.field15, input.field16, input.field17, input.field18, input.field19, input.field20, input.field21, input.field22, input.field23, input.field24, input.field25 }); }
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); }