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;
}
Aggregations