Java Code Examples for net.dv8tion.jda.api.EmbedBuilder#setThumbnail()

The following examples show how to use net.dv8tion.jda.api.EmbedBuilder#setThumbnail() . 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: ServerInfoCommand.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String query) {
    Guild guild = message.getGuild();

    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(messageService.getMessage("discord.command.server.title", guild.getName()));
    builder.setThumbnail(guild.getIconUrl());
    builder.setFooter(messageService.getMessage("discord.command.info.identifier", guild.getId()), null);

    builder.addField(getMemberListField(guild));
    builder.addField(getChannelListField(guild));
    builder.addField(getShard(guild));
    builder.addField(getVerificationLevel(guild.getVerificationLevel()));
    builder.addField(getRegion(guild));
    builder.addField(getOwner(guild));
    builder.addField(getCreatedAt(guild, context));

    messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
    return true;
}
 
Example 2
Source File: AudioMessageManager.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private EmbedBuilder getBasicMessage(TrackRequest request) {
    AudioTrackInfo info = request.getTrack().getInfo();
    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(getTitle(info), getUrl(info));
    String artworkUri = DiscordUtils.getUrl(TrackData.getArtwork(request.getTrack()));
    builder.setAuthor(getArtist(info), getUrl(info), artworkUri);
    builder.setThumbnail(artworkUri);
    builder.setDescription(messageService.getMessage("discord.command.audio.queue.add"));
    return builder;
}
 
Example 3
Source File: InfoCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String query) {
    String prefix = context.getConfig() != null ? context.getConfig().getPrefix() : commonProperties.getDiscord().getDefaultPrefix();

    EmbedBuilder builder = messageService.getBaseEmbed(true);
    builder.setAuthor(message.getJDA().getSelfUser().getName(), messageService.getMessage("about.support.page"));
    builder.setThumbnail(commonProperties.getBranding().getAvatarSmallUrl());

    String helpCommand = messageService.getMessageByLocale("discord.command.help.key",
            context.getCommandLocale());

    builder.setDescription(messageService.getMessage("discord.command.info.description", prefix, helpCommand));

    builder.addField(
            messageService.getMessage("discord.command.info.author.title"),
            messageService.getMessage("about.support.owner"), true);

    DateTimeFormatter formatter = DateTimeFormat
            .mediumDateTime()
            .withLocale(contextService.getLocale())
            .withZone(context.getTimeZone());
    builder.addField(
            messageService.getMessage("discord.command.info.version.title"),
            String.format("%s (%s)", appVersion, formatter.print(buildTimestamp)), true);

    builder.addField(
            messageService.getMessage("discord.command.info.links.title"),
            messageService.getMessage("discord.command.info.links.content"), true);

    builder.addField(
            messageService.getMessage("discord.command.info.framework.title"),
            messageService.getMessage("discord.command.info.framework.content",
                    jdaVersion, lavaPlayerVersion, springVersion),
            true);

    messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
    return true;
}
 
Example 4
Source File: StatsCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String content) {
    EmbedBuilder builder = messageService.getBaseEmbed(true);
    builder.setTitle(messageService.getMessage("discord.command.stats.title"));
    builder.setThumbnail(commonProperties.getBranding().getAvatarSmallUrl());

    Map<String, Metric> metricMap = metricRegistry.getMetrics();
    builder.addField(getCommonStats(metricMap));
    builder.addField(getCommandStats(metricMap));
    builder.addField(getPlatformStats(metricMap));

    messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
    return true;
}
 
Example 5
Source File: InviteCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private MessageEmbed createInfoMessage(InviteInfo inviteInfo, BotContext context) {
    EmbedBuilder builder = messageService.getBaseEmbed(false);

    if (inviteInfo.getGuild() != null) {
        InviteInfo.Guild guildInfo = inviteInfo.getGuild();
        String iconUrl = AvatarType.ICON.getUrl(guildInfo.getId(), guildInfo.getIcon());
        String inviteUrl = "https://discord.gg/" + (StringUtils.isNotEmpty(guildInfo.getVanityUrlCode()) ? guildInfo.getVanityUrlCode() : inviteInfo.getCode());
        builder.setTitle(String.format("%s (ID: %s)", guildInfo.getName(), guildInfo.getId()), inviteUrl);
        builder.setDescription(guildInfo.getDescription());
        builder.setThumbnail(iconUrl);

        Guild guild = discordService.getGuildById(Long.valueOf(guildInfo.getId()));
        if (guild != null) {
            builder.addField(getMemberListField(guild));
            builder.addField(getChannelListField(guild));
            builder.addField(getShard(guild));
            builder.addField(getVerificationLevel(guild.getVerificationLevel()));
            builder.addField(getRegion(guild));
            builder.addField(getOwner(guild));
            builder.addField(getCreatedAt(guild, context));
        } else {
            if (guildInfo.getVerificationLevel() != null) {
                builder.addField(getVerificationLevel(Guild.VerificationLevel.fromKey(guildInfo.getVerificationLevel())));
            }
        }
    }

    if (inviteInfo.getChannel() != null) {
        InviteInfo.Channel channel = inviteInfo.getChannel();
        String info = String.format("`#%s` (ID: %s)", channel.getName(), channel.getId());
        builder.addField(messageService.getMessage("discord.command.invite.channel"), info, true);
    }

    if (inviteInfo.getInviter() != null) {
        InviteInfo.Inviter inviter = inviteInfo.getInviter();
        String avatarUrl = StringUtils.isNotEmpty(inviter.getAvatar()) ? AvatarType.AVATAR.getUrl(inviter.getId(), inviter.getAvatar()) : null;
        builder.setFooter(String.format("%s#%s (ID: %s)", inviter.getUsername(), inviter.getDiscriminator(), inviter.getId()), avatarUrl);
    }
    return builder.build();
}
 
Example 6
Source File: EmbedJSON.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: ModLog.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static void log(Member author, User target, String reason, String channel, ModAction action, long caseNumber, int messagesDeleted) {
    DBGuild guildDB = db.getGuild(author.getGuild());
    Player player = db.getPlayer(author);
    PlayerData playerData = player.getData();
    EmbedBuilder embedBuilder = new EmbedBuilder();

    embedBuilder.addField("Responsible Moderator", author.getEffectiveName(), true);

    if (target != null) {
        embedBuilder.addField("Member", target.getName(), true);
        embedBuilder.setThumbnail(target.getEffectiveAvatarUrl());
    } else {
        embedBuilder.setThumbnail(author.getUser().getEffectiveAvatarUrl());
    }

    embedBuilder.addField("Reason", reason, false);
    embedBuilder.addField("Channel", channel, true);

    if (action == ModAction.PRUNE) {
        embedBuilder.addField("Messages Deleted", String.valueOf(messagesDeleted), true);
    }

    //Why was this a giant switch statement?
    embedBuilder.setAuthor(String.format("%s | Case #%s", Utils.capitalize(action.name()), caseNumber),
            null, author.getUser().getEffectiveAvatarUrl());

    if (!playerData.hasBadge(Badge.POWER_USER)) {
        playerData.addBadgeIfAbsent(Badge.POWER_USER);
        player.saveAsync();
    }

    if (guildDB.getData().getGuildLogChannel() != null) {
        TextChannel logChannel = MantaroBot.getInstance().getShardManager().getTextChannelById(guildDB.getData().getGuildLogChannel());
        if (logChannel != null) {
            logChannel.sendMessage(embedBuilder.build()).queue();
        }
    }
}
 
Example 8
Source File: UserInfoCommand.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String query) {
    DateTimeFormatter formatter = DateTimeFormat.mediumDateTime()
            .withLocale(contextService.getLocale())
            .withZone(context.getTimeZone());

    LocalMember localMember = reference.getLocalMember();
    LocalUser localUser = reference.getLocalUser();

    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(messageService.getMessage("discord.command.user.title", reference.getEffectiveName()));
    builder.setThumbnail(reference.getEffectiveAvatarUrl());
    builder.setFooter(messageService.getMessage("discord.command.info.identifier", reference.getId()), null);

    StringBuilder commonBuilder = new StringBuilder();
    getName(commonBuilder, reference);

    if (reference.getMember() != null) {
        Member member = reference.getMember();
        getOnlineStatus(commonBuilder, member);
        if (CollectionUtils.isNotEmpty(member.getActivities())) {
            getActivities(commonBuilder, member);
        }
        if (member.getOnlineStatus() == OnlineStatus.OFFLINE || member.getOnlineStatus() == OnlineStatus.INVISIBLE) {
            if (localUser != null && localUser.getLastOnline() != null) {
                getLastOnlineAt(commonBuilder, localUser, formatter);
            }
        }
        getJoinedAt(commonBuilder, member, formatter);
        getCreatedAt(commonBuilder, member.getUser(), formatter);
    }

    builder.addField(messageService.getMessage("discord.command.user.common"), commonBuilder.toString(), false);

    Guild guild = event.getGuild();

    if (localMember != null) {
        RankingConfig config = rankingConfigService.get(event.getGuild());
        if (config != null && config.isEnabled()) {
            RankingInfo info = rankingService.getRankingInfo(event.getGuild().getIdLong(), reference.getId());
            rankCommand.addFields(builder, config, info, guild);
        }
    }

    MemberBio memberBio = bioRepository.findByGuildIdAndUserId(guild.getIdLong(), reference.getId());
    String bio = memberBio != null ? memberBio.getBio() : null;
    if (StringUtils.isEmpty(bio)
            && Objects.equals(event.getAuthor(), reference.getUser())
            && !commandsService.isRestricted(BioCommand.KEY, event.getChannel(), event.getMember())) {
        String bioCommand = messageService.getMessageByLocale("discord.command.bio.key",
                context.getCommandLocale());
        bio = messageService.getMessage("discord.command.user.bio.none", context.getConfig().getPrefix(),
                bioCommand);
    }
    if (StringUtils.isNotEmpty(bio)) {
        builder.setDescription(CommonUtils.trimTo(bio, MessageEmbed.TEXT_MAX_LENGTH));
    }
    messageService.sendMessageSilent(event.getChannel()::sendMessage, builder.build());
    return true;
}
 
Example 9
Source File: SteamCommand.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@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 10
Source File: MessageTemplateServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
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;
}