improve wrapper and general structure #16

Merged
tueem merged 23 commits from improve/structure into dev 2025-03-17 08:26:44 +00:00
2 changed files with 3 additions and 20 deletions
Showing only changes of commit e7c35d9308 - Show all commits

View File

@ -66,13 +66,13 @@ public class SlashCommandDefinition {
.map(x -> x.parent()) .map(x -> x.parent())
.toList(); .toList();
return InteractionIdentifier.distinct(subCommandGroups).toArray(SlashCommandIdentifier[]::new); return subCommandGroups.toArray(SlashCommandIdentifier[]::new);
} }
public SlashCommandIdentifier[] getSubCommands() { public SlashCommandIdentifier[] getSubCommands() {
if (isRootCommand) if (isRootCommand)
return null; return null;
return InteractionIdentifier.distinct(entries.stream().filter(x -> x.parent() instanceof RootCommandIdentifier).toList()).toArray(SlashCommandIdentifier[]::new); return entries.stream().filter(x -> x.parent() instanceof RootCommandIdentifier).toArray(SlashCommandIdentifier[]::new);
} }
public SlashCommandIdentifier[] getSubCommands(String groupName) { public SlashCommandIdentifier[] getSubCommands(String groupName) {
@ -84,7 +84,7 @@ public class SlashCommandDefinition {
.map(x -> x.parent().parent()) .map(x -> x.parent().parent())
.toList(); .toList();
return InteractionIdentifier.distinct(subCommands).toArray(SlashCommandIdentifier[]::new); return subCommands.toArray(SlashCommandIdentifier[]::new);
} }
@Override @Override

View File

@ -1,8 +1,5 @@
package net.tomatentum.marinara.interaction.ident; package net.tomatentum.marinara.interaction.ident;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import net.tomatentum.marinara.interaction.InteractionType; import net.tomatentum.marinara.interaction.InteractionType;
@ -38,20 +35,6 @@ public class InteractionIdentifier {
tryAddDescriptions(receiver.parent(), provider.parent()); tryAddDescriptions(receiver.parent(), provider.parent());
} }
/*
* TODO: Might not be the best solution. Propagating to future
* returns only one Identifier per name and takes the first present description
*/
public static Collection<InteractionIdentifier> distinct(List<InteractionIdentifier> identifiers) {
HashMap<String, InteractionIdentifier> distinctIdentifiers = new HashMap<>();
identifiers.forEach((x) -> {
InteractionIdentifier current = distinctIdentifiers.get(x.name());
if (current == null || (current.description().isBlank() && !x.description().isBlank()))
distinctIdentifiers.put(x.name(), x);
});
return distinctIdentifiers.values();
}
private InteractionIdentifier parent; private InteractionIdentifier parent;
private String name; private String name;
private String description; private String description;