mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-01 15:28:35 +00:00
[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:
@@ -23,7 +23,6 @@ import net.dv8tion.jda.api.entities.Member;
|
|||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -76,16 +75,15 @@ public class Ban extends AbstractConditionableCommand {
|
|||||||
duration = null;
|
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()
|
return event.deferReply().submit()
|
||||||
.thenCompose((hook) -> self.banMember(event, member, reason, duration, hook))
|
.thenCompose((hook) -> self.banMember(event, member, reason, duration, hook))
|
||||||
.thenApply(commandResult -> CommandResult.fromSuccess());
|
.thenApply(commandResult -> CommandResult.fromSuccess());
|
||||||
} else {
|
} else {
|
||||||
String userIdStr = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, String.class);
|
User user = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, User.class);
|
||||||
Long userId = Long.parseLong(userIdStr);
|
|
||||||
return event.deferReply().submit()
|
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());
|
.thenApply(commandResult -> CommandResult.fromSuccess());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import net.dv8tion.jda.api.entities.Member;
|
|||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -86,16 +85,15 @@ public class Infractions extends AbstractConditionableCommand {
|
|||||||
public CompletableFuture<CommandResult> showInfractions(InteractionHook hook, SlashCommandInteractionEvent event) {
|
public CompletableFuture<CommandResult> showInfractions(InteractionHook hook, SlashCommandInteractionEvent event) {
|
||||||
List<Infraction> infractions;
|
List<Infraction> infractions;
|
||||||
Guild guild = hook.getInteraction().getGuild();
|
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)) {
|
if(!member.getGuild().equals(guild)) {
|
||||||
throw new EntityGuildMismatchException();
|
throw new EntityGuildMismatchException();
|
||||||
}
|
}
|
||||||
infractions = infractionManagementService.getInfractionsForUser(userInServerManagementService.loadOrCreateUser(member));
|
infractions = infractionManagementService.getInfractionsForUser(userInServerManagementService.loadOrCreateUser(member));
|
||||||
} else if(slashCommandParameterService.hasCommandOptionWithFullType(USER_PARAMETER, event, OptionType.STRING)){
|
} else if(user != null){
|
||||||
String userIdStr = slashCommandParameterService.getCommandOption(USER_PARAMETER, event, User.class, String.class);
|
AUserInAServer userInServer = userInServerManagementService.loadOrCreateUser(guild.getIdLong(), user.getIdLong());
|
||||||
Long userId = Long.parseLong(userIdStr);
|
|
||||||
AUserInAServer userInServer = userInServerManagementService.loadOrCreateUser(guild.getIdLong(), userId);
|
|
||||||
infractions = infractionManagementService.getInfractionsForUser(userInServer);
|
infractions = infractionManagementService.getInfractionsForUser(userInServer);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import dev.sheldan.abstracto.core.interaction.InteractionService;
|
|||||||
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandConfig;
|
||||||
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
|
import dev.sheldan.abstracto.core.interaction.slash.SlashCommandPrivilegeLevels;
|
||||||
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
import dev.sheldan.abstracto.core.interaction.slash.parameter.SlashCommandParameterService;
|
||||||
import dev.sheldan.abstracto.core.service.UserService;
|
|
||||||
import dev.sheldan.abstracto.stickyroles.config.StickyRolesFeatureDefinition;
|
import dev.sheldan.abstracto.stickyroles.config.StickyRolesFeatureDefinition;
|
||||||
import dev.sheldan.abstracto.stickyroles.config.StickyRolesSlashCommandNames;
|
import dev.sheldan.abstracto.stickyroles.config.StickyRolesSlashCommandNames;
|
||||||
import dev.sheldan.abstracto.stickyroles.service.StickyRoleService;
|
import dev.sheldan.abstracto.stickyroles.service.StickyRoleService;
|
||||||
@@ -19,10 +18,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -47,34 +44,18 @@ public class ToggleStickinessManagement extends AbstractConditionableCommand {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private StickyRoleService stickyRoleService;
|
private StickyRoleService stickyRoleService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ToggleStickinessManagement self;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
Boolean newState = slashCommandParameterService.getCommandOption(STICKY_PARAMETER_NAME, event, Boolean.class);
|
Boolean newState = slashCommandParameterService.getCommandOption(STICKY_PARAMETER_NAME, event, Boolean.class);
|
||||||
if(slashCommandParameterService.hasCommandOptionWithFullType(MEMBER_PARAMETER_NAME, event, OptionType.USER)) {
|
Member targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_NAME, event, User.class, Member.class);
|
||||||
Member targetMember = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_NAME, event, User.class, Member.class);
|
User targetUser = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_NAME, event, User.class, User.class);
|
||||||
|
if(targetMember != null) {
|
||||||
stickyRoleService.setStickiness(targetMember, newState);
|
stickyRoleService.setStickiness(targetMember, newState);
|
||||||
return interactionService.replyEmbed(RESPONSE_TEMPLATE, event)
|
|
||||||
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
|
||||||
} else {
|
} else {
|
||||||
String userIdStr = slashCommandParameterService.getCommandOption(MEMBER_PARAMETER_NAME, event, User.class, String.class);
|
stickyRoleService.setStickiness(targetUser, event.getGuild(), newState);
|
||||||
Long userId = Long.parseLong(userIdStr);
|
|
||||||
return userService.retrieveUserForId(userId).thenCompose(user -> {
|
|
||||||
self.callService(event, user, newState);
|
|
||||||
return interactionService.replyEmbed(RESPONSE_TEMPLATE, event);
|
|
||||||
}).thenApply(interactionHook -> CommandResult.fromSuccess());
|
|
||||||
}
|
}
|
||||||
}
|
return interactionService.replyEmbed(RESPONSE_TEMPLATE, event)
|
||||||
|
.thenApply(interactionHook -> CommandResult.fromSuccess());
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void callService(SlashCommandInteractionEvent event, User user, Boolean newState) {
|
|
||||||
stickyRoleService.setStickiness(user, event.getGuild(), newState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class UserSlashCommandParameterProvider implements SlashCommandParameterP
|
|||||||
return SlashCommandOptionTypeMapping
|
return SlashCommandOptionTypeMapping
|
||||||
.builder()
|
.builder()
|
||||||
.type(User.class)
|
.type(User.class)
|
||||||
.optionTypes(Arrays.asList(OptionType.USER, OptionType.STRING))
|
.optionTypes(Arrays.asList(OptionType.USER))
|
||||||
.strictTypes(List.of(OptionType.USER))
|
.strictTypes(List.of(OptionType.USER))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user