Java Code Examples for net.dv8tion.jda.api.EmbedBuilder#setImage()
The following examples show how to use
net.dv8tion.jda.api.EmbedBuilder#setImage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractPhotoCommand.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public void doCommandAsync(GuildMessageReceivedEvent message, BotContext context, String query) { try { message.getChannel().sendTyping().queue(); RandomPhotoResponse response = photoResult.get(); if (response == null) { messageService.onEmbedMessage(message.getChannel(), getErrorCode()); return; } EmbedBuilder builder = messageService.getBaseEmbed(); builder.setImage(response.getFile()); builder.setColor(null); messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build()); } catch (Exception e) { log.warn("Could not get photo"); messageService.onEmbedMessage(message.getChannel(), getErrorCode()); } }
Example 2
Source File: AvatarCommand.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String query) { String avatarUrl = reference.getEffectiveAvatarUrl(); if (StringUtils.isEmpty(avatarUrl)) { messageService.onEmbedMessage(event.getChannel(), "discord.command.avatar.none"); return false; } String name = reference.getEffectiveName(); EmbedBuilder builder = messageService.getBaseEmbed(); if (StringUtils.isNotEmpty(name)) { builder.setDescription(messageService.getMessage("discord.command.avatar.text", name)); } builder.setImage(avatarUrl + "?size=512"); messageService.sendMessageSilent(event.getChannel()::sendMessage, builder.build()); return true; }
Example 3
Source File: DogCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private void sendImage(GuildMessageReceivedEvent event, DogImage image) { EmbedBuilder builder = messageService.getBaseEmbed(); builder.setImage(image.getUrl()); if (CollectionUtils.isNotEmpty(image.getBreeds())) { DogBreed breed = image.getBreeds().get(0); if (StringUtils.isNotEmpty(breed.getName())) { builder.addField(messageService.getMessage("discord.command.dog.breed.title"), breed.getName(), true); } if (StringUtils.isNotEmpty(breed.getBreedGroup())) { builder.addField(messageService.getMessage("discord.command.dog.breedGroup.title"), breed.getBreedGroup(), true); } if (StringUtils.isNotEmpty(breed.getBredFor())) { builder.addField(messageService.getMessage("discord.command.dog.bredFor.title"), breed.getBredFor(), true); } if (StringUtils.isNotEmpty(breed.getTemperament())) { builder.addField(messageService.getMessage("discord.command.dog.temperament.title"), breed.getTemperament(), true); } String weight = getMeasure(breed.getWeight()); if (StringUtils.isNotEmpty(weight)) { builder.addField(messageService.getMessage("discord.command.dog.weight.title"), weight, true); } String height = getMeasure(breed.getHeight()); if (StringUtils.isNotEmpty(height)) { builder.addField(messageService.getMessage("discord.command.dog.height.title"), height, true); } } messageService.sendMessageSilent(event.getChannel()::sendMessage, builder.build()); }
Example 4
Source File: EmbedJSON.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
public MessageEmbed gen(Member member) { EmbedBuilder embedBuilder = new EmbedBuilder(); if (title != null) embedBuilder.setTitle(title, titleUrl); if (description != null) embedBuilder.setDescription(description); if (author != null) embedBuilder.setAuthor(author, authorUrl, authorImg); if (footer != null) embedBuilder.setFooter(footer, footerImg); if (image != null) embedBuilder.setImage(image); if (thumbnail != null) embedBuilder.setThumbnail(thumbnail); if (color != null) { Color col = null; try { col = (Color) Color.class.getField(color).get(null); } catch (Exception ignored) { String colorLower = color.toLowerCase(); if (colorLower.equals("member")) { if (member != null) col = member.getColor(); } else if (colorLower.matches("#?(0x)?[0123456789abcdef]{1,6}")) { try { col = Color.decode(colorLower.startsWith("0x") ? colorLower : "0x" + colorLower); } catch (Exception ignored2) { } } } if (col != null) embedBuilder.setColor(col); } fields.forEach(f -> { if (f == null) { embedBuilder.addBlankField(false); } else if (f.value == null) { embedBuilder.addBlankField(f.inline); } else { embedBuilder.addField(f.name == null ? "" : f.name, f.value, f.inline); } }); return embedBuilder.build(); }
Example 5
Source File: SteamCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
@Override public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String query) { if (StringUtils.isEmpty(query)) { messageService.onMessage(message.getChannel(), "discord.command.steam.enter"); return true; } message.getChannel().sendTyping().queue(); SteamApp app = null; if (StringUtils.isNumeric(query)) { app = steamService.findByAppId(Long.parseLong(query)); } if (app == null) { app = steamService.findOne(query); } SteamAppDetails details = steamService.getDetails(app, contextService.getLocale()); if (details == null) { messageService.onMessage(message.getChannel(), "discord.command.steam.noResults"); return false; } String storeUrl = APP_PAGE + app.getAppId(); EmbedBuilder builder = messageService.getBaseEmbed(true); if (StringUtils.isNotEmpty(details.getHeaderImage())) { builder.setThumbnail(details.getHeaderImage()); } builder.setAuthor(details.getName(), storeUrl); builder.setDescription(details.getShortDescription()); if (details.getReleaseDate() != null && details.getReleaseDate().isCorrect()) { builder.addField(getReleaseDate(details.getReleaseDate())); } if (details.getPrice() != null && details.getPrice().isCorrect()) { builder.addField(getPrice(details.getPrice())); } if (CollectionUtils.isNotEmpty(details.getDevelopers())) { builder.addField(getParts(details.getDevelopers(), "discord.command.steam.developers")); } if (CollectionUtils.isNotEmpty(details.getPublishers())) { builder.addField(getParts(details.getPublishers(), "discord.command.steam.publishers")); } if (details.getPlatforms() != null && details.getPlatforms().isCorrect()) { builder.addField(getPlatforms(details.getPlatforms())); } if (StringUtils.isNotEmpty(details.getWebSite())) { builder.addField(messageService.getMessage("discord.command.steam.website"), details.getWebSite(), true); } if (CollectionUtils.isNotEmpty(details.getScreenshots())) { for (SteamAppScreenshot screenshot : details.getScreenshots()) { if (StringUtils.isNotEmpty(screenshot.getFull())) { builder.setImage(screenshot.getFull()); break; } } } messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build()); return true; }
Example 6
Source File: MessageTemplateServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
public Message compile(@NonNull MessageTemplateCompiler compiler) { try { MessageTemplatePlaceholderResolver resolver = getPropertyResolver(compiler); String content = processContent(getContent(compiler), resolver, compiler, Message.MAX_CONTENT_LENGTH, false); MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.setContent(content); if (compiler.getTemplate() != null) { messageBuilder.setTTS(compiler.getTemplate().isTts()); } if (compiler.getTemplate() == null || compiler.getTemplate().getType() == MessageTemplateType.TEXT) { if (StringUtils.isBlank(content)) { return null; } return messageBuilder.build(); } MessageTemplate template = compiler.getTemplate(); EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setDescription(processContent(getEmbedContent(compiler), resolver, compiler, MessageEmbed.TEXT_MAX_LENGTH, false)); embedBuilder.setThumbnail(processUrl(template.getThumbnailUrl(), resolver, compiler)); embedBuilder.setImage(processUrl(template.getImageUrl(), resolver, compiler)); if (StringUtils.isNotEmpty(template.getColor())) { embedBuilder.setColor(Color.decode(template.getColor())); } else { embedBuilder.setColor(contextService.getDefaultColor()); } if (template.getTimestamp() != null) { embedBuilder.setTimestamp(template.getTimestamp().toInstant()); } embedBuilder.setAuthor( processContent(template.getAuthor(), resolver, compiler, MessageEmbed.TITLE_MAX_LENGTH, false), processUrl(template.getAuthorUrl(), resolver, compiler), processUrl(template.getAuthorIconUrl(), resolver, compiler)); embedBuilder.setTitle( processContent(template.getTitle(), resolver, compiler, MessageEmbed.TITLE_MAX_LENGTH, false), processUrl(template.getTitleUrl(), resolver, compiler)); embedBuilder.setFooter( processContent(template.getFooter(), resolver, compiler, MessageEmbed.TEXT_MAX_LENGTH, false), processUrl(template.getFooterIconUrl(), resolver, compiler)); int length = embedBuilder.length(); if (CollectionUtils.isNotEmpty(template.getFields())) { for (MessageTemplateField templateField : template.getFields()) { String name = processContent(templateField.getName(), resolver, compiler, MessageEmbed.TITLE_MAX_LENGTH, false); if (StringUtils.isEmpty(name)) { name = ""; } String value = processContent(templateField.getValue(), resolver, compiler, MessageEmbed.VALUE_MAX_LENGTH, false); if (StringUtils.isEmpty(value)) { value = ""; } if ((length += name.length() + value.length()) > MessageEmbed.EMBED_MAX_LENGTH_BOT) { break; } embedBuilder.addField(name, value, templateField.isInline()); } } if (messageBuilder.isEmpty() && embedBuilder.isEmpty()) { return null; } messageBuilder.setEmbed(embedBuilder.build()); return messageBuilder.build(); } catch (IllegalArgumentException e) { log.error("Cannot compile message", e); } return null; }
Example 7
Source File: ImageGame.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
protected RestAction<Message> sendEmbedImage(MessageChannel channel, String url, Consumer<EmbedBuilder> embedConfigurator) { EmbedBuilder eb = new EmbedBuilder(); embedConfigurator.accept(eb); eb.setImage("attachment://image.png"); return channel.sendMessage(new MessageBuilder().setEmbed(eb.build()).build()).addFile(cache.getInput(url), "image.png"); }