use of com.freya02.botcommands.api.application.context.message.GlobalMessageEvent 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.context.message.GlobalMessageEvent 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;
}
Aggregations