All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.elypia.commandler.parsing.parsers.jda.EmoteParser Maven / Gradle / Ivy

The newest version!
package com.elypia.commandler.parsing.parsers.jda;

import com.elypia.commandler.data.SearchScope;
import com.elypia.commandler.events.MessageEvent;
import com.elypia.commandler.parsing.IParamParser;
import net.dv8tion.jda.core.entities.*;

import java.util.*;

public class EmoteParser implements IParamParser {

    @Override
    public Emote parse(MessageEvent event, SearchScope scope, String input) {
        final Set emotes = new HashSet<>();

        emotes.addAll(event.getMessage().getEmotes());

        switch (scope) {
            case GLOBAL:
                emotes.addAll(event.getMessageEvent().getJDA().getEmotes());
                break;

            case MUTUAL:
                User user = event.getMessage().getAuthor();
                Collection guilds = user.getMutualGuilds();
                guilds.forEach(g -> emotes.addAll(g.getEmotes()));
                break;

            case LOCAL:
                emotes.addAll(event.getMessageEvent().getGuild().getEmotes());
                break;
        }

        for (Emote emote : emotes) {
            if (compare(input, emote))
                return emote;
        }

        event.invalidate("Parameter `" + input + "` could not be be linked to an emote.");
        return null;
    }

    public boolean compare(String input, Emote emote) {
        return (emote.getId().equals(input) || emote.getAsMention().equalsIgnoreCase(input) || emote.getName().equalsIgnoreCase(input) || emote.toString().equalsIgnoreCase(input));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy