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

The following examples show how to use net.dv8tion.jda.api.EmbedBuilder#setColor() . 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 vote down vote up
@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: GroovyCommand.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) {
    if (!enabled || !discordService.isSuperUser(message.getAuthor()) || StringUtils.isEmpty(query)) {
        return false;
    }
    message.getChannel().sendTyping().queue();
    String script = CommonUtils.unwrapCode(query);
    try {
        Object result = getShell(message).evaluate(script);
        if (result != null) {
            messageService.sendMessageSilent(message.getChannel()::sendMessage,
                    "```groovy\n" + String.valueOf(result) + "```");
        }
    } catch (Exception e) {
        String errorText = String.format("\n`%s`\n\nStack trace:```javascript\n%s", e.getMessage(), ExceptionUtils.getStackTrace(e));
        EmbedBuilder builder = messageService.getBaseEmbed();
        builder.setTitle(e.getClass().getName());
        builder.setColor(Color.RED);
        builder.setDescription(CommonUtils.trimTo(errorText, 2045) + "```");
        messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
        return fail(message);
    }
    return ok(message);
}
 
Example 3
Source File: EmergencyServiceImpl.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void error(String message, Throwable throwable) {
    Long emergencyChannelId = workerProperties.getSupport().getEmergencyChannelId();
    if (emergencyChannelId == null || !discordService.isConnected(workerProperties.getSupport().getGuildId())) {
        return;
    }
    TextChannel channel = discordService.getShardManager().getTextChannelById(emergencyChannelId);
    if (channel == null) {
        return;
    }

    String errorText = String.format("`%s`\n\nStack trace:```javascript\n%s", throwable.getMessage(), ExceptionUtils.getStackTrace(throwable));
    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(message);
    builder.setColor(Color.RED);
    builder.setDescription(CommonUtils.trimTo(errorText, 2045) + "```");

    MessageBuilder messageBuilder = new MessageBuilder();
    messageBuilder.setContent("@here");
    messageBuilder.setEmbed(builder.build());
    messageService.sendMessageSilent(channel::sendMessage, messageBuilder.build());
}
 
Example 4
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 5
Source File: AudioMessageManager.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
public void onQueueError(MessageChannel sourceChannel, String code, Object... args) {
    EmbedBuilder builder = getQueueMessage();
    builder.setColor(Color.RED);
    builder.setDescription(messageService.getMessage(code, args));
    messageService.sendMessageSilent(sourceChannel::sendMessage, builder.build());
}
 
Example 6
Source File: AudioMessageManager.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
public void onEmptyQueue(MessageChannel sourceChannel) {
    EmbedBuilder builder = getQueueMessage();
    builder.setColor(Color.RED);
    builder.setDescription(messageService.getMessage("discord.command.audio.queue.empty"));
    messageService.sendMessageSilent(sourceChannel::sendMessage, builder.build());
}
 
Example 7
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;
}