Search in sources :

Example 1 with Action

use of com.misterveiga.cds.entities.Action 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)

Aggregations

CdsDataImpl (com.misterveiga.cds.data.CdsDataImpl)1 Action (com.misterveiga.cds.entities.Action)1 Properties (com.misterveiga.cds.utils.Properties)1 RoleUtils (com.misterveiga.cds.utils.RoleUtils)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Member (net.dv8tion.jda.api.entities.Member)1 Message (net.dv8tion.jda.api.entities.Message)1 MentionType (net.dv8tion.jda.api.entities.Message.MentionType)1 MessageChannel (net.dv8tion.jda.api.entities.MessageChannel)1 MessageReaction (net.dv8tion.jda.api.entities.MessageReaction)1 ReactionEmote (net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote)1 TextChannel (net.dv8tion.jda.api.entities.TextChannel)1 User (net.dv8tion.jda.api.entities.User)1