Compare commits
No commits in common. "bae077654ed1bc7838f23fa25de02d8675970909" and "432cf78a2e19cf555f76d4a4b171a2b096d004d3" have entirely different histories.
bae077654e
...
432cf78a2e
@ -95,10 +95,6 @@ public class SlashCommandDefinition {
|
|||||||
return this.rootIdentifier().equals(other.rootIdentifier());
|
return this.rootIdentifier().equals(other.rootIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[] serverIds() {
|
|
||||||
return rootIdentifier().serverIds();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<InteractionIdentifier> entries() {
|
public Set<InteractionIdentifier> entries() {
|
||||||
return this.entries;
|
return this.entries;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.tomatentum.marinara.registry;
|
package net.tomatentum.marinara.registry;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -13,10 +13,9 @@ import net.tomatentum.marinara.Marinara;
|
|||||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||||
import net.tomatentum.marinara.interaction.InteractionType;
|
import net.tomatentum.marinara.interaction.InteractionType;
|
||||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
|
||||||
import net.tomatentum.marinara.interaction.ident.RootCommandIdentifier;
|
import net.tomatentum.marinara.interaction.ident.RootCommandIdentifier;
|
||||||
|
import net.tomatentum.marinara.interaction.ident.SlashCommandIdentifier;
|
||||||
import net.tomatentum.marinara.util.LoggerUtil;
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
import net.tomatentum.marinara.util.ObjectAggregator;
|
|
||||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||||
import net.tomatentum.marinara.interaction.methods.InteractionMethod;
|
import net.tomatentum.marinara.interaction.methods.InteractionMethod;
|
||||||
|
|
||||||
@ -52,19 +51,26 @@ public class InteractionRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommands() {
|
public void registerCommands() {
|
||||||
List<InteractionIdentifier> slashIdentifiers = interactions.stream()
|
List<SlashCommandDefinition> defs = new ArrayList<>();
|
||||||
|
List<SlashCommandIdentifier> slashIdentifiers = interactions.stream()
|
||||||
.filter((x) -> x.type().equals(InteractionType.COMMAND))
|
.filter((x) -> x.type().equals(InteractionType.COMMAND))
|
||||||
.map((x) -> x.identifier())
|
.map((x) -> (SlashCommandIdentifier)x.identifier())
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
SlashCommandDefinition[] defs = new ObjectAggregator<InteractionIdentifier, RootCommandIdentifier, SlashCommandDefinition>(
|
slashIdentifiers.forEach((ident) -> {
|
||||||
i -> Arrays.asList((RootCommandIdentifier)i.rootNode()),
|
Optional<SlashCommandDefinition> appDef = defs.stream()
|
||||||
SlashCommandDefinition::addIdentifier,
|
.filter((x) -> x.rootIdentifier().equals(ident.rootNode()))
|
||||||
SlashCommandDefinition::new)
|
.findFirst();
|
||||||
.aggregate(slashIdentifiers)
|
|
||||||
.toArray(SlashCommandDefinition[]::new);
|
|
||||||
|
|
||||||
marinara.getWrapper().getRegisterer().register(defs);
|
if (appDef.isPresent())
|
||||||
|
appDef.get().addIdentifier(ident);
|
||||||
|
else
|
||||||
|
defs.add(
|
||||||
|
new SlashCommandDefinition((RootCommandIdentifier) ident.rootNode())
|
||||||
|
.addIdentifier(ident));
|
||||||
|
});
|
||||||
|
|
||||||
|
marinara.getWrapper().registerSlashCommands(defs.toArray(SlashCommandDefinition[]::new));
|
||||||
logger.info("Registered all SlashCommands");
|
logger.info("Registered all SlashCommands");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package net.tomatentum.marinara.util;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class ObjectAggregator<O, K, V> {
|
|
||||||
private Function<O, Iterable<K>> keySupplier;
|
|
||||||
private BiConsumer<V, O> valueConsumer;
|
|
||||||
private Function<K, V> defaultGenerator;
|
|
||||||
|
|
||||||
public ObjectAggregator(
|
|
||||||
Function<O, Iterable<K>> keySupplier,
|
|
||||||
BiConsumer<V, O> valueConsumer,
|
|
||||||
Function<K, V> defaultGenerator) {
|
|
||||||
this.keySupplier = keySupplier;
|
|
||||||
this.valueConsumer = valueConsumer;
|
|
||||||
this.defaultGenerator = defaultGenerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectAggregator(
|
|
||||||
Function<O, Iterable<K>> keySupplier,
|
|
||||||
BiConsumer<V, O> valueConsumer,
|
|
||||||
Supplier<V> defaultGenerator) {
|
|
||||||
this.keySupplier = keySupplier;
|
|
||||||
this.valueConsumer = valueConsumer;
|
|
||||||
this.defaultGenerator = _ -> defaultGenerator.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<V> aggregate(Iterable<O> iterator) {
|
|
||||||
Map<K, V> map = new HashMap<>();
|
|
||||||
for (O element : iterator) {
|
|
||||||
Iterable<K> keys = this.keySupplier.apply(element);
|
|
||||||
for (K key : keys) {
|
|
||||||
V value = map.getOrDefault(key, this.defaultGenerator.apply(key));
|
|
||||||
this.valueConsumer.accept(value, element);
|
|
||||||
map.putIfAbsent(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package net.tomatentum.marinara.util;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class ObjectListAggregator<O, K, V> extends ObjectAggregator<O, K, ArrayList<V>> {
|
|
||||||
|
|
||||||
public ObjectListAggregator(Function<O, Iterable<K>> keySupplier, Function<O, V> valueConsumer) {
|
|
||||||
super(keySupplier,
|
|
||||||
(l, o) -> l.add(valueConsumer.apply(o)),
|
|
||||||
() -> new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package net.tomatentum.marinara.wrapper;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
|
||||||
import net.tomatentum.marinara.util.ObjectAggregator;
|
|
||||||
|
|
||||||
public class CommandRegisterer<A extends Object> {
|
|
||||||
|
|
||||||
public static <A extends Object> CommandRegisterer<A> of(Strategy<A> strategy, CommandConverter<A, ?, ?> converter) {
|
|
||||||
return new CommandRegisterer<A>(strategy, converter);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Strategy<A> strategy;
|
|
||||||
private CommandConverter<A, ?, ?> converter;
|
|
||||||
|
|
||||||
CommandRegisterer(Strategy<A> strategy, CommandConverter<A, ?, ?> converter) {
|
|
||||||
this.strategy = strategy;
|
|
||||||
this.converter = converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(SlashCommandDefinition[] slashDefs) {
|
|
||||||
Set<ServerCommandList<A>> serverCommands = new ObjectAggregator<SlashCommandDefinition, Long, ServerCommandList<A>>(
|
|
||||||
def -> Arrays.stream(def.serverIds()).boxed().toList(),
|
|
||||||
(l, o) -> l.add(converter.convert(o)),
|
|
||||||
ServerCommandList::new)
|
|
||||||
.aggregate(Arrays.asList(slashDefs)).stream()
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
Set<A> globalCommands = Arrays.stream(slashDefs)
|
|
||||||
.filter(x -> x.serverIds().length <= 0)
|
|
||||||
.map(converter::convert)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
serverCommands.forEach(strategy::registerServer);
|
|
||||||
strategy.registerGlobal(globalCommands);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Strategy<A extends Object> {
|
|
||||||
void registerServer(ServerCommandList<A> commands);
|
|
||||||
void registerGlobal(Set<A> defs);
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,9 @@ package net.tomatentum.marinara.wrapper;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||||
|
|
||||||
public abstract class LibraryWrapper {
|
public abstract class LibraryWrapper {
|
||||||
|
|
||||||
private List<Consumer<Object>> interactionSubscriber;
|
private List<Consumer<Object>> interactionSubscriber;
|
||||||
@ -22,7 +25,8 @@ public abstract class LibraryWrapper {
|
|||||||
interactionSubscriber.remove(consumer);
|
interactionSubscriber.remove(consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract CommandRegisterer<?> getRegisterer();
|
public abstract void registerSlashCommands(SlashCommandDefinition[] defs);
|
||||||
|
|
||||||
public abstract IdentifierProvider createIdentifierProvider();
|
public abstract IdentifierProvider createIdentifierProvider();
|
||||||
public abstract ContextObjectProvider getContextObjectProvider();
|
public abstract ContextObjectProvider getContextObjectProvider();
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package net.tomatentum.marinara.wrapper;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class ServerCommandList<A> extends HashSet<A>{
|
|
||||||
|
|
||||||
private long serverId;
|
|
||||||
|
|
||||||
public ServerCommandList(long serverId) {
|
|
||||||
this.serverId = serverId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long serverId() {
|
|
||||||
return serverId;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package net.tomatentum.marinara.wrapper.discord4j;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import discord4j.core.GatewayDiscordClient;
|
|
||||||
import discord4j.discordjson.json.ApplicationCommandRequest;
|
|
||||||
import discord4j.rest.service.ApplicationService;
|
|
||||||
import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
|
||||||
import net.tomatentum.marinara.wrapper.ServerCommandList;
|
|
||||||
|
|
||||||
public class Discord4JRegistererStrategy implements CommandRegisterer.Strategy<ApplicationCommandRequest> {
|
|
||||||
|
|
||||||
private ApplicationService appService;
|
|
||||||
private long applicationId;
|
|
||||||
|
|
||||||
public Discord4JRegistererStrategy(GatewayDiscordClient api) {
|
|
||||||
this.appService = api.getRestClient().getApplicationService();
|
|
||||||
this.applicationId = api.getRestClient().getApplicationId().block();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerServer(ServerCommandList<ApplicationCommandRequest> commands) {
|
|
||||||
appService.bulkOverwriteGuildApplicationCommand(applicationId, commands.serverId(), new ArrayList<>(commands));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerGlobal(Set<ApplicationCommandRequest> defs) {
|
|
||||||
appService.bulkOverwriteGlobalApplicationCommand(applicationId, new ArrayList<>(defs));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,7 @@
|
|||||||
package net.tomatentum.marinara.wrapper.discord4j;
|
package net.tomatentum.marinara.wrapper.discord4j;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@ -9,11 +11,13 @@ import discord4j.core.GatewayDiscordClient;
|
|||||||
import discord4j.core.event.domain.interaction.InteractionCreateEvent;
|
import discord4j.core.event.domain.interaction.InteractionCreateEvent;
|
||||||
import discord4j.core.object.command.ApplicationCommandInteractionOption;
|
import discord4j.core.object.command.ApplicationCommandInteractionOption;
|
||||||
import discord4j.core.object.command.ApplicationCommandOption.Type;
|
import discord4j.core.object.command.ApplicationCommandOption.Type;
|
||||||
|
import discord4j.discordjson.json.ApplicationCommandOptionChoiceData;
|
||||||
|
import discord4j.discordjson.json.ApplicationCommandOptionData;
|
||||||
import discord4j.discordjson.json.ApplicationCommandRequest;
|
import discord4j.discordjson.json.ApplicationCommandRequest;
|
||||||
|
|
||||||
|
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||||
import net.tomatentum.marinara.util.LoggerUtil;
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
import net.tomatentum.marinara.wrapper.CommandConverter;
|
import net.tomatentum.marinara.wrapper.CommandConverter;
|
||||||
import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
|
||||||
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
||||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||||
@ -33,15 +37,16 @@ public class Discord4JWrapper extends LibraryWrapper {
|
|||||||
.filter(o -> !o.getType().equals(Type.SUB_COMMAND) && !o.getType().equals(Type.SUB_COMMAND_GROUP))
|
.filter(o -> !o.getType().equals(Type.SUB_COMMAND) && !o.getType().equals(Type.SUB_COMMAND_GROUP))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
private GatewayDiscordClient api;
|
||||||
private Discord4JContextObjectProvider contextObjectProvider;
|
private Discord4JContextObjectProvider contextObjectProvider;
|
||||||
private CommandRegisterer<ApplicationCommandRequest> commandRegisterer;
|
private CommandConverter<ApplicationCommandRequest, ApplicationCommandOptionData, ApplicationCommandOptionChoiceData> commandConverter;
|
||||||
|
|
||||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||||
|
|
||||||
public Discord4JWrapper(GatewayDiscordClient api) {
|
public Discord4JWrapper(GatewayDiscordClient api) {
|
||||||
|
this.api = api;
|
||||||
this.contextObjectProvider = new Discord4JContextObjectProvider();
|
this.contextObjectProvider = new Discord4JContextObjectProvider();
|
||||||
var converter = CommandConverter.of(new Discord4JConverterSpec());
|
this.commandConverter = CommandConverter.of(new Discord4JConverterSpec());
|
||||||
this.commandRegisterer = CommandRegisterer.of(new Discord4JRegistererStrategy(api), converter);
|
|
||||||
|
|
||||||
if (api != null)
|
if (api != null)
|
||||||
api.on(InteractionCreateEvent.class)
|
api.on(InteractionCreateEvent.class)
|
||||||
@ -53,8 +58,26 @@ public class Discord4JWrapper extends LibraryWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandRegisterer<?> getRegisterer() {
|
public void registerSlashCommands(SlashCommandDefinition[] defs) {
|
||||||
return this.commandRegisterer;
|
HashMap<Long, List<ApplicationCommandRequest>> serverCommands = new HashMap<>();
|
||||||
|
List<ApplicationCommandRequest> globalCommands = new ArrayList<>();
|
||||||
|
long applicationId = api.getRestClient().getApplicationId().block();
|
||||||
|
|
||||||
|
for (SlashCommandDefinition slashCommandDefinition : defs) {
|
||||||
|
ApplicationCommandRequest request = this.commandConverter.convert(slashCommandDefinition);
|
||||||
|
if (slashCommandDefinition.rootIdentifier().serverIds().length > 0) {
|
||||||
|
for (long serverId : slashCommandDefinition.rootIdentifier().serverIds()) {
|
||||||
|
serverCommands.putIfAbsent(serverId, new ArrayList<>());
|
||||||
|
serverCommands.get(serverId).add(request);
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
globalCommands.add(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (long serverId : serverCommands.keySet()) {
|
||||||
|
api.getRestClient().getApplicationService().bulkOverwriteGuildApplicationCommand(applicationId, serverId, serverCommands.get(serverId));
|
||||||
|
}
|
||||||
|
api.getRestClient().getApplicationService().bulkOverwriteGlobalApplicationCommand(applicationId, globalCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
package net.tomatentum.marinara.wrapper.javacord;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.javacord.api.DiscordApi;
|
|
||||||
import org.javacord.api.interaction.SlashCommandBuilder;
|
|
||||||
|
|
||||||
import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
|
||||||
import net.tomatentum.marinara.wrapper.ServerCommandList;
|
|
||||||
|
|
||||||
public class JavacordRegistererStrategy implements CommandRegisterer.Strategy<SlashCommandBuilder> {
|
|
||||||
|
|
||||||
private DiscordApi api;
|
|
||||||
|
|
||||||
public JavacordRegistererStrategy(DiscordApi api) {
|
|
||||||
this.api = api;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerServer(ServerCommandList<SlashCommandBuilder> commands) {
|
|
||||||
api.bulkOverwriteServerApplicationCommands(commands.serverId(), commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerGlobal(Set<SlashCommandBuilder> defs) {
|
|
||||||
api.bulkOverwriteGlobalApplicationCommands(defs);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +1,17 @@
|
|||||||
package net.tomatentum.marinara.wrapper.javacord;
|
package net.tomatentum.marinara.wrapper.javacord;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.javacord.api.DiscordApi;
|
import org.javacord.api.DiscordApi;
|
||||||
import org.javacord.api.interaction.SlashCommandBuilder;
|
import org.javacord.api.interaction.SlashCommandBuilder;
|
||||||
|
import org.javacord.api.interaction.SlashCommandOption;
|
||||||
|
import org.javacord.api.interaction.SlashCommandOptionChoice;
|
||||||
|
|
||||||
|
import net.tomatentum.marinara.interaction.commands.SlashCommandDefinition;
|
||||||
import net.tomatentum.marinara.wrapper.CommandConverter;
|
import net.tomatentum.marinara.wrapper.CommandConverter;
|
||||||
import net.tomatentum.marinara.wrapper.CommandRegisterer;
|
|
||||||
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
import net.tomatentum.marinara.wrapper.ContextObjectProvider;
|
||||||
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
import net.tomatentum.marinara.wrapper.IdentifierProvider;
|
||||||
import net.tomatentum.marinara.util.LoggerUtil;
|
import net.tomatentum.marinara.util.LoggerUtil;
|
||||||
@ -16,15 +22,16 @@ import net.tomatentum.marinara.wrapper.javacord.identifierconverter.SlashCommand
|
|||||||
|
|
||||||
public class JavacordWrapper extends LibraryWrapper {
|
public class JavacordWrapper extends LibraryWrapper {
|
||||||
|
|
||||||
|
private DiscordApi api;
|
||||||
private JavacordContextObjectProvider contextObjectProvider;
|
private JavacordContextObjectProvider contextObjectProvider;
|
||||||
private CommandRegisterer<SlashCommandBuilder> commandRegisterer;
|
private CommandConverter<SlashCommandBuilder, SlashCommandOption, SlashCommandOptionChoice> commandConverter;
|
||||||
|
|
||||||
private Logger logger = LoggerUtil.getLogger(getClass());
|
private Logger logger = LoggerUtil.getLogger(getClass());
|
||||||
|
|
||||||
public JavacordWrapper(DiscordApi api) {
|
public JavacordWrapper(DiscordApi api) {
|
||||||
|
this.api = api;
|
||||||
this.contextObjectProvider = new JavacordContextObjectProvider();
|
this.contextObjectProvider = new JavacordContextObjectProvider();
|
||||||
var converter = CommandConverter.of(new JavacordConverterSpec());
|
this.commandConverter = CommandConverter.of(new JavacordConverterSpec());
|
||||||
this.commandRegisterer = CommandRegisterer.of(new JavacordRegistererStrategy(api), converter);
|
|
||||||
|
|
||||||
if (api != null)
|
if (api != null)
|
||||||
api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction()));
|
api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction()));
|
||||||
@ -34,8 +41,24 @@ public class JavacordWrapper extends LibraryWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandRegisterer<?> getRegisterer() {
|
public void registerSlashCommands(SlashCommandDefinition[] defs) {
|
||||||
return this.commandRegisterer;
|
HashMap<Long, Set<SlashCommandBuilder>> serverCommands = new HashMap<>();
|
||||||
|
Set<SlashCommandBuilder> globalCommands = new HashSet<>();
|
||||||
|
for (SlashCommandDefinition slashCommandDefinition : defs) {
|
||||||
|
SlashCommandBuilder builder = commandConverter.convert(slashCommandDefinition);
|
||||||
|
if (slashCommandDefinition.rootIdentifier().serverIds().length > 0) {
|
||||||
|
for (long serverId : slashCommandDefinition.rootIdentifier().serverIds()) {
|
||||||
|
serverCommands.putIfAbsent(serverId, new HashSet<>());
|
||||||
|
serverCommands.get(serverId).add(builder);
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
globalCommands.add(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (long serverId : serverCommands.keySet()) {
|
||||||
|
api.bulkOverwriteServerApplicationCommands(serverId, serverCommands.get(serverId));
|
||||||
|
}
|
||||||
|
api.bulkOverwriteGlobalApplicationCommands(globalCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user