Search in sources :

Example 26 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project MantaroBot by Mantaro.

the class Poll method createPoll.

private void createPoll(Context ctx, Message message, I18nContext languageContext) {
    runningPoll = ReactionOperations.create(message, TimeUnit.MILLISECONDS.toSeconds(timeout), new ReactionOperation() {

        @Override
        public int add(MessageReactionAddEvent e) {
            // always return false anyway lul
            return Operation.IGNORED;
        }

        @Override
        public void onExpire() {
            if (getChannel() == null)
                return;
            var user = ctx.getAuthor();
            var embedBuilder = new EmbedBuilder().setTitle(languageContext.get("commands.poll.result_header")).setDescription(String.format(languageContext.get("commands.poll.result_screen"), user.getName(), name)).setFooter(languageContext.get("commands.poll.thank_note"), null);
            var react = new AtomicInteger(0);
            var counter = new AtomicInteger(0);
            getChannel().retrieveMessageById(message.getIdLong()).queue(message -> {
                var votes = message.getReactions().stream().filter(r -> react.getAndIncrement() <= options.length).map(r -> String.format(languageContext.get("commands.poll.vote_results"), r.getCount() - 1, options[counter.getAndIncrement()])).collect(Collectors.joining("\n"));
                embedBuilder.addField(languageContext.get("commands.poll.results"), "```diff\n" + votes + "```", false);
                getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
            });
            getRunningPolls().remove(getChannel().getId());
        }

        @Override
        public void onCancel() {
            getChannel().sendMessageFormat(languageContext.get("commands.poll.cancelled"), EmoteReference.CORRECT).queue();
            onExpire();
        }
    }, reactions(options.length));
}
Also used : ReactionOperation(net.kodehawa.mantarobot.core.listeners.operations.core.ReactionOperation) Message(net.dv8tion.jda.api.entities.Message) Color(java.awt.Color) InteractiveOperations(net.kodehawa.mantarobot.core.listeners.operations.InteractiveOperations) Permission(net.dv8tion.jda.api.Permission) Utils(net.kodehawa.mantarobot.utils.Utils) HashMap(java.util.HashMap) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) TextChannel(net.dv8tion.jda.api.entities.TextChannel) MessageReactionAddEvent(net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent) Collectors(java.util.stream.Collectors) ReactionOperations(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperations) Lobby(net.kodehawa.mantarobot.commands.interaction.Lobby) TimeUnit(java.util.concurrent.TimeUnit) Future(java.util.concurrent.Future) Stream(java.util.stream.Stream) I18nContext(net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) Map(java.util.Map) MantaroData(net.kodehawa.mantarobot.data.MantaroData) ReactionOperation(net.kodehawa.mantarobot.core.listeners.operations.core.ReactionOperation) Context(net.kodehawa.mantarobot.core.modules.commands.base.Context) Operation(net.kodehawa.mantarobot.core.listeners.operations.core.Operation) MessageReactionAddEvent(net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 27 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project MantaroBot by Mantaro.

the class EmbedJSON method gen.

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();
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Color(java.awt.Color)

Example 28 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.

the class GuildMemberLeaveListener method onGuildMemberRemove.

@Override
public void onGuildMemberRemove(GuildMemberRemoveEvent event) {
    event.getGuild().getTextChannelsByName("log", true).forEach(channel -> {
        final EmbedBuilder embedBuilder = DiscordUtils.getDefaultEmbed(event.getMember());
        embedBuilder.appendDescription(event.getMember().getEffectiveName() + " hat c0debase verlassen");
        channel.sendMessage(embedBuilder.build()).queue();
    });
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder)

Example 29 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.

the class MessageReceiveListener method checkMemeMessage.

/**
 * @param message
 * @return if the message has been deleted
 */
private boolean checkMemeMessage(final Message message) {
    if (!message.getTextChannel().getName().contains("meme")) {
        return false;
    }
    if (message.getTextChannel().getTopic() == null || !message.getTextChannel().getTopic().contains("test")) {
        return false;
    }
    final boolean containsURL = StringUtils.containtsURL(message.getContentStripped());
    final boolean containsAttachment = !message.getAttachments().isEmpty();
    if (!containsURL && !containsAttachment) {
        message.delete().queue(success -> {
            final MessageEmbed messageEmbed = new EmbedBuilder().setDescription("Deine Nachricht wurde gelöscht da sie kein Bild/Video oder Link enthält.").setColor(message.getGuild().getSelfMember().getColor()).build();
            message.getChannel().sendMessage(messageEmbed).delay(Duration.ofSeconds(10)).flatMap(Message::delete).queue();
        });
        return true;
    }
    return false;
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed)

Example 30 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.

the class MessageReceiveListener method updateXP.

private void updateXP(final Message message) {
    final User user = bot.getDatabase().getUserDao().getOrCreateUser(message.getGuild().getId(), message.getAuthor().getId());
    final float time = (System.currentTimeMillis() - user.getLastMessage()) / 1000;
    if (time >= 50.0f) {
        if (user.addXP(50)) {
            final EmbedBuilder levelUpEmbed = DiscordUtils.getDefaultEmbed(message.getMember());
            final int newLevel = user.getLevel();
            levelUpEmbed.appendDescription(message.getAuthor().getAsMention() + " ist nun Level " + newLevel);
            if (message.getIdLong() != DISCUSSION_CHANNEL_ID) {
                levelUpEmbed.setImage(gifs.get(Constants.RANDOM.nextInt(gifs.size())));
            }
            message.getTextChannel().sendMessage(levelUpEmbed.build()).queue();
            if (newLevel > 2 && !message.getMember().getRoles().contains(message.getJDA().getRoleById(PROJECT_ROLE_ID))) {
                message.getGuild().addRoleToMember(message.getMember(), message.getJDA().getRoleById(PROJECT_ROLE_ID)).queue();
            }
        }
        user.setLastMessage(System.currentTimeMillis());
        bot.getDatabase().getUserDao().updateUser(user);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) User(de.c0debase.bot.database.model.User)

Aggregations

EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)47 Member (net.dv8tion.jda.api.entities.Member)8 TimeUnit (java.util.concurrent.TimeUnit)7 Collectors (java.util.stream.Collectors)7 Message (net.dv8tion.jda.api.entities.Message)7 Context (net.kodehawa.mantarobot.core.modules.commands.base.Context)7 MantaroData (net.kodehawa.mantarobot.data.MantaroData)7 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)7 Color (java.awt.Color)6 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)6 MessageEmbed (net.dv8tion.jda.api.entities.MessageEmbed)6 Utils (net.kodehawa.mantarobot.utils.Utils)6 Subscribe (com.google.common.eventbus.Subscribe)5 List (java.util.List)5 Role (net.dv8tion.jda.api.entities.Role)5 CommandCategory (net.kodehawa.mantarobot.core.modules.commands.base.CommandCategory)5 HelpContent (net.kodehawa.mantarobot.core.modules.commands.help.HelpContent)5 I18nContext (net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext)5 LinkedList (java.util.LinkedList)4 Permission (net.dv8tion.jda.api.Permission)4