/** * 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()); } }
/** * Whether this embed is empty. * * @return True, if this embed has no content */ public boolean isEmpty() { return getLength() == 0 && getImage() == null && getThumbnail() == null; }
embeddedBuilder.setTitle(embed.getTitle()); embeddedBuilder.setDescription(embed.getDescription()); embeddedBuilder.setColor(embed.getColor()); embeddedBuilder.setTimestamp(embed.getTimestamp()); if (embed.getFooter() != null) { embeddedBuilder.setFooter(embed.getFooter().getText(), null); for (MessageEmbed.Field field : embed.getFields()) { if (!field.getName().equalsIgnoreCase("Reason")) { embeddedBuilder.addField(field);
/** * 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(); }
public static void sendMessage(MessageType type, EmbedBuilder builder, TextChannel channel, long autoDeleteDelay) { if (builder.build().getColor() == null) builder.setColor(type.getColor()); if (type == MessageType.ERROR) { if (flareHeart == null) flareHeart = Getters.getEmoteById(386550693294768129L); builder.setDescription(builder.build().getDescription() + "\n\nIf you need more support join our " + "[Support Server](" + Constants.INVITE_URL + ")! Our staff can support on any issue you may have! " + (flareHeart == null ? "<3" : flareHeart.getAsMention())); } if (type != MessageType.WARNING && type != MessageType.ERROR && builder.getFields().isEmpty()) { Optional<String> globalMsg = getGlobalMessage(); if ((!lastGlobalMsg.containsKey(channel.getIdLong()) || System.currentTimeMillis() - lastGlobalMsg.get(channel.getIdLong()) >= GLOBAL_MSG_DELAY) && globalMsg.isPresent()) { lastGlobalMsg.put(channel.getIdLong(), System.currentTimeMillis()); builder.setDescription(builder.build().getDescription() + "\n\n" + globalMsg.get()); } } if (autoDeleteDelay > 0) sendAutoDeletedMessage(builder.build(), autoDeleteDelay, channel); else sendMessage(builder.build(), channel); }
@Test public void testFooterIsSetWithoutIconCorrectly() { PlaceholderMessage message = createWith(null); message.setFooter("Some weird title!"); MessageEmbed embed = message.buildEmbed(); assertEquals("Some weird title!", embed.getFooter().getText()); assertEquals(null, embed.getFooter().getIconUrl()); }
@Test public void testFieldsAreCreatedCorrectly() { PlaceholderMessage message = createWith(null); message.addField("Name", "Some Value", false); MessageEmbed embed = message.buildEmbed(); assertEquals(1, embed.getFields().size()); assertEquals("Name", embed.getFields().get(0).getName()); assertEquals("Some Value", embed.getFields().get(0).getValue()); assertEquals(false, embed.getFields().get(0).isInline()); }
String messageContent = event.getMessage().getContentStripped(); if (messageContent.trim().length() == 0 && !event.getMessage().getEmbeds().isEmpty()) { messageContent = event.getMessage().getEmbeds().get(0).getDescription();
@Test public void testAuthorIsSetCorrectly() { PlaceholderMessage message = createWith(null); message.setAuthor("Senither", "https://avairebot.com/", "https://i.imgur.com/odFyo1Q.gif"); MessageEmbed embed = message.buildEmbed(); assertEquals("Senither", embed.getAuthor().getName()); assertEquals("https://avairebot.com/", embed.getAuthor().getUrl()); assertEquals("https://i.imgur.com/odFyo1Q.gif", embed.getAuthor().getIconUrl()); }
@Test public void testTimestampIsSetCorrectly() { Instant now = Instant.now(); PlaceholderMessage message = createWith(null); message.setTimestamp(now); MessageEmbed embed = message.buildEmbed(); assertEquals(now.toEpochMilli(), embed.getTimestamp().toInstant().toEpochMilli()); }
@Test public void testColorIsSetCorrectly() { Color color = Color.decode("#BB1150"); // Can't build an empty embed message, so have to set a description since setting the color alone doesn't count. PlaceholderMessage message = createWith("Lorem ipsum"); message.setColor(color); MessageEmbed embed = message.buildEmbed(); assertEquals(color, embed.getColor()); }
@Test public void testThumbnailIsSetCorrectly() { PlaceholderMessage message = createWith(null); message.setThumbnail("https://i.imgur.com/wAD0tqK.gif"); MessageEmbed embed = message.buildEmbed(); assertEquals("https://i.imgur.com/wAD0tqK.gif", embed.getThumbnail().getUrl()); }
@Test public void testImageIsSetCorrectly() { PlaceholderMessage message = createWith(null); message.setImage("https://i.imgur.com/W7qSt0G.gif"); MessageEmbed embed = message.buildEmbed(); assertEquals("https://i.imgur.com/W7qSt0G.gif", embed.getImage().getUrl()); }
@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 testFooterIsSetWithIconCorrectly() { PlaceholderMessage message = createWith(null); message.setFooter("Some weird title!", "https://i.imgur.com/xW53ysv.gif"); MessageEmbed embed = message.buildEmbed(); assertEquals("Some weird title!", embed.getFooter().getText()); assertEquals("https://i.imgur.com/xW53ysv.gif", embed.getFooter().getIconUrl()); }
@Test public void testMultipleFieldsAreCreatedCorrectly() { PlaceholderMessage message = createWith(null); message.addField("Stuff 1", "Some Value", false); message.addField("Stuff 2", "Value Some", true); MessageEmbed embed = message.buildEmbed(); assertEquals(2, embed.getFields().size()); assertEquals("Stuff 1", embed.getFields().get(0).getName()); assertEquals("Some Value", embed.getFields().get(0).getValue()); assertEquals(false, embed.getFields().get(0).isInline()); assertEquals("Stuff 2", embed.getFields().get(1).getName()); assertEquals("Value Some", embed.getFields().get(1).getValue()); assertEquals(true, embed.getFields().get(1).isInline()); }
String messageContent = message.getContentStripped(); if (messageContent.isEmpty() && !message.getEmbeds().isEmpty()) { messageContent = message.getEmbeds().get(0).getDescription();
@Test public void testAuthorIsSetWithoutIconCorrectly() { PlaceholderMessage message = createWith(null); message.setAuthor("Senither", "https://avairebot.com/"); MessageEmbed embed = message.buildEmbed(); assertEquals("Senither", embed.getAuthor().getName()); assertEquals("https://avairebot.com/", embed.getAuthor().getUrl()); assertEquals(null, embed.getAuthor().getIconUrl()); }
@Test public void testAuthorIsSetWithoutUrlAndIconCorrectly() { PlaceholderMessage message = createWith(null); message.setAuthor("Senither"); MessageEmbed embed = message.buildEmbed(); assertEquals("Senither", embed.getAuthor().getName()); assertEquals(null, embed.getAuthor().getIconUrl()); assertEquals(null, embed.getAuthor().getUrl()); }