Compare commits
No commits in common. "e7c35d9308df60b6b6dd344b26e27cece3df0061" and "bae077654ed1bc7838f23fa25de02d8675970909" have entirely different histories.
e7c35d9308
...
bae077654e
@ -66,13 +66,13 @@ public class SlashCommandDefinition {
|
|||||||
.map(x -> x.parent())
|
.map(x -> x.parent())
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return subCommandGroups.toArray(SlashCommandIdentifier[]::new);
|
return InteractionIdentifier.distinct(subCommandGroups).toArray(SlashCommandIdentifier[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlashCommandIdentifier[] getSubCommands() {
|
public SlashCommandIdentifier[] getSubCommands() {
|
||||||
if (isRootCommand)
|
if (isRootCommand)
|
||||||
return null;
|
return null;
|
||||||
return entries.stream().filter(x -> x.parent() instanceof RootCommandIdentifier).toArray(SlashCommandIdentifier[]::new);
|
return InteractionIdentifier.distinct(entries.stream().filter(x -> x.parent() instanceof RootCommandIdentifier).toList()).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 subCommands.toArray(SlashCommandIdentifier[]::new);
|
return InteractionIdentifier.distinct(subCommands).toArray(SlashCommandIdentifier[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
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;
|
||||||
@ -35,6 +38,20 @@ 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;
|
||||||
|
@ -40,12 +40,11 @@ public class InteractionRegistry {
|
|||||||
for (Method method : interactionHandler.getClass().getMethods()) {
|
for (Method method : interactionHandler.getClass().getMethods()) {
|
||||||
InteractionMethod iMethod = InteractionMethod.create(method, interactionHandler, marinara);
|
InteractionMethod iMethod = InteractionMethod.create(method, interactionHandler, marinara);
|
||||||
if (iMethod != null) {
|
if (iMethod != null) {
|
||||||
Optional<InteractionEntry> oentry = this.interactions.stream()
|
Optional<InteractionEntry> entry = this.interactions.stream().filter(iMethod::equals).findFirst();
|
||||||
.filter(i -> i.identifier().equals(iMethod.identifier()))
|
if (entry.isEmpty()) {
|
||||||
.findFirst();
|
interactions.add(new InteractionEntry(iMethod.identifier()).addMethod(iMethod));
|
||||||
|
}else
|
||||||
InteractionEntry entry = oentry.orElse(new InteractionEntry(iMethod.identifier())).addMethod(iMethod);
|
entry.get().addMethod(iMethod);
|
||||||
if (oentry.isEmpty()) this.interactions.add(entry);
|
|
||||||
logger.debug("Added {} method from {}", iMethod.method().getName(), interactionHandler.getClass().getSimpleName());
|
logger.debug("Added {} method from {}", iMethod.method().getName(), interactionHandler.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ public class Discord4JWrapper extends LibraryWrapper {
|
|||||||
public Discord4JWrapper(GatewayDiscordClient api) {
|
public Discord4JWrapper(GatewayDiscordClient api) {
|
||||||
this.contextObjectProvider = new Discord4JContextObjectProvider();
|
this.contextObjectProvider = new Discord4JContextObjectProvider();
|
||||||
var converter = CommandConverter.of(new Discord4JConverterSpec());
|
var converter = CommandConverter.of(new Discord4JConverterSpec());
|
||||||
|
this.commandRegisterer = CommandRegisterer.of(new Discord4JRegistererStrategy(api), converter);
|
||||||
|
|
||||||
if (api != null) {
|
if (api != null)
|
||||||
this.commandRegisterer = CommandRegisterer.of(new Discord4JRegistererStrategy(api), converter);
|
|
||||||
api.on(InteractionCreateEvent.class)
|
api.on(InteractionCreateEvent.class)
|
||||||
.subscribe(event -> handleInteraction(event));
|
.subscribe(event -> handleInteraction(event));
|
||||||
}else
|
else
|
||||||
logger.warn("GatewayDiscordClient was null so no Events were subscribed to.");
|
logger.warn("GatewayDiscordClient was null so no Events were subscribed to.");
|
||||||
|
|
||||||
logger.info("Discord4J wrapper loaded!");
|
logger.info("Discord4J wrapper loaded!");
|
||||||
|
@ -24,11 +24,11 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
public JavacordWrapper(DiscordApi api) {
|
public JavacordWrapper(DiscordApi api) {
|
||||||
this.contextObjectProvider = new JavacordContextObjectProvider();
|
this.contextObjectProvider = new JavacordContextObjectProvider();
|
||||||
var converter = CommandConverter.of(new JavacordConverterSpec());
|
var converter = CommandConverter.of(new JavacordConverterSpec());
|
||||||
|
this.commandRegisterer = CommandRegisterer.of(new JavacordRegistererStrategy(api), converter);
|
||||||
|
|
||||||
if (api != null) {
|
if (api != null)
|
||||||
this.commandRegisterer = CommandRegisterer.of(new JavacordRegistererStrategy(api), converter);
|
|
||||||
api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction()));
|
api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction()));
|
||||||
}else
|
else
|
||||||
logger.warn("DiscordApi was null so no Events were subscribed to.");
|
logger.warn("DiscordApi was null so no Events were subscribed to.");
|
||||||
logger.info("Javacord wrapper loaded!");
|
logger.info("Javacord wrapper loaded!");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user