use of net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote in project Bean by Xirado.
the class MessageReactionAddListener method onMessageReactionAdd.
@Override
public void onMessageReactionAdd(@NotNull MessageReactionAddEvent e) {
if (!e.isFromGuild())
return;
if (GuildJoinListener.isGuildBanned(e.getGuild().getIdLong()))
return;
try {
if (e.getMember().getUser().isBot())
return;
Guild g = e.getGuild();
long id = e.getMessageIdLong();
ReactionEmote reactionemote = e.getReactionEmote();
String reacted = reactionemote.isEmoji() ? reactionemote.getAsReactionCode() : reactionemote.getEmote().getId();
GuildData data = GuildManager.getGuildData(e.getGuild());
ReactionRole reactionRole = data.getReactionRoles().stream().filter(x -> x.getMessageId() == id && x.getEmote().equals(reacted)).findFirst().orElse(null);
if (reactionRole != null) {
Role role = e.getGuild().getRoleById(reactionRole.getRoleId());
if (role != null)
g.addRoleToMember(e.getMember(), role).queue(s -> {
}, ex -> {
});
}
} catch (Exception e2) {
LOGGER.error("An error occured whilst executing reaction role event!", e2);
}
}
use of net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote in project Minecord by Tisawesomeness.
the class ReactListener method onMessageReactionAdd.
@Override
public void onMessageReactionAdd(MessageReactionAddEvent e) {
// Make sure message matches
HashMap<Long, ReactMenu> menus = ReactMenu.getMenus();
if (menus.containsKey(e.getMessageIdLong())) {
// Make sure owner matches
ReactMenu menu = menus.get(e.getMessageIdLong());
boolean removed = false;
if (menu.getOwnerID() == e.getUserIdLong()) {
// Make sure emote matches
HashMap<String, Runnable> buttons = menu.getButtons();
ReactionEmote re = e.getReactionEmote();
if (e.getReactionEmote().isEmoji()) {
String emote = re.getAsCodepoints();
if (buttons.containsKey(emote)) {
// Run the code
removeEmote(e);
removed = true;
Runnable r = buttons.get(emote);
if (r != null) {
menu.keepAlive();
r.run();
}
}
}
}
if (!e.getUser().isBot() && !removed) {
removeEmote(e);
}
}
}
use of net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote in project Sx4 by sx4-discord-bot.
the class StarboardCommand method emote.
@Command(value = "emote", aliases = { "emoji" }, description = "Sets the emote/emoji to be used for starboard")
@CommandId(199)
@Examples({ "starboard emote ☝️", "starboard emote <:upvote:761345612079693865>", "starboard emote reset" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void emote(Sx4CommandEvent event, @Argument(value = "emote | reset", endless = true) @AlternativeOptions("reset") Alternative<ReactionEmote> option) {
ReactionEmote emote = option.getValue();
boolean emoji = emote != null && emote.isEmoji();
List<Bson> update = emote == null ? List.of(Operators.unset("starboard.emote")) : List.of(Operators.set("starboard.emote." + (emoji ? "name" : "id"), emoji ? emote.getEmoji() : emote.getIdLong()), Operators.unset("starboard.emote." + (emoji ? "id" : "name")));
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.BEFORE).upsert(true).projection(Projections.include("starboard.emote"));
event.getMongo().findAndUpdateGuildById(event.getGuild().getIdLong(), update, options).whenComplete((data, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
Document emoteData = data == null ? null : data.getEmbedded(List.of("starboard", "emote"), Document.class);
if ((emote == null && emoteData == null) || (emote != null && emoteData != null && (emoji ? emote.getEmoji().equals(emoteData.getString("name")) : emoteData.getLong("id") == emote.getIdLong()))) {
event.replyFailure("Your starboard emote was already " + (emote == null ? "unset" : "set to that")).queue();
return;
}
event.replySuccess("Your starboard emote has been " + (emote == null ? "unset" : "updated")).queue();
});
}
use of net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote in project Sx4 by sx4-discord-bot.
the class ReactionRoleHandler method onGenericGuildMessageReaction.
public void onGenericGuildMessageReaction(GenericGuildMessageReactionEvent event) {
User user = event.getUser();
Guild guild = event.getGuild();
ReactionEmote emote = event.getReactionEmote();
if (user == null || user.isBot()) {
return;
}
Config config = this.bot.getConfig();
List<Document> reactionRoles = this.bot.getMongo().getReactionRoles(Filters.eq("messageId", event.getMessageIdLong()), MongoDatabase.EMPTY_DOCUMENT).into(new ArrayList<>());
if (reactionRoles.isEmpty()) {
return;
}
if (!guild.getSelfMember().hasPermission(Permission.MANAGE_ROLES)) {
user.openPrivateChannel().flatMap(channel -> channel.sendMessage("I am missing the `" + Permission.MANAGE_ROLES.getName() + "` permission " + config.getFailureEmote())).queue(null, ErrorResponseException.ignore(ErrorResponse.CANNOT_SEND_TO_USER));
return;
}
int reactedTo = 0;
List<Role> roles = null;
Document reactionRole = null;
boolean remove = false;
Set<Role> memberRoles = new HashSet<>(event.getMember().getRoles());
for (Document data : reactionRoles) {
List<Role> rolesData = data.getList("roles", Long.class).stream().map(guild::getRoleById).filter(Objects::nonNull).filter(role -> guild.getSelfMember().canInteract(role)).collect(Collectors.toList());
boolean allRoles = memberRoles.containsAll(rolesData);
if (allRoles) {
reactedTo++;
}
Document emoteData = data.get("emote", Document.class);
if ((emote.isEmoji() && emoteData.containsKey("name") && emoteData.getString("name").equals(emote.getEmoji())) || (emote.isEmote() && emoteData.containsKey("id") && emoteData.getLong("id") == emote.getEmote().getIdLong())) {
if (rolesData.isEmpty()) {
return;
}
roles = rolesData;
reactionRole = data;
remove = allRoles;
}
}
if (roles == null) {
return;
}
if (!remove) {
List<Document> permissions = reactionRole.getList("permissions", Document.class, Collections.emptyList());
for (int i = 0; i < permissions.size(); i++) {
Document permission = permissions.get(i);
long holderId = permission.getLong("id");
int type = permission.getInteger("type");
boolean granted = permission.getBoolean("granted");
if (type == HolderType.USER.getType() && holderId == user.getIdLong()) {
if (granted) {
break;
}
} else if (type == HolderType.ROLE.getType() && (holderId == guild.getIdLong() || memberRoles.stream().anyMatch(role -> role.getIdLong() == holderId))) {
if (granted) {
break;
}
}
if (i == permissions.size() - 1) {
user.openPrivateChannel().flatMap(channel -> channel.sendMessage("You are not whitelisted to be able to get the roles behind this reaction " + config.getFailureEmote())).queue(null, ErrorResponseException.ignore(ErrorResponse.CANNOT_SEND_TO_USER));
return;
}
}
}
int maxReactions = reactionRole.get("maxReactions", 0);
if (!remove && reactedTo >= maxReactions && maxReactions != 0) {
user.openPrivateChannel().flatMap(channel -> channel.sendMessage("You can only react to **" + maxReactions + "** reaction" + (maxReactions == 1 ? "" : "s") + " on this message " + config.getFailureEmote())).queue(null, ErrorResponseException.ignore(ErrorResponse.CANNOT_SEND_TO_USER));
return;
}
if (remove) {
guild.modifyMemberRoles(event.getMember(), null, roles).queue();
} else {
guild.modifyMemberRoles(event.getMember(), roles, null).queue();
}
String message = "You " + (remove ? "no longer" : "now") + " have the role" + (roles.size() == 1 ? "" : "s") + " `" + roles.stream().map(Role::getName).collect(Collectors.joining("`, `")) + "` " + config.getSuccessEmote();
if (reactionRole.getBoolean("dm", true)) {
user.openPrivateChannel().flatMap(channel -> channel.sendMessage(message)).queue(null, ErrorResponseException.ignore(ErrorResponse.CANNOT_SEND_TO_USER));
}
}
use of net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote 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