com.elypia.commandler.parsing.parsers.jda.EmoteParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commandler Show documentation
Show all versions of commandler Show documentation
Commandler is an commands framework designed for Discord bots with JDA.
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));
}
}