From b0abb423d39a20b47f9acfd56ca041a938dd09c0 Mon Sep 17 00:00:00 2001 From: tueem Date: Tue, 29 Oct 2024 23:20:19 +0100 Subject: [PATCH] add register impl --- .../wrapper/javacord/JavacordWrapper.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/wrapper/javacord/src/main/java/net/tomatentum/marinare/wrapper/javacord/JavacordWrapper.java b/wrapper/javacord/src/main/java/net/tomatentum/marinare/wrapper/javacord/JavacordWrapper.java index 57cb7de..41ae182 100644 --- a/wrapper/javacord/src/main/java/net/tomatentum/marinare/wrapper/javacord/JavacordWrapper.java +++ b/wrapper/javacord/src/main/java/net/tomatentum/marinare/wrapper/javacord/JavacordWrapper.java @@ -3,8 +3,10 @@ package net.tomatentum.marinare.wrapper.javacord; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Set; import org.javacord.api.DiscordApi; import org.javacord.api.interaction.SlashCommandBuilder; @@ -29,8 +31,23 @@ public class JavacordWrapper extends LibraryWrapper { @Override public void registerSlashCommands(SlashCommandDefinition[] defs) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'registerSlashCommands'"); + HashMap> serverCommands = new HashMap<>(); + Set globalCommands = new HashSet<>(); + for (SlashCommandDefinition slashCommandDefinition : defs) { + SlashCommandBuilder builder = convertSlashCommand(slashCommandDefinition); + if (slashCommandDefinition.getFullSlashCommand().serverIds().length > 0) { + for (long serverId : slashCommandDefinition.getFullSlashCommand().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