use of com.freya02.botcommands.api.application.ApplicationCommand in project BotCommands by freya022.
the class ApplicationCommandsBuilder method processUserCommand.
private void processUserCommand(ApplicationCommand applicationCommand, Method method) {
if (method.getAnnotation(JDAUserCommand.class).guildOnly()) {
if (!ReflectionUtils.hasFirstParameter(method, GlobalUserEvent.class) && !ReflectionUtils.hasFirstParameter(method, GuildUserEvent.class))
throw new IllegalArgumentException("User command at " + Utils.formatMethodShort(method) + " must have a GuildUserEvent or GlobalUserEvent as first parameter");
if (!ReflectionUtils.hasFirstParameter(method, GuildUserEvent.class)) {
// If type is correct but guild specialization isn't used
LOGGER.warn("Guild-only user command {} uses GlobalUserEvent, consider using GuildUserEvent to remove warnings related to guild stuff's nullability", Utils.formatMethodShort(method));
}
} else {
if (!ReflectionUtils.hasFirstParameter(method, GlobalUserEvent.class))
throw new IllegalArgumentException("User command at " + Utils.formatMethodShort(method) + " must have a GlobalUserEvent as first parameter");
}
final UserCommandInfo info = new UserCommandInfo(context, applicationCommand, method);
LOGGER.debug("Adding user command {} for method {}", info.getPath().getName(), Utils.formatMethodShort(method));
context.addUserCommand(info);
}
use of com.freya02.botcommands.api.application.ApplicationCommand in project BotCommands by freya022.
the class ApplicationCommandsBuilder method processMessageCommand.
private void processMessageCommand(ApplicationCommand applicationCommand, Method method) {
if (method.getAnnotation(JDAMessageCommand.class).guildOnly()) {
if (!ReflectionUtils.hasFirstParameter(method, GlobalMessageEvent.class) && !ReflectionUtils.hasFirstParameter(method, GuildMessageEvent.class))
throw new IllegalArgumentException("Message command at " + Utils.formatMethodShort(method) + " must have a GuildMessageEvent or GlobalMessageEvent as first parameter");
if (!ReflectionUtils.hasFirstParameter(method, GuildMessageEvent.class)) {
// If type is correct but guild specialization isn't used
LOGGER.warn("Guild-only message command {} uses GlobalMessageEvent, consider using GuildMessageEvent to remove warnings related to guild stuff's nullability", Utils.formatMethodShort(method));
}
} else {
if (!ReflectionUtils.hasFirstParameter(method, GlobalMessageEvent.class))
throw new IllegalArgumentException("Message command at " + Utils.formatMethodShort(method) + " must have a GlobalMessageEvent as first parameter");
}
final MessageCommandInfo info = new MessageCommandInfo(context, applicationCommand, method);
LOGGER.debug("Adding message command {} for method {}", info.getPath().getName(), Utils.formatMethodShort(method));
context.addMessageCommand(info);
}
use of com.freya02.botcommands.api.application.ApplicationCommand in project BotCommands by freya022.
the class ApplicationCommandsBuilder method processSlashCommand.
private void processSlashCommand(ApplicationCommand applicationCommand, Method method) {
if (method.getAnnotation(JDASlashCommand.class).guildOnly()) {
if (!ReflectionUtils.hasFirstParameter(method, GlobalSlashEvent.class) && !ReflectionUtils.hasFirstParameter(method, GuildSlashEvent.class))
throw new IllegalArgumentException("Slash command at " + Utils.formatMethodShort(method) + " must have a GuildSlashEvent or GlobalSlashEvent as first parameter");
if (!ReflectionUtils.hasFirstParameter(method, GuildSlashEvent.class)) {
// If type is correct but guild specialization isn't used
LOGGER.warn("Guild-only slash command {} uses GlobalSlashEvent, consider using GuildSlashEvent to remove warnings related to guild stuff's nullability", Utils.formatMethodShort(method));
}
} else {
if (!ReflectionUtils.hasFirstParameter(method, GlobalSlashEvent.class))
throw new IllegalArgumentException("Slash command at " + Utils.formatMethodShort(method) + " must have a GlobalSlashEvent as first parameter");
}
final SlashCommandInfo info = new SlashCommandInfo(context, applicationCommand, method);
LOGGER.debug("Adding slash command path {} for method {}", info.getPath(), Utils.formatMethodShort(method));
context.addSlashCommand(info);
}
use of com.freya02.botcommands.api.application.ApplicationCommand in project BotCommands by freya022.
the class CommandsBuilderImpl method processMethod.
private boolean processMethod(Method method) throws InvocationTargetException, InstantiationException, IllegalAccessException {
for (Class<? extends Annotation> annotation : applicationMethodAnnotations) {
final ApplicationCommand applicationCommand = tryInstantiateMethod(annotation, ApplicationCommand.class, "Application command", method);
if (applicationCommand != null) {
applicationCommandsBuilder.processApplicationCommand(applicationCommand, method);
return true;
}
}
final TextCommand textCommand = tryInstantiateMethod(JDATextCommand.class, TextCommand.class, "Text command", method);
if (textCommand != null) {
prefixedCommandsBuilder.processPrefixedCommand(textCommand, method);
return true;
}
final Object eventListener = tryInstantiateMethod(JDAEventListener.class, Object.class, "JDA event listener", method);
if (eventListener != null) {
eventListenersBuilder.processEventListener(eventListener, method);
return true;
}
final Object autocompletionHandler = tryInstantiateMethod(AutocompletionHandler.class, Object.class, "Slash command auto completion", method);
if (autocompletionHandler != null) {
autocompletionHandlersBuilder.processHandler(autocompletionHandler, method);
return true;
}
return false;
}
Aggregations