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

The following examples show how to use net.dv8tion.jda.api.EmbedBuilder#build() . 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: 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 2
Source File: GuildListener.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private MessageEmbed createWelcomeMessage(Guild guild) {
    Function<String, String> m = messageService::getMessage;
    String webPage = m.apply("about.support.page");
    String discordServer = m.apply("about.support.server");
    String githubPage = m.apply("about.support.github");
    EmbedBuilder builder = messageService.getBaseEmbed(true);
    builder.setDescription(messageService.getMessage("welcome.guild.message") + NEW_LINE);

    User self = guild.getJDA().getSelfUser();
    builder.setAuthor(self.getName(), webPage, self.getAvatarUrl());

    builder.addField(m.apply("welcome.fields.common.title"),
            m.apply("welcome.fields.common.content") + NEW_LINE, false);
    builder.addField(m.apply("welcome.fields.music.title"),
            m.apply("welcome.fields.music.content") + NEW_LINE, false);
    builder.addField(m.apply("welcome.fields.audit.title"),
            m.apply("welcome.fields.audit.content") + NEW_LINE, false);
    builder.addField(m.apply("welcome.fields.subscriptions.title"),
            m.apply("welcome.fields.subscriptions.content") + NEW_LINE, false);
    builder.addField(m.apply("welcome.fields.ranking.title"),
            m.apply("welcome.fields.ranking.content") + NEW_LINE, false);
    builder.addField(m.apply("welcome.fields.welcome.title"),
            m.apply("welcome.fields.welcome.content") + NEW_LINE, false);
    builder.addField(m.apply("welcome.fields.commands.title"),
            m.apply("welcome.fields.commands.content") + NEW_LINE, false);
    builder.addField(m.apply("welcome.fields.custom.title"),
            m.apply("welcome.fields.custom.content") + NEW_LINE, false);
    builder.addField(m.apply("welcome.fields.fun.title"),
            m.apply("welcome.fields.fun.content") + NEW_LINE, false);

    builder.addField(m.apply("welcome.fields.support.title"),
            messageService.getMessage("welcome.fields.support.content", webPage, discordServer, githubPage),
            false);

    return builder.build();
}
 
Example 3
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 4
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
private void analyseCard(MessageReceivedEvent event) {
	logger.debug("Received message :" + event.getMessage().getContentRaw() + " from " + event.getAuthor().getName()+ " in #" + event.getChannel().getName());
	final List<MagicCard> liste = new ArrayList<>();
	Pattern p = Pattern.compile(getString(REGEX));
	Matcher m = p.matcher(event.getMessage().getContentRaw());
	if(m.find())
	{
		String name=m.group(1).trim();
		MagicEdition ed = null;
		if(name.contains("|"))
		{
			ed = new MagicEdition();
			ed.setId(name.substring(name.indexOf('|')+1,name.length()).toUpperCase().trim());
			name=name.substring(0, name.indexOf('|')).trim();
		}
		
		MessageChannel channel = event.getChannel();
			channel.sendTyping().queue();

			try {
				liste.addAll(MTGControler.getInstance().getEnabled(MTGCardsProvider.class).searchCardByName(name, ed, false));
			}
			catch(Exception e)
			{
				logger.error(e);
			}
			
			if(liste.isEmpty())
			{
				channel.sendMessage("Sorry i can't found "+name ).queue();
				return;
			}
			
			NavigableEmbed.Builder builder = new NavigableEmbed.Builder(event.getChannel());
			for (int x = 0; x < liste.size(); x++) {
				MagicCard result = liste.get(x);
				BiFunction<MagicCard, Integer, MessageEmbed> getEmbed = (c, resultIndex) -> {
					MessageEmbed embed=parseCard(result);
					EmbedBuilder eb = new EmbedBuilder(embed);
					if (liste.size() > 1)
						eb.setFooter("Result " + (resultIndex + 1) + "/" + liste.size(), null);
					
					return eb.build();
				};
				int finalIndex = x;
				builder.addEmbed(() -> getEmbed.apply(result, finalIndex));
			}
			
			NavigableEmbed navEb = builder.build();
			
			
			if(liste.size()>1)
			{
				applyControl(EmbedButton.PREVIOUS.getIcon(), navEb.getMessage(), navEb.getWidth() > 1);
				applyControl(EmbedButton.NEXT.getIcon(), navEb.getMessage(), navEb.getWidth() > 1);
		
				ReactionListener rl = new ReactionListener(jda, navEb.getMessage(), false, 30L * 1000L);
				rl.addController(event.getAuthor());
				rl.addResponse(EmbedButton.PREVIOUS.getIcon(), ev -> {
					navEb.setY(0);
					if (navEb.getX() > 0) navEb.left();
					applyControl(EmbedButton.PREVIOUS.getIcon(), navEb.getMessage(), navEb.getWidth() > 1);
				});
				rl.addResponse(EmbedButton.NEXT.getIcon(), ev -> {
					navEb.setY(0);
					if (navEb.getX() < navEb.getWidth() - 1) navEb.right();
					applyControl(EmbedButton.NEXT.getIcon(), navEb.getMessage(), navEb.getWidth() > 1);
				});

			}
		}	
		
	
	
}