provide some contexts for JDA

This commit is contained in:
Aikar
2018-01-22 22:18:17 -05:00
parent 8667970216
commit 46ee14e4a3
@@ -1,7 +1,44 @@
package co.aikar.commands;
import co.aikar.commands.annotation.Optional;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
public class JDACommandContexts extends CommandContexts<JDACommandExecutionContext> {
JDACommandContexts(CommandManager manager) {
public JDACommandContexts(JDACommandManager manager) {
super(manager);
this.registerIssuerOnlyContext(CommandEvent.class, CommandExecutionContext::getIssuer);
this.registerIssuerOnlyContext(MessageReceivedEvent.class, c -> c.getIssuer().getIssuer());
this.registerIssuerOnlyContext(Message.class, c -> {
MessageReceivedEvent event = c.getIssuer().getIssuer();
return event.getMessage();
});
this.registerIssuerOnlyContext(Guild.class, c -> {
MessageReceivedEvent event = c.getIssuer().getIssuer();
if (event.isFromType(ChannelType.PRIVATE) && c.getAnnotation(Optional.class) == null) {
throw new InvalidCommandArgument("This command can only be executed in a Guild.", false); // TODO: Message Keys
} else {
return event.getGuild();
}
});
this.registerIssuerOnlyContext(MessageChannel.class, c -> {
MessageReceivedEvent event = c.getIssuer().getIssuer();
return event.getChannel();
});
this.registerIssuerOnlyContext(ChannelType.class, c -> {
MessageReceivedEvent event = c.getIssuer().getIssuer();
return event.getChannelType();
});
this.registerIssuerOnlyContext(User.class, c -> {
MessageReceivedEvent event = c.getIssuer().getIssuer();
return event.getAuthor();
});
this.registerIssuerOnlyContext(JDA.class, c -> ((JDACommandManager) this.manager).getJDA());
}
}