net.dv8tion.jda.api.entities.MessageEmbed Java Examples

The following examples show how to use net.dv8tion.jda.api.entities.MessageEmbed. 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: EmbedBuilder.java    From JDA with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the Title of the embed.
 * <br>You can provide {@code null} as url if no url should be used.
 *
 * <p><b><a href="https://raw.githubusercontent.com/DV8FromTheWorld/JDA/assets/assets/docs/embeds/04-setTitle.png">Example</a></b>
 *
 * @param  title
 *         the title of the embed
 * @param  url
 *         Makes the title into a hyperlink pointed at this url.
 *
 * @throws java.lang.IllegalArgumentException
 *         <ul>
 *             <li>If the provided {@code title} is an empty String.</li>
 *             <li>If the length of {@code title} is greater than {@link net.dv8tion.jda.api.entities.MessageEmbed#TITLE_MAX_LENGTH}.</li>
 *             <li>If the length of {@code url} is longer than {@link net.dv8tion.jda.api.entities.MessageEmbed#URL_MAX_LENGTH}.</li>
 *             <li>If the provided {@code url} is not a properly formatted http or https url.</li>
 *         </ul>
 *
 * @return the builder after the title has been set
 */
@Nonnull
public EmbedBuilder setTitle(@Nullable String title, @Nullable String url)
{
    if (title == null)
    {
        this.title = null;
        this.url = null;
    }
    else
    {
        Checks.notEmpty(title, "Title");
        Checks.check(title.length() <= MessageEmbed.TITLE_MAX_LENGTH, "Title cannot be longer than %d characters.", MessageEmbed.TITLE_MAX_LENGTH);
        if (Helpers.isBlank(url))
            url = null;
        urlCheck(url);

        this.title = title;
        this.url = url;
    }
    return this;
}
 
Example #2
Source File: EmbedBuilder.java    From JDA with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an EmbedBuilder using fields in an existing embed.
 *
 * @param  embed
 *         the existing embed
 */
public EmbedBuilder(@Nullable 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());
    }
}
 
Example #3
Source File: WikiFurService.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
private MessageEmbed renderArticle(Article article, boolean redirected) {
    if (article == null || StringUtils.isEmpty(article.getRevisionId())) {
        return null;
    }
    EngProcessedPage processedPage = processedPage(article);
    String redirect = lookupRedirect(processedPage);
    if (redirect != null) {
        if (redirected) {
            return null;
        }
        return renderArticle(getArticle(redirect), true);
    }

    EmbedBuilder embedBuilder = messageService.getBaseEmbed();
    embedBuilder.setTitle(article.getTitle(), WIKI_URL + UriUtils.encode(article.getTitle(), "UTF-8"));
    TextConverter converter = new TextConverter(config, embedBuilder);
    return (MessageEmbed) converter.go(processedPage.getPage());
}
 
Example #4
Source File: HelpEmbeds.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
public static MessageEmbed generateCommandEmbed(String prefix, CommandCategory... categories) {
    final EmbedBuilder embed = defaultEmbed()
        .setTitle("Click here for the support server", "https://dunctebot.link/server")
        .setDescription("Use `" + prefix + "help [command]` to get more info about a command\n");

    if (categories == null || categories.length == 0) {
        addAllCategoriesToEmbed(embed);
    } else {
        for (final CommandCategory category : categories) {
            final MessageEmbed.Field generated = getFieldForCategory(category);

            if (generated != null) {
                embed.addField(generated);
            }
        }
    }

    return embed.addField("Support",
        "Support server: [https://dunctebot.link/server](https://dunctebot.link/server)\n" +
            "Support development of this bot: [https://www.patreon.com/DuncteBot](https://www.patreon.com/DuncteBot)", false)
        .build();
}
 
Example #5
Source File: DiscordUtils.java    From MantaroBot with GNU General Public License v3.0 6 votes vote down vote up
public static List<List<MessageEmbed.Field>> divideFields(int max, List<MessageEmbed.Field> fields) {
    List<MessageEmbed.Field> temp = new LinkedList<>();
    List<List<MessageEmbed.Field>> m = new LinkedList<>();

    while (fields.size() > 0) {
        if (temp.size() < max) {
            temp.add(fields.get(0));
            fields.remove(0);
        } else {
            m.add(temp);
            temp = new LinkedList<>();
        }
    }

    if (temp.size() != 0) m.add(temp);

    return m;
}
 
Example #6
Source File: BioCommand.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) {
    LocalMember localMember = entityAccessor.getOrCreate(message.getMember());
    MemberBio bio = bioRepository.findByMember(localMember);
    if (bio == null) {
        bio = new MemberBio();
        bio.setMember(localMember);
    }

    String userCommand = messageService.getMessageByLocale("discord.command.user.key",
            context.getCommandLocale());
    String bioCommand = messageService.getMessageByLocale("discord.command.bio.key",
            context.getCommandLocale());

    if (StringUtils.isEmpty(query)) {
        EmbedBuilder builder = messageService.getBaseEmbed(true);
        if (StringUtils.isNotEmpty(bio.getBio())) {
            builder.appendDescription(bio.getBio()).appendDescription("\n\n--------\n");
        }
        builder.appendDescription(messageService.getMessage("discord.command.bio.info",
                context.getConfig().getPrefix(), bioCommand, userCommand));
        messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
        return true;
    }
    bio.setBio("-".equals(query) ? null : CommonUtils.trimTo(query.trim(), MessageEmbed.TEXT_MAX_LENGTH - 500));
    bioRepository.save(bio);

    String updatedMsg = messageService.getMessage("discord.command.bio.updated",
            context.getConfig().getPrefix(), userCommand);
    return ok(message, updatedMsg);
}
 
Example #7
Source File: SteamCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private MessageEmbed.Field getReleaseDate(SteamAppReleaseDate releaseDate) {
    StringBuilder builder = new StringBuilder();
    if (releaseDate.isComingSoon()) {
        builder.append(messageService.getMessage("discord.command.steam.releaseDate.comingSoon")).append(" ");
    }
    if (StringUtils.isNotEmpty(releaseDate.getDate())) {
        builder.append(releaseDate.getDate());
    }
    return new MessageEmbed.Field(messageService.getMessage("discord.command.steam.releaseDate"),
            builder.toString(), true);
}
 
Example #8
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 #9
Source File: ServerInfoCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
protected MessageEmbed.Field getChannelListField(Guild guild) {
    long total = guild.getTextChannels().size() + guild.getVoiceChannels().size();
    StringBuilder memberBuilder = new StringBuilder();
    if (!guild.getTextChannels().isEmpty()) {
        memberBuilder.append(messageService.getMessage("discord.command.server.channels.text",
                guild.getTextChannels().size())).append("\n");
    }
    if (!guild.getVoiceChannels().isEmpty()) {
        memberBuilder.append(messageService.getMessage("discord.command.server.channels.voice",
                guild.getVoiceChannels().size())).append("\n");
    }
    return new MessageEmbed.Field(messageService.getMessage("discord.command.server.channels", total),
            memberBuilder.toString(), true);
}
 
Example #10
Source File: VkSubscriptionServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private WebhookEmbedBuilder initBuilderIfRequired(CallbackMessage<Wallpost> message, List<WebhookEmbedBuilder> builders, int desiredLength) {
    WebhookEmbedBuilder prevBuilder = CollectionUtils.isNotEmpty(builders) ? builders.get(builders.size() - 1) : null;
    if (prevBuilder == null || getFields(prevBuilder).size() == 25) {
        return initBuilder(message, builders);
    }
    WebhookEmbed embed = prevBuilder.build();
    return getWebhookLength(embed) + desiredLength <= MessageEmbed.EMBED_MAX_LENGTH_BOT
            ? prevBuilder : initBuilder(message, builders);
}
 
Example #11
Source File: HelpEmbeds.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private static MessageEmbed.Field getFieldForCategory(CommandCategory category) {
    if ("unlisted".equalsIgnoreCase(category.name())) {
        return null;
    }

    final Class<?> cls = HelpEmbeds.class;
    final String fieldName = category.name() + "_COMMANDS";
    final String descFieldName = category.name() + "_COMMANDS_DESC";
    try {
        final Field field = cls.getDeclaredField(fieldName);
        final Field descField = cls.getDeclaredField(descFieldName);

        return new MessageEmbed.Field(
            (String) descField.get(cls),
            (String) field.get(cls),
            INLINE
        );
    }
    catch (NoSuchFieldException ignored) {
        return null;
    }
    catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return null;
}
 
Example #12
Source File: VkSubscriptionServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private void setText(VkConnection connection, WebhookEmbedBuilder builder, String text, String url) {
    if (StringUtils.isNotEmpty(text)) {
        if (connection.isShowPostLink()) {
            builder.setTitle(new WebhookEmbed.EmbedTitle(getMessage(connection, "vk.message.open"), url));
        }
        builder.setDescription(trimTo(CommonUtils.parseVkLinks(HtmlUtils.htmlUnescape(text)), MessageEmbed.TEXT_MAX_LENGTH));
    }
}
 
Example #13
Source File: CommandManager.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private void runCustomCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
    final CustomCommand cc = (CustomCommand) cmd;

    if (cc.getGuildId() != event.getGuild().getIdLong()) {
        return;
    }

    try {
        MDC.put("command.custom.message", cc.getMessage());

        final Parser parser = CommandUtils.getParser(new CommandContext(invoke, args, event, variables));

        final String message = parser.parse(cc.getMessage());
        final MessageBuilder messageBuilder = new MessageBuilder();
        final DataObject object = parser.get("embed");

        if (!message.isEmpty()) {
            messageBuilder.setContent("\u200B" + message);
        }

        if (object != null) {
            final JDAImpl jda = (JDAImpl) event.getJDA();
            final MessageEmbed embed = jda.getEntityBuilder().createMessageEmbed(object);

            messageBuilder.setEmbed(embed);
        }

        if (!messageBuilder.isEmpty()) {
            sendMsg(event, messageBuilder.build());
        }


        parser.clear();
    }
    catch (Exception e) {
        sendMsg(event, "Error with parsing custom command: " + e.getMessage());
        Sentry.capture(e);
    }
}
 
Example #14
Source File: TextConverter.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private void append(CharSequence sequence) {
    if (limitCheck) {
        if (endReached) {
            return;
        }
        if (textBuilder.length() + sequence.length() > MessageEmbed.TEXT_MAX_LENGTH) {
            endReached = true;
            if (textBuilder.length() + 3 <= MessageEmbed.TEXT_MAX_LENGTH) {
                textBuilder.append("...");
            }
            return;
        }
    }
    textBuilder.append(sequence);
}
 
Example #15
Source File: HelpCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private void sendHelp(GuildMessageReceivedEvent event, MessageEmbed embed) {
    event.getAuthor()
        .openPrivateChannel()
        .flatMap((pc) -> pc.sendMessage(embed))
        .queue(
            (msg) -> sendMsg(event, event.getAuthor().getAsMention() + " check your DM's"),
            //When sending fails, send to the channel
            (err) -> sendMsg(event, "You can check out my commands here:\nhttps://dunctebot.com/commands")
        );
}
 
Example #16
Source File: BotinfoCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {
    if ("support".equals(ctx.getInvoke())) {
        MessageUtils.sendMsg(ctx, "You can join my support server here: <https://dunctebot.link/server>");
        return;
    }

    final User u = ctx.getJDA().getSelfUser();
    final String duncte = " <@191231307290771456> (duncte123#1245)";

    final MessageEmbed eb = EmbedUtils.defaultEmbed()
        .setDescription("Here is some information about me \uD83D\uDE09")
        .setThumbnail(u.getEffectiveAvatarUrl())
        .addField("About me", "Hello there, my name is DuncteBot and I’m currently being developed by " +
            duncte + ".\n" +
            "If you want to add me to your server you can do that by [clicking here](https://bots.discord.pw/bots/210363111729790977).\n" +
            "\n**[Support server](https://dunctebot.link/server)** \u2022 **[Website](https://dunctebot.com/)** \u2022 " +
            "**[Invite me](https://dunctebot.link/invite)**" +
            " \u2022 **[Twitter](https://twitter.com/DuncteBot)**  \u2022 **[Cheap hosting](https://billing.oxide.host/aff.php?aff=6)**" +
            "\n\u200B", true)
        .addField("Lang & lib info", "**Coded in:** Java (version " + System.getProperty("java.version") +
            ") and Kotlin (version " + KotlinVersion.CURRENT + ")\n\n" +
            "**JDA version:** " + JDAInfo.VERSION + "" +
            "\n**LavaPlayer version:** " + this.lavaplayerVersion + "\n" +
            "**Weeb.java version:** " + WeebInfo.VERSION + "\n\u200B", false)
        .addField("Support", "If you want to help keep the bot up 24/7, please consider " +
            "[becoming a patron](https://www.patreon.com/DuncteBot).", false)
        .build();

    sendEmbed(ctx, eb);
}
 
Example #17
Source File: StatsCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private MessageEmbed.Field getCommonStats(Map<String, Metric> metricMap) {
    String value =
            getGaugeValue(metricMap, DiscordMetricsRegistry.GAUGE_GUILDS) + "\n" +
                    getGaugeValue(metricMap, DiscordMetricsRegistry.GAUGE_USERS) + "\n" +
                    getGaugeValue(metricMap, DiscordMetricsRegistry.GAUGE_TEXT_CHANNELS) + "\n" +
                    getGaugeValue(metricMap, DiscordMetricsRegistry.GAUGE_PING) + "\n" +
                    getGaugeValue(metricMap, "player.activeConnections") + "\n";
    return new MessageEmbed.Field(messageService.getMessage("discord.command.stats.common"), value, true);
}
 
Example #18
Source File: ChangeLogCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {

    if (embedJson == null || embedJson.isEmpty()) {
        fetchLatetstGitHubCommits(ctx.getEvent());
        return;
    }

    final JDAImpl jda = (JDAImpl) ctx.getJDA();

    final MessageEmbed embed = jda.getEntityBuilder().createMessageEmbed(DataObject.fromJson(embedJson));

    sendEmbed(ctx.getEvent(), embed);
}
 
Example #19
Source File: SteamCommand.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private MessageEmbed.Field getPlatforms(SteamAppPlatforms platforms) {
    StringBuilder builder = new StringBuilder();
    if (platforms.isWindows()) {
        builder.append("<:windows:636568315354939392> ");
    }
    if (platforms.isLinux()) {
        builder.append("<:steamos:636568315111800847> ");
    }
    if (platforms.isMac()) {
        builder.append("<:macos:636568314965131267> ");
    }
    return new MessageEmbed.Field(messageService.getMessage("discord.command.steam.platforms"),
            builder.toString(), true);
}
 
Example #20
Source File: ChangeLogCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private void fetchLatetstGitHubCommits(GuildMessageReceivedEvent event) {
    WebUtils.ins.getJSONObject("https://api.github.com/repos/DuncteBot/SkyBot/releases/latest").async(json -> {
        final String body = json.get("body").asText();
        final String version = json.get("tag_name").asText();
        final EmbedBuilder eb = EmbedUtils.defaultEmbed()
            .setTitle("Changelog for DuncteBot v" + version, json.get("html_url").asText());

        for (final String item : body.split("\n")) {
            final String hash = item.substring(0, 7);
            final String text = item.substring(8);

            eb.appendDescription(String.format("[%s](http://g.entered.space/%s)%n", text, hash));
        }

        // fallback if with url is too long
        if (eb.getDescriptionBuilder().length() > MessageEmbed.TEXT_MAX_LENGTH) {
            eb.setDescription(body);
        }

        final MessageEmbed embed = eb.setFooter("Released on", null)
            .setTimestamp(Instant.ofEpochMilli(parseTimeStamp(json.get("published_at").asText())))
            .build();

        embedJson = embed.toData()
            .put("type", "rich")
            .toString();

        sendEmbed(event, embed);
    });
}
 
Example #21
Source File: ModerationAuditForwardProvider.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
protected void addReasonField(AuditAction action, EmbedBuilder embedBuilder) {
    String reason = action.getAttribute(REASON_ATTR, String.class);
    if (StringUtils.isNotEmpty(reason)) {
        embedBuilder.addField(messageService.getMessage("audit.reason"),
                CommonUtils.trimTo(reason, MessageEmbed.TEXT_MAX_LENGTH), true);
    }
}
 
Example #22
Source File: ScriptTextChannel.java    From Arraybot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new script channel.
 * @param environment The command environment.
 * @param underlying The underlying text channel.
 */
public ScriptTextChannel(CommandEnvironment environment, TextChannel underlying) {
    super(underlying);
    this.underlying = underlying;
    this.messenger = new AbstractMessenger(environment, false) {
        @Override
        protected void abstractMessage(String message) throws Exception { underlying.sendMessage(message).queue(); }
        @Override
        protected void abstractEmbed(MessageEmbed embed) throws Exception { underlying.sendMessage(embed).queue(); }
    };
}
 
Example #23
Source File: AbstractMessenger.java    From Arraybot with Apache License 2.0 5 votes vote down vote up
/**
 * Sends an embed to the receiver.
 * @param embed The receiver.
 */
public void message(MessageEmbed embed) {
    if(embed == null
            || isLimited()) {
        return;
    }
    try {
        abstractEmbed(embed);
    } catch(Exception exception) {
        UScript.error(environment, exception);
    }
}
 
Example #24
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 #25
Source File: DiscordUtils.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static <T> Pair<String, Integer> embedList(List<T> list, Function<T, String> toString) {
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < list.size(); i++) {
        String s = toString.apply(list.get(i));
        if (b.length() + s.length() + 5 > MessageEmbed.TEXT_MAX_LENGTH) return Pair.of(b.toString(), i);
        b.append("**").append(i + 1).append(".** ");
        b.append(s);
        b.append("\n");
    }

    return Pair.of(b.toString(), list.size());
}
 
Example #26
Source File: DiscordUtils.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
private static EmbedBuilder addAllFields(EmbedBuilder builder, List<MessageEmbed.Field> fields) {
    builder.clearFields();
    for (MessageEmbed.Field f : fields) {
        builder.addField(f);
    }

    return builder;
}
 
Example #27
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
NavigableEmbed( List<List<Supplier<MessageEmbed>>> embeds,  MessageChannel channel) {
	this.embeds = new ArrayList<>();
	this.embeds.addAll(embeds);
	this.channel = channel;
	xindex = 0;
	yindex = 0;
	sendMessage();
}
 
Example #28
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public Builder addEmbed( Supplier<MessageEmbed> embedSupplier) {
	
	ArrayList<Supplier<MessageEmbed>> list = new ArrayList<>();
	list.add(embedSupplier);
	embeds.add(list);
	return this;
}
 
Example #29
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public Builder addEmbed(Supplier<MessageEmbed> embedSupplier, int xIndex) {
	if (xIndex >= embeds.size())
		throw new IllegalArgumentException("xIndex is not within current bounds of the navigatable embed. " + xIndex + " >= " + embeds.size());
	List<Supplier<MessageEmbed>> xList = embeds.get(xIndex);
	xList.add(embedSupplier);
	return this;
}
 
Example #30
Source File: EmbedBuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void urlCheck(@Nullable String url)
{
    if (url != null)
    {
        Checks.check(url.length() <= MessageEmbed.URL_MAX_LENGTH, "URL cannot be longer than %d characters.", MessageEmbed.URL_MAX_LENGTH);
        Checks.check(URL_PATTERN.matcher(url).matches(), "URL must be a valid http(s) or attachment url.");
    }
}