From 76d4d5b525ae3d8a8ec1710d6bc212d9422b5385 Mon Sep 17 00:00:00 2001 From: tueem Date: Tue, 5 Nov 2024 15:55:01 +0100 Subject: [PATCH] add Javacord impl --- .../wrapper/javacord/JavacordWrapper.java | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 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 dcc5af8..9811147 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 @@ -6,10 +6,13 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.javacord.api.DiscordApi; +import org.javacord.api.entity.channel.TextChannel; import org.javacord.api.interaction.ApplicationCommandInteraction; +import org.javacord.api.interaction.ButtonInteraction; import org.javacord.api.interaction.SlashCommandBuilder; import org.javacord.api.interaction.SlashCommandInteraction; import org.javacord.api.interaction.SlashCommandInteractionOption; @@ -35,6 +38,14 @@ public class JavacordWrapper extends LibraryWrapper { api.addInteractionCreateListener((e) -> handleInteraction(e.getInteraction())); } + @Override + public InteractionType getInteractionType(Class clazz) { + if (ApplicationCommandInteraction.class.isAssignableFrom(clazz)) + return InteractionType.COMMAND; + + return null; + } + @Override public void registerSlashCommands(SlashCommandDefinition[] defs) { HashMap> serverCommands = new HashMap<>(); @@ -56,14 +67,6 @@ public class JavacordWrapper extends LibraryWrapper { api.bulkOverwriteGlobalApplicationCommands(globalCommands); } - @Override - public InteractionType getInteractionType(Class clazz) { - if (ApplicationCommandInteraction.class.isAssignableFrom(clazz)) - return InteractionType.COMMAND; - - return null; - } - @Override public Object convertCommandOption(Object context, SlashCommandOptionType type, String optionName) { if (!(context instanceof SlashCommandInteraction)) @@ -156,4 +159,30 @@ public class JavacordWrapper extends LibraryWrapper { return null; } } + + @Override + public String getButtonId(Object context) { + ButtonInteraction button = (ButtonInteraction) context; + return button.getCustomId(); + } + + @Override + public Object getComponentContextObject(Object context, Class type) { + ButtonInteraction button = (ButtonInteraction) context; + switch (type.getName()) { + case "TextChannel": + return button.getChannel().orElse(null); + case "Message": + return button.getMessage(); + case "Server": + return button.getServer().orElse(null); + case "User": + return button.getUser(); + case "Member": + return button.getUser(); + } + return null; + } + + }