Search in sources :

Example 1 with MessageContextParameterResolver

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

the class MessageCommandInfo method execute.

public boolean execute(BContext context, MessageContextInteractionEvent event, Consumer<Throwable> throwableConsumer) throws Exception {
    final Object[] objects = new Object[commandParameters.size() + 1];
    if (guildOnly) {
        objects[0] = new GuildMessageEvent(context, event);
    } else {
        objects[0] = new GlobalMessageEvent(context, event);
    }
    for (int i = 0, commandParametersLength = commandParameters.size(); i < commandParametersLength; i++) {
        ContextCommandParameter<MessageContextParameterResolver> 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 Message (and custom resolvers)
        } else {
            objects[i + 1] = parameter.getCustomResolver().resolve(context, this, event);
        }
    }
    applyCooldown(event);
    getMethodRunner().invoke(objects, throwableConsumer);
    return true;
}
Also used : MessageContextParameterResolver(com.freya02.botcommands.api.parameters.MessageContextParameterResolver) GlobalMessageEvent(com.freya02.botcommands.api.application.context.message.GlobalMessageEvent) GuildMessageEvent(com.freya02.botcommands.api.application.context.message.GuildMessageEvent)

Aggregations

GlobalMessageEvent (com.freya02.botcommands.api.application.context.message.GlobalMessageEvent)1 GuildMessageEvent (com.freya02.botcommands.api.application.context.message.GuildMessageEvent)1 MessageContextParameterResolver (com.freya02.botcommands.api.parameters.MessageContextParameterResolver)1