[AB-xxx] fixing custom command alternative to filter when it should be executed more accurately

This commit is contained in:
Sheldan
2023-12-23 23:16:01 +01:00
parent d2231b0934
commit 20a6e29f1b
3 changed files with 13 additions and 5 deletions

View File

@@ -166,7 +166,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
if(commandAlternatives != null) {
Optional<CommandAlternative> foundAlternativeOptional = commandAlternatives
.stream()
.filter(commandAlternative -> commandAlternative.shouldExecute(result.getParameter(), event.getGuild()))
.filter(commandAlternative -> commandAlternative.shouldExecute(result.getParameter(), event.getGuild(), message))
.findFirst();
if(foundAlternativeOptional.isPresent()) {
CommandAlternative foundAlternative = foundAlternativeOptional.get();
@@ -584,7 +584,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
metricService.registerCounter(COMMANDS_WRONG_PARAMETER_COUNTER, "Commands with incorrect parameter");
this.parameterHandlers = parameterHandlers.stream().sorted(comparing(CommandParameterHandler::getPriority)).collect(Collectors.toList());
if(commandAlternatives != null) {
this.commandAlternatives = commandAlternatives.stream().sorted(comparing(Prioritized::getPriority)).collect(Collectors.toList());
this.commandAlternatives = commandAlternatives.stream().sorted(comparing(Prioritized::getPriority).reversed()).collect(Collectors.toList());
}
}

View File

@@ -6,6 +6,6 @@ import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
public interface CommandAlternative extends Prioritized {
boolean shouldExecute(UnParsedCommandParameter parameter, Guild guild);
boolean shouldExecute(UnParsedCommandParameter parameter, Guild guild, Message message);
void execute(UnParsedCommandParameter parameter, Message message);
}