Java Code Examples for net.dv8tion.jda.api.entities.MessageEmbed#EMBED_MAX_LENGTH_BOT

The following examples show how to use net.dv8tion.jda.api.entities.MessageEmbed#EMBED_MAX_LENGTH_BOT . 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: 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 2
Source File: WarnsCommand.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) {
    LocalMember member = reference.getLocalMember();

    List<MemberWarning> warningList = moderationService.getWarnings(member);
    if (warningList.isEmpty()) {
        messageService.onEmbedMessage(event.getChannel(), "discord.command.mod.warns.empty");
        return false;
    }
    if (warningList.size() > 20) {
        warningList = warningList.subList(0, 20);
    }

    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(messageService.getMessage("discord.command.mod.warns.message.title", member.getEffectiveName()));

    DateTimeFormatter formatter = DateTimeFormat
            .shortDateTime()
            .withZone(context.getTimeZone())
            .withLocale(contextService.getLocale());

    int i = 1;
    int length = builder.length();
    for (MemberWarning warning : warningList) {
        String title = String.format("%2s. %s %s (%s)", i++,
                formatter.print(new DateTime(warning.getDate())),
                CommonUtils.getUTCOffset(context.getTimeZone()),
                warning.getModerator().getEffectiveName());
        StringBuilder detailsBuilder = new StringBuilder();
        if (StringUtils.isNotEmpty(warning.getReason())) {
            detailsBuilder.append(messageService.getMessage("discord.command.mod.warns.reason",
                    warning.getReason()));
        }
        if (warning.getEndDate() != null) {
            if (detailsBuilder.length() > 0) {
                detailsBuilder.append("\n");
            }
            detailsBuilder.append(messageService.getMessage("discord.command.mod.warns.until",
                    formatter.print(new DateTime(warning.getEndDate())),
                    CommonUtils.getUTCOffset(context.getTimeZone())));
        }
        if ((length += title.length() + detailsBuilder.length()) > MessageEmbed.EMBED_MAX_LENGTH_BOT) {
            break;
        }
        builder.addField(title, detailsBuilder.toString(), false);
    }
    messageService.sendMessageSilent(event.getChannel()::sendMessage, builder.build());
    return true;
}
 
Example 3
Source File: EmbedBuilder.java    From JDA with Apache License 2.0 4 votes vote down vote up
/**
 * Checks whether the constructed {@link net.dv8tion.jda.api.entities.MessageEmbed MessageEmbed}
 * is within the limits for the specified {@link net.dv8tion.jda.api.AccountType AccountType}
 * <ul>
 *     <li>Bot: {@value MessageEmbed#EMBED_MAX_LENGTH_BOT}</li>
 *     <li>Client: {@value MessageEmbed#EMBED_MAX_LENGTH_CLIENT}</li>
 * </ul>
 *
 * @param  type
 *         The {@link net.dv8tion.jda.api.AccountType AccountType} to validate
 *
 * @throws java.lang.IllegalArgumentException
 *         If provided with {@code null}
 *
 * @return True, if the {@link #length() length} is less or equal to the specific limit
 *
 * @deprecated Replace with {@link #isValidLength()}
 */
@Deprecated
@ForRemoval
@DeprecatedSince("4.2.0")
public boolean isValidLength(@Nonnull AccountType type)
{
    Checks.notNull(type, "AccountType");
    final int length = length();
    switch (type)
    {
        case BOT:
            return length <= MessageEmbed.EMBED_MAX_LENGTH_BOT;
        case CLIENT:
        default:
            return length <= MessageEmbed.EMBED_MAX_LENGTH_CLIENT;
    }
}
 
Example 4
Source File: EmbedBuilder.java    From JDA with Apache License 2.0 2 votes vote down vote up
/**
 * Checks whether the constructed {@link net.dv8tion.jda.api.entities.MessageEmbed MessageEmbed}
 * is within the limits for a bot account.
 *
 * @return True, if the {@link #length() length} is less or equal to the specific limit
 *
 * @see    MessageEmbed#EMBED_MAX_LENGTH_BOT
 */
public boolean isValidLength()
{
    final int length = length();
    return length <= MessageEmbed.EMBED_MAX_LENGTH_BOT;
}