Compare commits
3 Commits
bae077654e
...
e7c35d9308
Author | SHA1 | Date | |
---|---|---|---|
e7c35d9308 | |||
d4a91f3251 | |||
bce4ce7812 |
@ -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
|
||||||
|
@ -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;
|
||||||
@ -37,20 +34,6 @@ public class InteractionIdentifier {
|
|||||||
receiver.description = provider.description();
|
receiver.description = provider.description();
|
||||||
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;
|
||||||
|
@ -40,11 +40,12 @@ 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> entry = this.interactions.stream().filter(iMethod::equals).findFirst();
|
Optional<InteractionEntry> oentry = this.interactions.stream()
|
||||||
if (entry.isEmpty()) {
|
.filter(i -> i.identifier().equals(iMethod.identifier()))
|
||||||
interactions.add(new InteractionEntry(iMethod.identifier()).addMethod(iMethod));
|
.findFirst();
|
||||||
}else
|
|
||||||
entry.get().addMethod(iMethod);
|
InteractionEntry entry = oentry.orElse(new InteractionEntry(iMethod.identifier())).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