use of com.freya02.botcommands.api.application.context.user.GuildUserEvent 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.context.user.GuildUserEvent in project BotCommands by freya022.
the class ContextAvatar method execute.
@JDAUserCommand(name = "Get avatar")
public void execute(GuildUserEvent event) {
final User targetUser = event.getTarget();
event.reply(targetUser.getEffectiveAvatarUrl()).queue();
}
use of com.freya02.botcommands.api.application.context.user.GuildUserEvent 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;
}
Aggregations