mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-22 13:14:12 +00:00
added ability to define aliases in the code
This commit is contained in:
@@ -26,7 +26,7 @@ public class CommandManager implements CommandRegistry {
|
||||
public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter) {
|
||||
Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
|
||||
CommandConfiguration commandConfiguration = o.getConfiguration();
|
||||
if(!commandConfiguration.getName().equalsIgnoreCase(name)) {
|
||||
if(!commandNameMatches(name, commandConfiguration)) {
|
||||
return false;
|
||||
}
|
||||
boolean parameterFit;
|
||||
@@ -49,6 +49,18 @@ public class CommandManager implements CommandRegistry {
|
||||
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) {
|
||||
Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
|
||||
CommandConfiguration commandConfiguration = o.getConfiguration();
|
||||
|
||||
@@ -3,7 +3,6 @@ package dev.sheldan.abstracto.command.execution;
|
||||
import dev.sheldan.abstracto.command.HelpInfo;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,6 +13,7 @@ public class CommandConfiguration {
|
||||
private String module;
|
||||
private String description;
|
||||
private List<Parameter> parameters;
|
||||
private List<String> aliases;
|
||||
private boolean causesReaction;
|
||||
private boolean templated;
|
||||
private HelpInfo help;
|
||||
|
||||
@@ -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 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<String> aliases = Arrays.asList("addTChGrp", "chGrpCh+");
|
||||
return CommandConfiguration.builder()
|
||||
.name("addToChannelGroup")
|
||||
.module("channels")
|
||||
.aliases(aliases)
|
||||
.parameters(parameters)
|
||||
.description("Adds the mentioned channel to the channel group.")
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -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 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<String> aliases = Arrays.asList("rmChChgrp", "chGrpCh-");
|
||||
return CommandConfiguration.builder()
|
||||
.name("removeFromChannelGroup")
|
||||
.module("channels")
|
||||
.aliases(aliases)
|
||||
.parameters(parameters)
|
||||
.description("Removes the mentioned channel from the channel group.")
|
||||
.causesReaction(true)
|
||||
|
||||
Reference in New Issue
Block a user