Search in sources :

Example 1 with UserContextParameterResolver

use of com.freya02.botcommands.api.parameters.UserContextParameterResolver in project BotCommands by freya022.

the class UserCommandInfo method execute.

public boolean execute(BContext context, UserContextInteractionEvent event, Consumer<Throwable> throwableConsumer) throws Exception {
    final Object[] objects = new Object[commandParameters.size() + 1];
    if (guildOnly) {
        objects[0] = new GuildUserEvent(context, event);
    } else {
        objects[0] = new GlobalUserEvent(context, event);
    }
    for (int i = 0, commandParametersLength = commandParameters.size(); i < commandParametersLength; i++) {
        ContextCommandParameter<UserContextParameterResolver> parameter = commandParameters.get(i);
        if (parameter.isOption()) {
            objects[i + 1] = parameter.getResolver().resolve(context, this, event);
        // no need to check for unresolved parameters,
        // it is impossible to have other arg types other than User (and custom resolvers)
        } else {
            objects[i + 1] = parameter.getCustomResolver().resolve(context, this, event);
        }
    }
    applyCooldown(event);
    getMethodRunner().invoke(objects, throwableConsumer);
    return true;
}
Also used : GuildUserEvent(com.freya02.botcommands.api.application.context.user.GuildUserEvent) UserContextParameterResolver(com.freya02.botcommands.api.parameters.UserContextParameterResolver) GlobalUserEvent(com.freya02.botcommands.api.application.context.user.GlobalUserEvent)

Aggregations

GlobalUserEvent (com.freya02.botcommands.api.application.context.user.GlobalUserEvent)1 GuildUserEvent (com.freya02.botcommands.api.application.context.user.GuildUserEvent)1 UserContextParameterResolver (com.freya02.botcommands.api.parameters.UserContextParameterResolver)1