mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-14 03:45:57 +00:00
[AB-xxx] fixing custom command alternative to filter when it should be executed more accurately
This commit is contained in:
@@ -45,8 +45,16 @@ public class CustomCommandAlternative implements CommandAlternative {
|
|||||||
private CustomCommandFeatureConfig customCommandFeatureConfig;
|
private CustomCommandFeatureConfig customCommandFeatureConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldExecute(UnParsedCommandParameter parameter, Guild guild) {
|
public boolean shouldExecute(UnParsedCommandParameter parameter, Guild guild, Message message) {
|
||||||
return featureFlagService.isFeatureEnabled(customCommandFeatureConfig, guild.getIdLong());
|
boolean featureEnabled = featureFlagService.isFeatureEnabled(customCommandFeatureConfig, guild.getIdLong());
|
||||||
|
if(featureEnabled) {
|
||||||
|
String contentStripped = message.getContentRaw();
|
||||||
|
List<String> parameters = Arrays.asList(contentStripped.split(" "));
|
||||||
|
String commandName = commandRegistry.getCommandName(parameters.get(0), message.getGuild().getIdLong());
|
||||||
|
Optional<CustomCommand> customCommandOptional = customCommandManagementService.getCustomCommandByName(commandName, message.getGuild().getIdLong());
|
||||||
|
return customCommandOptional.isPresent();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
|||||||
if(commandAlternatives != null) {
|
if(commandAlternatives != null) {
|
||||||
Optional<CommandAlternative> foundAlternativeOptional = commandAlternatives
|
Optional<CommandAlternative> foundAlternativeOptional = commandAlternatives
|
||||||
.stream()
|
.stream()
|
||||||
.filter(commandAlternative -> commandAlternative.shouldExecute(result.getParameter(), event.getGuild()))
|
.filter(commandAlternative -> commandAlternative.shouldExecute(result.getParameter(), event.getGuild(), message))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if(foundAlternativeOptional.isPresent()) {
|
if(foundAlternativeOptional.isPresent()) {
|
||||||
CommandAlternative foundAlternative = foundAlternativeOptional.get();
|
CommandAlternative foundAlternative = foundAlternativeOptional.get();
|
||||||
@@ -584,7 +584,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
|||||||
metricService.registerCounter(COMMANDS_WRONG_PARAMETER_COUNTER, "Commands with incorrect parameter");
|
metricService.registerCounter(COMMANDS_WRONG_PARAMETER_COUNTER, "Commands with incorrect parameter");
|
||||||
this.parameterHandlers = parameterHandlers.stream().sorted(comparing(CommandParameterHandler::getPriority)).collect(Collectors.toList());
|
this.parameterHandlers = parameterHandlers.stream().sorted(comparing(CommandParameterHandler::getPriority)).collect(Collectors.toList());
|
||||||
if(commandAlternatives != null) {
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ import net.dv8tion.jda.api.entities.Guild;
|
|||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
|
||||||
public interface CommandAlternative extends Prioritized {
|
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);
|
void execute(UnParsedCommandParameter parameter, Message message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user