Search in sources :

Example 1 with ApplicationCommand

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);
}
Also used : GuildUserEvent(com.freya02.botcommands.api.application.context.user.GuildUserEvent) UserCommandInfo(com.freya02.botcommands.internal.application.context.user.UserCommandInfo) GlobalUserEvent(com.freya02.botcommands.api.application.context.user.GlobalUserEvent) JDAUserCommand(com.freya02.botcommands.api.application.context.annotations.JDAUserCommand)

Example 2 with ApplicationCommand

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);
}
Also used : MessageCommandInfo(com.freya02.botcommands.internal.application.context.message.MessageCommandInfo) GlobalMessageEvent(com.freya02.botcommands.api.application.context.message.GlobalMessageEvent) JDAMessageCommand(com.freya02.botcommands.api.application.context.annotations.JDAMessageCommand) GuildMessageEvent(com.freya02.botcommands.api.application.context.message.GuildMessageEvent)

Example 3 with ApplicationCommand

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);
}
Also used : SlashCommandInfo(com.freya02.botcommands.internal.application.slash.SlashCommandInfo) GuildSlashEvent(com.freya02.botcommands.api.application.slash.GuildSlashEvent) GlobalSlashEvent(com.freya02.botcommands.api.application.slash.GlobalSlashEvent) JDASlashCommand(com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)

Example 4 with ApplicationCommand

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;
}
Also used : JDATextCommand(com.freya02.botcommands.api.prefixed.annotations.JDATextCommand) TextCommand(com.freya02.botcommands.api.prefixed.TextCommand) ApplicationCommand(com.freya02.botcommands.api.application.ApplicationCommand)

Aggregations

ApplicationCommand (com.freya02.botcommands.api.application.ApplicationCommand)1 JDAMessageCommand (com.freya02.botcommands.api.application.context.annotations.JDAMessageCommand)1 JDAUserCommand (com.freya02.botcommands.api.application.context.annotations.JDAUserCommand)1 GlobalMessageEvent (com.freya02.botcommands.api.application.context.message.GlobalMessageEvent)1 GuildMessageEvent (com.freya02.botcommands.api.application.context.message.GuildMessageEvent)1 GlobalUserEvent (com.freya02.botcommands.api.application.context.user.GlobalUserEvent)1 GuildUserEvent (com.freya02.botcommands.api.application.context.user.GuildUserEvent)1 GlobalSlashEvent (com.freya02.botcommands.api.application.slash.GlobalSlashEvent)1 GuildSlashEvent (com.freya02.botcommands.api.application.slash.GuildSlashEvent)1 JDASlashCommand (com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)1 TextCommand (com.freya02.botcommands.api.prefixed.TextCommand)1 JDATextCommand (com.freya02.botcommands.api.prefixed.annotations.JDATextCommand)1 MessageCommandInfo (com.freya02.botcommands.internal.application.context.message.MessageCommandInfo)1 UserCommandInfo (com.freya02.botcommands.internal.application.context.user.UserCommandInfo)1 SlashCommandInfo (com.freya02.botcommands.internal.application.slash.SlashCommandInfo)1