Compare commits
No commits in common. "76d4d5b525ae3d8a8ec1710d6bc212d9422b5385" and "11fd16fa778077fee23d1ba0ffb345baa46102cc" have entirely different histories.
76d4d5b525
...
11fd16fa77
@ -1,5 +0,0 @@
|
||||
package net.tomatentum.marinara.interaction.annotation;
|
||||
|
||||
public @interface Button {
|
||||
public String customId();
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package net.tomatentum.marinara.interaction.methods;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.tomatentum.marinara.interaction.InteractionHandler;
|
||||
import net.tomatentum.marinara.interaction.InteractionType;
|
||||
import net.tomatentum.marinara.interaction.annotation.Button;
|
||||
import net.tomatentum.marinara.wrapper.LibraryWrapper;
|
||||
|
||||
public class ButtonInteractionMethod extends InteractionMethod {
|
||||
|
||||
private String customId;
|
||||
|
||||
ButtonInteractionMethod(Method method, InteractionHandler handler, LibraryWrapper wrapper) {
|
||||
super(method, handler, wrapper);
|
||||
parseMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameter(Object parameter, int index) {
|
||||
Class<?> type = getMethod().getParameterTypes()[index];
|
||||
return wrapper.getComponentContextObject(parameter, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRun(Object context) {
|
||||
return wrapper.getButtonId(context).equals(customId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionType getType() {
|
||||
return InteractionType.BUTTON;
|
||||
}
|
||||
|
||||
private void parseMethod() {
|
||||
Button button = getMethod().getAnnotation(Button.class);
|
||||
this.customId = button.customId();
|
||||
}
|
||||
|
||||
}
|
@ -17,6 +17,7 @@ public abstract class LibraryWrapper {
|
||||
interactionSubscriber = new ArrayList<>();
|
||||
}
|
||||
|
||||
public abstract void registerSlashCommands(SlashCommandDefinition[] defs);
|
||||
|
||||
public void handleInteraction(Object context) {
|
||||
interactionSubscriber.forEach((o) -> o.accept(context));
|
||||
@ -30,11 +31,6 @@ public abstract class LibraryWrapper {
|
||||
}
|
||||
|
||||
public abstract InteractionType getInteractionType(Class<?> clazz);
|
||||
|
||||
public abstract void registerSlashCommands(SlashCommandDefinition[] defs);
|
||||
public abstract Object convertCommandOption(Object context, SlashCommandOptionType type, String optionName);
|
||||
public abstract ExecutableSlashCommandDefinition getCommandDefinition(Object context);
|
||||
|
||||
public abstract String getButtonId(Object context);
|
||||
public abstract Object getComponentContextObject(Object context, Class<?> type);
|
||||
}
|
@ -6,13 +6,10 @@ 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;
|
||||
@ -38,14 +35,6 @@ 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<Long, Set<SlashCommandBuilder>> serverCommands = new HashMap<>();
|
||||
@ -67,6 +56,14 @@ 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))
|
||||
@ -159,30 +156,4 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user