Search in sources :

Example 1 with PaginationPage

use of me.piggypiglet.gary.core.objects.paginations.PaginationPage in project Gary by help-chat.

the class PaginationHandler method execute.

@Override
protected void execute(GenericEvent event) {
    switch(EventsEnum.fromEvent(event)) {
        case MESSAGE_REACTION_ADD:
            GuildMessageReactionAddEvent e = (GuildMessageReactionAddEvent) event;
            if (!e.getMember().getUser().isBot()) {
                String messageId = e.getMessageId();
                if (paginations.containsKey(messageId)) {
                    MessageReaction.ReactionEmote reactionEmote = e.getReactionEmote();
                    PaginationPage newPage;
                    if (reactionEmote.getEmote() == null) {
                        newPage = paginations.get(messageId).getPage(reactionEmote.getName());
                    } else {
                        newPage = paginations.get(messageId).getPage(reactionEmote.getEmote());
                    }
                    if (newPage != null) {
                        Object newMessage = newPage.getMessage();
                        Message message = e.getChannel().retrieveMessageById(messageId).complete();
                        if (newMessage instanceof String) {
                            message.editMessage((String) newMessage).queue();
                        } else if (newMessage instanceof MessageEmbed) {
                            message.editMessage((MessageEmbed) newMessage).override(true).queue();
                        }
                        e.getReaction().removeReaction(e.getUser()).queue();
                    }
                }
            }
            break;
        case MESSAGE_DELETE:
            paginations.remove(((GuildMessageDeleteEvent) event).getMessageId());
            break;
    }
}
Also used : MessageReaction(net.dv8tion.jda.api.entities.MessageReaction) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) Message(net.dv8tion.jda.api.entities.Message) PaginationPage(me.piggypiglet.gary.core.objects.paginations.PaginationPage) GuildMessageReactionAddEvent(net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent)

Aggregations

PaginationPage (me.piggypiglet.gary.core.objects.paginations.PaginationPage)1 Message (net.dv8tion.jda.api.entities.Message)1 MessageEmbed (net.dv8tion.jda.api.entities.MessageEmbed)1 MessageReaction (net.dv8tion.jda.api.entities.MessageReaction)1 GuildMessageReactionAddEvent (net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent)1