Skip to content

Commit

Permalink
fix: fixed conflicts & updated things broken by changes in JDA
Browse files Browse the repository at this point in the history
feat: Added support for new select menu types
  • Loading branch information
seailz committed Oct 25, 2022
1 parent 65eb25b commit 9e12b4b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/seailz/jdaframework/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.GenericSelectMenuInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
import net.dv8tion.jda.api.hooks.EventListener;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu;

import javax.security.auth.login.LoginException;
import java.util.HashMap;
Expand All @@ -37,7 +39,7 @@ public class DiscordBot {
private static HashMap<String, Consumer<ButtonInteractionEvent>> buttonRegistry;

@Getter
private static HashMap<String, Consumer<SelectMenuInteractionEvent>> selectRegistry;
private static HashMap<String, Consumer<GenericSelectMenuInteractionEvent>> selectRegistry;

private String token;
private JDA jda;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/seailz/jdaframework/modals/Modal.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.GenericSelectMenuInteractionEvent;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
import net.dv8tion.jda.api.interactions.modals.ModalMapping;

Expand Down Expand Up @@ -72,7 +72,7 @@ public void open(Member member, SlashCommandInteractionEvent interaction) {
* @param member The member to show the modal to
* @param interaction The interaction to reply to
*/
public void open(Member member, SelectMenuInteractionEvent interaction) {
public void open(Member member, GenericSelectMenuInteractionEvent interaction) {
ModalManager.open(this, member, interaction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.GenericSelectMenuInteractionEvent;
import net.dv8tion.jda.api.interactions.Interaction;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
Expand Down Expand Up @@ -36,7 +36,7 @@ public static void open(Modal modal, Member member, Interaction interaction) {
components.add(component.apply(member));
});

net.dv8tion.jda.api.interactions.components.Modal.Builder jdaModal = net.dv8tion.jda.api.interactions.components.Modal.create(
net.dv8tion.jda.api.interactions.modals.Modal.Builder jdaModal = net.dv8tion.jda.api.interactions.modals.Modal.create(
modal.getId(), modal.getTitle()
);

Expand All @@ -50,8 +50,8 @@ public static void open(Modal modal, Member member, Interaction interaction) {
} else if (interaction instanceof ButtonInteractionEvent) {
ButtonInteractionEvent e = (ButtonInteractionEvent) interaction;
e.replyModal(jdaModal.build()).queue();
} else if (interaction instanceof SelectMenuInteractionEvent) {
SelectMenuInteractionEvent e = (SelectMenuInteractionEvent) interaction;
} else if (interaction instanceof GenericSelectMenuInteractionEvent) {
GenericSelectMenuInteractionEvent e = (GenericSelectMenuInteractionEvent) interaction;
e.replyModal(jdaModal.build()).queue();
} else
throw new IllegalStateException("Interaction is not a SlashCommandInteractionEvent, SelectMenuInteractionEvent or ButtonInteractionEvent");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.seailz.jdaframework.select;

import com.seailz.jdaframework.DiscordBot;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.GenericSelectMenuInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;

public class SelectMenuListener extends ListenerAdapter {
@Override
public void onSelectMenuInteraction(@NotNull SelectMenuInteractionEvent event) {
public void onGenericSelectMenuInteraction(@NotNull GenericSelectMenuInteractionEvent event) {
if (DiscordBot.getSelectRegistry().containsKey(event.getSelectMenu().getId())) {
DiscordBot.getSelectRegistry().get(event.getSelectMenu().getId()).accept(event);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.seailz.jdaframework.select;

import com.seailz.jdaframework.DiscordBot;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.GenericSelectMenuInteractionEvent;

import java.util.function.Consumer;

Expand All @@ -12,7 +12,7 @@ public class SelectMenuManager {
* @param id The id of the select menu
* @param onClick The action to perform when the select menu is interacted with
*/
public static void listen(String id, Consumer<SelectMenuInteractionEvent> onClick) {
public static void listen(String id, Consumer<GenericSelectMenuInteractionEvent> onClick) {
DiscordBot.getSelectRegistry().put(id, onClick);
}

Expand Down

0 comments on commit 9e12b4b

Please sign in to comment.