use of net.dv8tion.jda.core.entities.MessageReaction in project FlareBot by FlareBot.
the class Events method onMessageReactionAdd.
@Override
public void onMessageReactionAdd(MessageReactionAddEvent event) {
if (!event.getGuild().getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_READ))
return;
if (event.getUser().isBot())
return;
if (ButtonUtil.isButtonMessage(event.getMessageId())) {
for (ButtonGroup.Button button : ButtonUtil.getButtonGroup(event.getMessageId()).getButtons()) {
if ((event.getReactionEmote() != null && event.getReactionEmote().isEmote() && event.getReactionEmote().getIdLong() == button.getEmoteId()) || (button.getUnicode() != null && event.getReactionEmote().getName().equals(button.getUnicode()))) {
try {
event.getChannel().getMessageById(event.getMessageId()).queue(message -> {
for (MessageReaction reaction : message.getReactions()) {
if (reaction.getReactionEmote().equals(event.getReactionEmote())) {
reaction.removeReaction(event.getUser()).queue();
}
}
});
} catch (InsufficientPermissionException e) {
event.getGuild().getOwner().getUser().openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage("I cannot remove reactions from messages in the channel: " + event.getChannel().getName() + "! Please give me the `MESSAGE_HISTORY` " + "permission to allow me to do this!").queue();
}, ignored -> {
});
}
button.onClick(ButtonUtil.getButtonGroup(event.getMessageId()).getOwner(), event.getUser());
String emote = event.getReactionEmote() != null ? event.getReactionEmote().getName() + "(" + event.getReactionEmote().getId() + ")" : button.getUnicode();
Metrics.buttonsPressed.labels(emote, ButtonUtil.getButtonGroup(event.getMessageId()).getName()).inc();
if (!event.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_MANAGE)) {
return;
}
return;
}
}
}
if (!FlareBotManager.instance().getGuild(event.getGuild().getId()).getBetaAccess())
return;
// Check if it's a :pushpin:
if (!event.getReactionEmote().getName().equals("\uD83D\uDCCC"))
return;
event.getChannel().getMessageById(event.getMessageId()).queue(message -> {
MessageReaction reaction = message.getReactions().stream().filter(r -> r.getReactionEmote().getName().equals(event.getReactionEmote().getName())).findFirst().orElse(null);
if (reaction != null) {
if (reaction.getCount() == 5) {
message.pin().queue((aVoid) -> event.getChannel().getHistory().retrievePast(1).complete().get(0).delete().queue());
}
}
});
}
Aggregations