Search in sources :

Example 1 with PartialEmote

use of com.sx4.bot.entities.mod.PartialEmote in project Sx4 by sx4-discord-bot.

the class SearchUtility method getPartialEmote.

public static PartialEmote getPartialEmote(ShardManager manager, String query) {
    Matcher mentionMatch = SearchUtility.EMOTE_MENTION.matcher(query);
    Matcher urlMatch = SearchUtility.EMOTE_URL.matcher(query);
    if (mentionMatch.matches()) {
        String id = mentionMatch.group(3);
        try {
            return new PartialEmote(Long.parseLong(id), mentionMatch.group(2), mentionMatch.group(1) != null);
        } catch (NumberFormatException e) {
            return null;
        }
    } else if (NumberUtility.isNumberUnsigned(query)) {
        try {
            Emote emote = manager.getEmoteById(query);
            if (emote == null) {
                return new PartialEmote(Long.parseLong(query), null, null);
            } else {
                return new PartialEmote(emote);
            }
        } catch (NumberFormatException e) {
            return null;
        }
    } else if (urlMatch.matches()) {
        try {
            long id = Long.parseLong(urlMatch.group(1));
            Emote emote = manager.getEmoteById(id);
            if (emote == null) {
                return new PartialEmote(id, null, urlMatch.group(2).equals("gif"));
            } else {
                return new PartialEmote(emote);
            }
        } catch (NumberFormatException e) {
            return null;
        }
    }
    return null;
}
Also used : PartialEmote(com.sx4.bot.entities.mod.PartialEmote) Matcher(java.util.regex.Matcher) ReactionEmote(net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote) PartialEmote(com.sx4.bot.entities.mod.PartialEmote)

Aggregations

PartialEmote (com.sx4.bot.entities.mod.PartialEmote)1 Matcher (java.util.regex.Matcher)1 ReactionEmote (net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote)1