[AB-xxx] enabling commands which take users to only require one parameter instead of a string and a member option

This commit is contained in:
Sheldan
2025-07-29 23:04:33 +02:00
parent 433fdb7068
commit ef4bdb2ab2
4 changed files with 16 additions and 39 deletions

View File

@@ -23,7 +23,6 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -76,16 +75,15 @@ public class Ban extends AbstractConditionableCommand {
duration = null;
}
if(slashCommandParameterService.hasCommandOptionWithFullType(USER_PARAMETER, event, OptionType.USER)) {
Member member = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, Member.class);
Member member = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, Member.class);
if(member != null) {
return event.deferReply().submit()
.thenCompose((hook) -> self.banMember(event, member, reason, duration, hook))
.thenApply(commandResult -> CommandResult.fromSuccess());
} else {
String userIdStr = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, String.class);
Long userId = Long.parseLong(userIdStr);
User user = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, User.class);
return event.deferReply().submit()
.thenCompose((hook) -> self.banViaUserId(event, userId, reason, duration, hook))
.thenCompose((hook) -> self.banViaUserId(event, user.getIdLong(), reason, duration, hook))
.thenApply(commandResult -> CommandResult.fromSuccess());
}
}

View File

@@ -33,7 +33,6 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -86,16 +85,15 @@ public class Infractions extends AbstractConditionableCommand {
public CompletableFuture<CommandResult> showInfractions(InteractionHook hook, SlashCommandInteractionEvent event) {
List<Infraction> infractions;
Guild guild = hook.getInteraction().getGuild();
if(slashCommandParameterService.hasCommandOptionWithFullType(USER_PARAMETER, event, OptionType.USER)) {
Member member = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, Member.class);
Member member = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, Member.class);
User user = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, User.class);
if(member != null) {
if(!member.getGuild().equals(guild)) {
throw new EntityGuildMismatchException();
}
infractions = infractionManagementService.getInfractionsForUser(userInServerManagementService.loadOrCreateUser(member));
} else if(slashCommandParameterService.hasCommandOptionWithFullType(USER_PARAMETER, event, OptionType.STRING)){
String userIdStr = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, String.class);
Long userId = Long.parseLong(userIdStr);
AUserInAServer userInServer = userInServerManagementService.loadOrCreateUser(guild.getIdLong(), userId);
} else if(user != null){
AUserInAServer userInServer = userInServerManagementService.loadOrCreateUser(guild.getIdLong(), user.getIdLong());
infractions = infractionManagementService.getInfractionsForUser(userInServer);
} else {