cleanup commands

This commit is contained in:
Lee
2024-06-27 19:36:52 +01:00
parent 3d39fd9784
commit f062fa21c3
35 changed files with 162 additions and 145 deletions

View File

@ -21,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @author Fascinated (fascinated7)
@ -61,11 +58,12 @@ public class CommandService extends ListenerAdapter {
* @param command The command to register
*/
public void registerCommand(@NonNull BatCommand command) {
if (commands.get(command.getName().toLowerCase()) != null) {
String commandName = command.getCommandInfo().name().toLowerCase();
if (commands.get(commandName) != null) {
return;
}
log.info("Registered command \"{}\"", command.getName());
commands.put(command.getName().toLowerCase(), command);
log.info("Registered command \"{}\"", command.getCommandInfo().name());
commands.put(commandName, command);
}
/**
@ -132,14 +130,14 @@ public class CommandService extends ListenerAdapter {
// No args provided, use the main command executor
if (event.getInteraction().getSubcommandName() == null) {
executor = command;
requiredPermissions.addAll(command.getRequiredPermissions());
requiredPermissions.addAll(Arrays.asList(command.getCommandInfo().requiredPermissions()));
} else {
// Subcommand provided, use the subcommand executor
for (Map.Entry<String, BatSubCommand> subCommand : command.getSubCommands().entrySet()) {
if (subCommand.getKey().equalsIgnoreCase(event.getInteraction().getSubcommandName())) {
executor = subCommand.getValue();
requiredPermissions.addAll(subCommand.getValue().getRequiredPermissions());
requiredPermissions.addAll(command.getRequiredPermissions()); // not sure if we'd want this, but it's here for now
requiredPermissions.addAll(Arrays.asList(subCommand.getValue().getCommandInfo().requiredPermissions()));
requiredPermissions.addAll(Arrays.asList(command.getCommandInfo().requiredPermissions())); // not sure if we'd want this, but it's here for now
break;
}
}