added ability to define aliases in the code

This commit is contained in:
Sheldan
2020-04-04 17:29:49 +02:00
parent 20b282584a
commit a957c66905
4 changed files with 18 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ public class CommandManager implements CommandRegistry {
public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter) { public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter) {
Optional<Command> commandOptional = commands.stream().filter((Command o )-> { Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
CommandConfiguration commandConfiguration = o.getConfiguration(); CommandConfiguration commandConfiguration = o.getConfiguration();
if(!commandConfiguration.getName().equalsIgnoreCase(name)) { if(!commandNameMatches(name, commandConfiguration)) {
return false; return false;
} }
boolean parameterFit; boolean parameterFit;
@@ -49,6 +49,18 @@ public class CommandManager implements CommandRegistry {
throw new CommandNotFound("Command not found."); throw new CommandNotFound("Command not found.");
} }
private boolean commandNameMatches(String name, CommandConfiguration commandConfiguration) {
boolean commandNameMatches = commandConfiguration.getName().equalsIgnoreCase(name);
if(commandNameMatches) {
return true;
}
boolean aliasesMatch = false;
if(commandConfiguration.getAliases() != null) {
aliasesMatch = commandConfiguration.getAliases().stream().anyMatch(s -> s.equalsIgnoreCase(name));
}
return aliasesMatch;
}
public Command findCommand(String name) { public Command findCommand(String name) {
Optional<Command> commandOptional = commands.stream().filter((Command o )-> { Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
CommandConfiguration commandConfiguration = o.getConfiguration(); CommandConfiguration commandConfiguration = o.getConfiguration();

View File

@@ -3,7 +3,6 @@ package dev.sheldan.abstracto.command.execution;
import dev.sheldan.abstracto.command.HelpInfo; import dev.sheldan.abstracto.command.HelpInfo;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import java.util.List; import java.util.List;
@@ -14,6 +13,7 @@ public class CommandConfiguration {
private String module; private String module;
private String description; private String description;
private List<Parameter> parameters; private List<Parameter> parameters;
private List<String> aliases;
private boolean causesReaction; private boolean causesReaction;
private boolean templated; private boolean templated;
private HelpInfo help; private HelpInfo help;

View File

@@ -34,9 +34,11 @@ public class AddToChannelGroup implements Command {
Parameter channelGroupName = Parameter.builder().name("name").type(String.class).description("The name of the channel group to add the channel to.").build(); Parameter channelGroupName = Parameter.builder().name("name").type(String.class).description("The name of the channel group to add the channel to.").build();
Parameter channelToAdd = Parameter.builder().name("channel").type(TextChannel.class).description("The mention of the channel to add to the group.").build(); Parameter channelToAdd = Parameter.builder().name("channel").type(TextChannel.class).description("The mention of the channel to add to the group.").build();
List<Parameter> parameters = Arrays.asList(channelGroupName, channelToAdd); List<Parameter> parameters = Arrays.asList(channelGroupName, channelToAdd);
List<String> aliases = Arrays.asList("addTChGrp", "chGrpCh+");
return CommandConfiguration.builder() return CommandConfiguration.builder()
.name("addToChannelGroup") .name("addToChannelGroup")
.module("channels") .module("channels")
.aliases(aliases)
.parameters(parameters) .parameters(parameters)
.description("Adds the mentioned channel to the channel group.") .description("Adds the mentioned channel to the channel group.")
.causesReaction(true) .causesReaction(true)

View File

@@ -34,9 +34,11 @@ public class RemoveFromChannelGroup implements Command {
Parameter channelGroupName = Parameter.builder().name("name").type(String.class).description("The name of the channel group to remove the channel from.").build(); Parameter channelGroupName = Parameter.builder().name("name").type(String.class).description("The name of the channel group to remove the channel from.").build();
Parameter channelToAdd = Parameter.builder().name("channel").type(TextChannel.class).description("The mention of the channel to remove from the group.").build(); Parameter channelToAdd = Parameter.builder().name("channel").type(TextChannel.class).description("The mention of the channel to remove from the group.").build();
List<Parameter> parameters = Arrays.asList(channelGroupName, channelToAdd); List<Parameter> parameters = Arrays.asList(channelGroupName, channelToAdd);
List<String> aliases = Arrays.asList("rmChChgrp", "chGrpCh-");
return CommandConfiguration.builder() return CommandConfiguration.builder()
.name("removeFromChannelGroup") .name("removeFromChannelGroup")
.module("channels") .module("channels")
.aliases(aliases)
.parameters(parameters) .parameters(parameters)
.description("Removes the mentioned channel from the channel group.") .description("Removes the mentioned channel from the channel group.")
.causesReaction(true) .causesReaction(true)