Search in sources :

Example 6 with MessageReaction

use of net.dv8tion.jda.api.entities.MessageReaction in project cds by iamysko.

the class ReactionListener method onMessageReactionAdd.

/**
 * On message reaction add.
 *
 * @param event the event
 */
@Override
public void onMessageReactionAdd(final MessageReactionAddEvent event) {
    final TextChannel commandChannel = event.getGuild().getTextChannelById(Properties.CHANNEL_COMMANDS_ID);
    final MessageReaction reaction = event.getReaction();
    final Member reactee = event.getMember();
    final MessageChannel channel = event.getTextChannel();
    final ReactionEmote emote = reaction.getReactionEmote();
    final String emoteId = emote.isEmote() ? emote.getId() : "";
    if (!emoteId.equals(ID_REACTION_ALERT_MODS) && !RoleUtils.isAnyRole(reactee, RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_SENIOR_MODERATOR, RoleUtils.ROLE_TRIAL_MODERATOR, RoleUtils.ROLE_BOT)) {
        // Do nothing.
        return;
    }
    event.retrieveMessage().queue(message -> {
        final String messageLink = message.getJumpUrl();
        message.getJDA().getGuildById(message.getGuild().getIdLong()).retrieveMemberById(message.getAuthor().getId()).queue(messageAuthor -> {
            if (emoteId.equals(ID_REACTION_ALERT_MODS)) {
                if (existingAlertsMap.get(message.getIdLong()) == null) {
                    alertMods(event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
                }
            }
            if (!RoleUtils.isAnyRole(reactee, RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_SENIOR_MODERATOR, RoleUtils.ROLE_TRIAL_MODERATOR, RoleUtils.ROLE_BOT)) {
                // Do nothing.
                return;
            }
            final Action commandAction = new Action();
            commandAction.setDate(Instant.now());
            commandAction.setUser(reactee.getUser().getAsTag());
            commandAction.setDiscordId(reactee.getIdLong());
            switch(emoteId) {
                case ID_REACTION_PURGE_MESSAGES:
                    if (!isStaffOnStaff(reactee, messageAuthor, commandChannel) && !isInStaffChannel(reactee, commandChannel, event.getChannel()) && RoleUtils.isAnyRole(event.getMember(), RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_TRIAL_MODERATOR, RoleUtils.ROLE_BOT)) {
                        purgeMessagesInChannel(messageAuthor, channel);
                        commandAction.setOffendingUser(messageAuthor.getUser().getAsTag());
                        commandAction.setOffendingUserId(messageAuthor.getIdLong());
                        commandAction.setActionType("REACTION_PURGE_MESSAGES");
                        log.info("[Reaction Command] Message purge executed by {} on {}", reactee.getUser().getAsTag(), messageAuthor.getUser().getAsTag());
                    }
                    break;
                case ID_REACTION_QM_30:
                    if (reactee.getIdLong() != messageAuthor.getIdLong()) {
                        if (RoleUtils.isAnyRole(reactee, RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_BOT)) {
                            if (event.getChannel().getIdLong() == Properties.CHANNEL_CENSORED_AND_SPAM_LOGS_ID || event.getChannel().getIdLong() == Properties.CHANNEL_MESSAGE_LOGS_ID) {
                                quickMuteFromLogs(reactee, message, commandChannel, "30m");
                                log.info("[Reaction Command] 30m Quick-Mute executed by {} ({}) (message: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                            } else if (event.getChannel().getIdLong() != Properties.CHANNEL_MOD_ALERTS_ID) {
                                if (!isStaffOnStaff(reactee, messageAuthor, commandChannel)) {
                                    muteUser(reactee, messageAuthor, "30m", message, commandChannel);
                                    purgeMessagesInChannel(messageAuthor, channel);
                                    commandAction.setOffendingUser(messageAuthor.getUser().getAsTag());
                                    commandAction.setOffendingUserId(messageAuthor.getIdLong());
                                    commandAction.setActionType("REACTION_QM_30");
                                    log.info("[Reaction Command] 30m Quick-Mute executed by {} on {}", reactee.getUser().getAsTag(), messageAuthor.getUser().getAsTag());
                                    deleteModAlert(messageLink, event);
                                }
                            } else {
                                final String rawMessage = message.getContentRaw();
                                final String channelId = rawMessage.split("/")[5];
                                final String messageId = rawMessage.split("/")[6];
                                final String authorId = rawMessage.split("`")[3];
                                event.getGuild().getTextChannelById(channelId).retrieveMessageById(messageId).queue(alertmessage -> {
                                    event.getGuild().retrieveMemberById(authorId).queue((author) -> {
                                        if (!isStaffOnStaff(reactee, author, commandChannel)) {
                                            muteUser(reactee, author, "30m", alertmessage, commandChannel);
                                            purgeMessagesInChannel(author, event.getGuild().getTextChannelById(channelId));
                                        }
                                    });
                                }, alertfailure -> {
                                    commandChannel.sendMessage(new StringBuilder().append(reactee.getAsMention()).append(" the message does not exist or action has already been taken.")).queue();
                                });
                                if (reactee.getIdLong() != messageAuthor.getIdLong()) {
                                    clearAlert(commandChannel, event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
                                    commandAction.setActionType("REACTION_ALERT_DONE");
                                    log.info("[Reaction Command] Mod alert marked done by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                                }
                            }
                        }
                    }
                    break;
                case ID_REACTION_QM_60:
                    if (reactee.getIdLong() != messageAuthor.getIdLong()) {
                        if (RoleUtils.isAnyRole(reactee, RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_BOT)) {
                            if (event.getChannel().getIdLong() == Properties.CHANNEL_CENSORED_AND_SPAM_LOGS_ID || event.getChannel().getIdLong() == Properties.CHANNEL_MESSAGE_LOGS_ID) {
                                quickMuteFromLogs(reactee, message, commandChannel, "1h");
                                log.info("[Reaction Command] 1h Quick-Mute executed by {} ({}) (message: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                            } else if (event.getChannel().getIdLong() != Properties.CHANNEL_MOD_ALERTS_ID) {
                                if (!isStaffOnStaff(reactee, messageAuthor, commandChannel)) {
                                    muteUser(reactee, messageAuthor, "1h", message, commandChannel);
                                    purgeMessagesInChannel(messageAuthor, channel);
                                    commandAction.setOffendingUser(messageAuthor.getUser().getAsTag());
                                    commandAction.setOffendingUserId(messageAuthor.getIdLong());
                                    commandAction.setActionType("REACTION_QM_60");
                                    log.info("[Reaction Command] 1h Quick-Mute executed by {} on {}", reactee.getUser().getAsTag(), messageAuthor.getUser().getAsTag());
                                    deleteModAlert(messageLink, event);
                                }
                            } else {
                                final String rawMessage = message.getContentRaw();
                                final String channelId = rawMessage.split("/")[5];
                                final String messageId = rawMessage.split("/")[6];
                                final String authorId = rawMessage.split("`")[3];
                                event.getGuild().getTextChannelById(channelId).retrieveMessageById(messageId).queue(alertmessage -> {
                                    event.getGuild().retrieveMemberById(authorId).queue((author) -> {
                                        if (!isStaffOnStaff(reactee, author, commandChannel)) {
                                            muteUser(reactee, author, "60m", alertmessage, commandChannel);
                                            purgeMessagesInChannel(author, event.getGuild().getTextChannelById(channelId));
                                        }
                                    });
                                }, alertfailure -> {
                                    commandChannel.sendMessage(new StringBuilder().append(reactee.getAsMention()).append(" the message does not exist or action has already been taken.")).queue();
                                });
                                if (reactee.getIdLong() != messageAuthor.getIdLong()) {
                                    clearAlert(commandChannel, event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
                                    commandAction.setActionType("REACTION_ALERT_DONE");
                                    log.info("[Reaction Command] Mod alert marked done by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                                }
                            }
                        }
                    }
                    break;
                case // Used for ban requests, filtered log bans, and mod alerts.
                ID_REACTION_APPROVE:
                    if (RoleUtils.isAnyRole(event.getMember(), RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_SENIOR_MODERATOR)) {
                        if (event.getChannel().getIdLong() == Properties.CHANNEL_MOD_ALERTS_ID) {
                            if (reactee.getIdLong() != messageAuthor.getIdLong()) {
                                clearAlert(commandChannel, event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
                                commandAction.setActionType("REACTION_ALERT_DONE");
                                log.info("[Reaction Command] Mod alert marked done by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                            }
                        }
                        if (event.getChannel().getIdLong() == Properties.CHANNEL_BAN_REQUESTS_QUEUE_ID) {
                            approveBanRequest(reactee, message, commandChannel);
                            commandAction.setActionType("REACTION_APPROVE_BAN_REQUEST");
                            log.info("[Reaction Command] Ban request approved by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                        } else if (event.getChannel().getIdLong() == Properties.CHANNEL_CENSORED_AND_SPAM_LOGS_ID || event.getChannel().getIdLong() == Properties.CHANNEL_MESSAGE_LOGS_ID) {
                            approveLogsBan(reactee, message, commandChannel);
                            commandAction.setActionType("REACTION_APPROVE_BAN_REQUEST");
                            log.info("[Reaction Command] Logs message ban approved by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                        }
                    } else if (RoleUtils.isAnyRole(event.getMember(), RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_TRIAL_MODERATOR)) {
                        if (event.getChannel().getIdLong() == Properties.CHANNEL_MOD_ALERTS_ID) {
                            clearAlert(commandChannel, event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
                            commandAction.setActionType("REACTION_ALERT_DONE");
                            log.info("[Reaction Command] Mod alert marked done by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                        }
                    }
                    break;
                case ID_REACTION_REJECT:
                    if (event.getChannel().getIdLong() == Properties.CHANNEL_BAN_REQUESTS_QUEUE_ID && RoleUtils.isAnyRole(event.getMember(), RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_SENIOR_MODERATOR)) {
                        rejectBanRequest(reactee, message, commandChannel);
                        commandAction.setActionType("REACTION_REJECT_BAN_REQUEST");
                        log.info("[Reaction Command] Ban request rejected by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
                    }
                    break;
                default:
                    // Do nothing.
                    return;
            }
            cdsData.insertAction(commandAction);
        });
    }, (failure) -> {
        log.error("An error occurred obtaining a reaction event's message. Details: {}", failure.getMessage());
    });
}
Also used : ReactionEmote(net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote) Action(com.misterveiga.cds.entities.Action) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) RoleUtils(com.misterveiga.cds.utils.RoleUtils) Properties(com.misterveiga.cds.utils.Properties) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PropertySource(org.springframework.context.annotation.PropertySource) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) User(net.dv8tion.jda.api.entities.User) Message(net.dv8tion.jda.api.entities.Message) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) Instant(java.time.Instant) MessageReactionAddEvent(net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Component(org.springframework.stereotype.Component) ChronoUnit(java.time.temporal.ChronoUnit) CdsDataImpl(com.misterveiga.cds.data.CdsDataImpl) MentionType(net.dv8tion.jda.api.entities.Message.MentionType) MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Action(com.misterveiga.cds.entities.Action) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) Member(net.dv8tion.jda.api.entities.Member) ReactionEmote(net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote)

Example 7 with MessageReaction

use of net.dv8tion.jda.api.entities.MessageReaction in project JDA by DV8FromTheWorld.

the class MessageReactionClearEmoteHandler method handleInternally.

@Override
protected Long handleInternally(DataObject content) {
    long guildId = content.getUnsignedLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(guildId))
        return guildId;
    Guild guild = getJDA().getGuildById(guildId);
    if (guild == null) {
        EventCache.LOG.debug("Caching MESSAGE_REACTION_REMOVE_EMOJI event for unknown guild {}", guildId);
        getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
        return null;
    }
    long channelId = content.getUnsignedLong("channel_id");
    // TODO-v5-unified-channel-cache
    GuildMessageChannel channel = guild.getTextChannelById(channelId);
    if (channel == null)
        channel = guild.getNewsChannelById(channelId);
    if (channel == null)
        channel = guild.getThreadChannelById(channelId);
    if (channel == null) {
        EventCache.LOG.debug("Caching MESSAGE_REACTION_REMOVE_EMOJI event for unknown channel {}", channelId);
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        return null;
    }
    long messageId = content.getUnsignedLong("message_id");
    DataObject emoji = content.getObject("emoji");
    MessageReaction.ReactionEmote reactionEmote = null;
    if (emoji.isNull("id")) {
        reactionEmote = MessageReaction.ReactionEmote.fromUnicode(emoji.getString("name"), getJDA());
    } else {
        long emoteId = emoji.getUnsignedLong("id");
        Emote emote = getJDA().getEmoteById(emoteId);
        if (emote == null) {
            emote = new EmoteImpl(emoteId, getJDA()).setAnimated(emoji.getBoolean("animated")).setName(emoji.getString("name", ""));
        }
        reactionEmote = MessageReaction.ReactionEmote.fromCustom(emote);
    }
    MessageReaction reaction = new MessageReaction(channel, reactionEmote, messageId, false, 0);
    getJDA().handleEvent(new MessageReactionRemoveEmoteEvent(getJDA(), responseNumber, messageId, channel, reaction));
    return null;
}
Also used : MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) EmoteImpl(net.dv8tion.jda.internal.entities.EmoteImpl) MessageReactionRemoveEmoteEvent(net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEmoteEvent) DataObject(net.dv8tion.jda.api.utils.data.DataObject) Emote(net.dv8tion.jda.api.entities.Emote) Guild(net.dv8tion.jda.api.entities.Guild) GuildMessageChannel(net.dv8tion.jda.api.entities.GuildMessageChannel)

Example 8 with MessageReaction

use of net.dv8tion.jda.api.entities.MessageReaction in project Sx4 by sx4-discord-bot.

the class GiveawayManager method endGiveawayBulk.

public CompletableFuture<UpdateOneModel<Document>> endGiveawayBulk(Document data, boolean forced) {
    long guildId = data.getLong("guildId"), messageId = data.get("messageId", 0L);
    Guild guild = this.bot.getShardManager().getGuildById(guildId);
    if (guild == null) {
        return CompletableFuture.completedFuture(null);
    }
    TextChannel channel = guild.getTextChannelById(data.getLong("channelId"));
    if (channel == null) {
        return CompletableFuture.completedFuture(null);
    }
    if (!guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_READ, Permission.MESSAGE_HISTORY, Permission.MESSAGE_EMBED_LINKS)) {
        return CompletableFuture.completedFuture(null);
    }
    CompletableFuture<UpdateOneModel<Document>> future = new CompletableFuture<>();
    channel.retrieveMessageById(messageId).queue(message -> {
        MessageReaction reaction = message.getReactions().stream().filter(r -> r.getReactionEmote().getName().equals("🎉")).findFirst().orElse(null);
        if (reaction == null) {
            future.complete(null);
            return;
        }
        List<Long> oldWinners = data.getList("winners", Long.class, Collections.emptyList());
        List<Member> members = new ArrayList<>();
        reaction.retrieveUsers().forEachAsync(user -> {
            Member member = guild.getMember(user);
            if (member != null && member.getIdLong() != guild.getSelfMember().getIdLong() && !oldWinners.contains(member.getIdLong())) {
                members.add(member);
            }
            return true;
        }).thenRun(() -> {
            Bson update;
            if (members.size() == 0) {
                update = Updates.set("winners", Collections.EMPTY_LIST);
                future.complete(new UpdateOneModel<>(Filters.eq("messageId", messageId), forced ? Updates.combine(Updates.set("endAt", Clock.systemUTC().instant().getEpochSecond()), update) : update));
                channel.sendMessage("At least " + (oldWinners.isEmpty() ? "1 person needs" : oldWinners.size() == 1 ? "1 extra person needs" : oldWinners.size() + " extra people need") + " to have entered the giveaway to pick a winner " + this.bot.getConfig().getFailureEmote()).queue();
                return;
            }
            Set<Member> winners = MathUtility.randomSample(members, Math.min(data.getInteger("winnersAmount"), members.size()));
            List<Long> winnerIds = new ArrayList<>();
            List<String> winnerTags = new ArrayList<>(), winnerMentions = new ArrayList<>();
            for (Member winner : winners) {
                winnerIds.add(winner.getIdLong());
                winnerTags.add(winner.getUser().getAsTag());
                winnerMentions.add(winner.getAsMention());
            }
            if (guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE)) {
                channel.sendMessage(String.join(", ", winnerMentions) + ", Congratulations you have won the giveaway for **" + data.getString("item") + "**").allowedMentions(EnumSet.of(MentionType.USER)).queue();
            }
            EmbedBuilder embed = new EmbedBuilder();
            embed.setTitle("Giveaway");
            embed.setDescription("**" + String.join(", ", winnerTags) + "** has won **" + data.getString("item") + "**");
            embed.setTimestamp(Instant.now());
            embed.setFooter("Giveaway Ended", null);
            if (guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE, Permission.MESSAGE_EMBED_LINKS)) {
                message.editMessageEmbeds(embed.build()).queue();
            }
            update = Updates.set("winners", winnerIds);
            future.complete(new UpdateOneModel<>(Filters.eq("messageId", messageId), forced ? Updates.combine(Updates.set("endAt", Clock.systemUTC().instant().getEpochSecond()), update) : update));
        });
    });
    this.deleteExecutor(messageId);
    return future;
}
Also used : Document(org.bson.Document) java.util(java.util) UpdateOneModel(com.mongodb.client.model.UpdateOneModel) java.util.concurrent(java.util.concurrent) Permission(net.dv8tion.jda.api.Permission) MongoDatabase(com.sx4.bot.database.mongo.MongoDatabase) Updates(com.mongodb.client.model.Updates) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Instant(java.time.Instant) Filters(com.mongodb.client.model.Filters) Bson(org.bson.conversions.Bson) Guild(net.dv8tion.jda.api.entities.Guild) Sx4(com.sx4.bot.core.Sx4) MentionType(net.dv8tion.jda.api.entities.Message.MentionType) MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) Clock(java.time.Clock) FutureUtility(com.sx4.bot.utility.FutureUtility) MathUtility(com.sx4.bot.utility.MathUtility) Guild(net.dv8tion.jda.api.entities.Guild) Bson(org.bson.conversions.Bson) MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) TextChannel(net.dv8tion.jda.api.entities.TextChannel) UpdateOneModel(com.mongodb.client.model.UpdateOneModel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Member(net.dv8tion.jda.api.entities.Member)

Example 9 with MessageReaction

use of net.dv8tion.jda.api.entities.MessageReaction in project Minecord by Tisawesomeness.

the class ReactListener method removeEmote.

/**
 * Removes an emote, keeping stars for starboard purposes
 * @param e The event received from a message reaction
 */
private void removeEmote(MessageReactionAddEvent e) {
    if (!e.isFromGuild() || !hasManageMessagePerms(e)) {
        return;
    }
    MessageReaction r = e.getReaction();
    if (!isRemovableEmoji(r.getReactionEmote())) {
        return;
    }
    User u = e.getUser();
    if (u != null) {
        r.removeReaction(u).queue();
    }
}
Also used : MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) User(net.dv8tion.jda.api.entities.User)

Example 10 with MessageReaction

use of net.dv8tion.jda.api.entities.MessageReaction in project LemBot by Leminee.

the class ReactionManager method registerReaction.

/**
 * Registriert eine neue ReactionMessage
 *
 * @param channelId Die Discord Textchannel ID, in welcher die Nachricht sich befindet
 * @param messageId Die Discord Message ID, auf die reagiert werden soll
 * @param emoji     Das Emoji als Codepoints ODER die Emote ID, nach dem gefiltert werden soll
 * @param roleId    Die Discord Role ID, die vergeben werden soll, wenn man auf die Nachricht reagiert
 * @return Diesen ReactionManager für Chain Calls
 */
public ReactionManager registerReaction(String channelId, String messageId, String emoji, String roleId) {
    try {
        jda.awaitReady();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ReactionMessage m = new ReactionMessage(channelId, messageId, emoji, roleId);
    Guild g = jda.getTextChannelById(channelId).getGuild();
    if (!reactionMessages.stream().anyMatch(m::equals))
        reactionMessages.add(m);
    jda.getTextChannelById(channelId).retrieveMessageById(messageId).queue(message -> {
        Optional<MessageReaction> optional;
        if (Helpers.isNumeric(emoji)) {
            Emote e = g.getEmoteById(emoji);
            message.addReaction(e).queue();
            optional = message.getReactions().stream().filter(r -> r.getReactionEmote().isEmote() && r.getReactionEmote().getEmote().getId().equals(emoji)).findFirst();
        } else {
            jda.getTextChannelById(channelId).addReactionById(messageId, emoji).queue();
            optional = message.getReactions().stream().filter(r -> r.getReactionEmote().isEmoji() && r.getReactionEmote().getEmoji().equals(emoji)).findFirst();
        }
        optional.ifPresent(r -> r.retrieveUsers().queue(l -> l.forEach(u -> g.addRoleToMember(u.getId(), g.getRoleById(roleId)))));
    });
    return this;
}
Also used : MessageReactionRemoveEvent(net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent) JDA(net.dv8tion.jda.api.JDA) Helpers(net.dv8tion.jda.internal.utils.Helpers) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) MessageReactionAddEvent(net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Guild(net.dv8tion.jda.api.entities.Guild) GenericMessageReactionEvent(net.dv8tion.jda.api.events.message.react.GenericMessageReactionEvent) MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) Emote(net.dv8tion.jda.api.entities.Emote) MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) Emote(net.dv8tion.jda.api.entities.Emote) Guild(net.dv8tion.jda.api.entities.Guild)

Aggregations

MessageReaction (net.dv8tion.jda.api.entities.MessageReaction)11 ArrayList (java.util.ArrayList)5 Instant (java.time.Instant)4 Member (net.dv8tion.jda.api.entities.Member)4 Message (net.dv8tion.jda.api.entities.Message)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)3 Emote (net.dv8tion.jda.api.entities.Emote)3 Guild (net.dv8tion.jda.api.entities.Guild)3 User (net.dv8tion.jda.api.entities.User)3 MessageReactionAddEvent (net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent)3 ChronoUnit (java.time.temporal.ChronoUnit)2 java.util (java.util)2 Objects (java.util.Objects)2 TimeUnit (java.util.concurrent.TimeUnit)2 JDA (net.dv8tion.jda.api.JDA)2 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)2 Permission (net.dv8tion.jda.api.Permission)2 GuildMessageReactionAddEvent (net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent)2