/** * Creates an EmbedBuilder using fields in an existing embed. * * @param embed * the existing embed */ public EmbedBuilder(MessageEmbed embed) { if(embed != null) { setDescription(embed.getDescription()); this.url = embed.getUrl(); this.title = embed.getTitle(); this.timestamp = embed.getTimestamp(); this.color = embed.getColorRaw(); this.thumbnail = embed.getThumbnail(); this.author = embed.getAuthor(); this.footer = embed.getFooter(); this.image = embed.getImage(); if (embed.getFields() != null) fields.addAll(embed.getFields()); } }
/** * Converts an {@link MessageEmbed} into a String. * This will first start with the title in bold. then adds the description. * Then puts in all the fields with the title fallowed by the value. The finally the footer italicized. * * @param embed The {@link MessageEmbed} to convert * @return The String containing embed data */ public static String embedToText(MessageEmbed embed) { StringBuilder sb = new StringBuilder(); if (embed.getTitle() != null) sb.append("**").append(embed.getTitle()).append("**: "); if (embed.getDescription() != null) sb.append(embed.getDescription()).append(" "); for (MessageEmbed.Field field : embed.getFields()) { sb.append("**").append(field.getName()).append("**: ").append(field.getValue()).append(" "); } if (embed.getFooter() != null) sb.append("*").append(embed.getFooter().getText()).append("*"); return sb.toString(); }
@Test public void testTitleIsSetWithUrlCorrectly() { PlaceholderMessage message = createWith(null); message.setTitle("Some weird Title", "https://avairebot.com/"); MessageEmbed embed = message.buildEmbed(); assertEquals("Some weird Title", embed.getTitle()); assertEquals("https://avairebot.com/", embed.getUrl()); }
@Test public void testTitleIsSetWithoutUrlCorrectly() { PlaceholderMessage message = createWith(null); message.setTitle("Some weird Title"); MessageEmbed embed = message.buildEmbed(); assertEquals("Some weird Title", embed.getTitle()); assertEquals(null, embed.getUrl()); }
embeddedBuilder.setTitle(embed.getTitle()); embeddedBuilder.setDescription(embed.getDescription()); embeddedBuilder.setColor(embed.getColor());