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());
});
}
Aggregations