diff --git a/build.gradle b/build.gradle index 3e3799f..155c2de 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ allprojects { ext { dependencies { // Creates shortcuts to avoid repeating dependencies throughout modules - jda = { [group: 'net.dv8tion', name: 'JDA', version: "5.0.0-alpha.17"] } + jda = { [group: 'net.dv8tion', name: 'JDA', version: "5.0.2"] } logback = { [group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.11'] } reflections = { [group: 'org.reflections', name: 'reflections', version: '0.10.2'] } diff --git a/commands/src/main/java/me/anutley/jdautils/commands/CommandListener.java b/commands/src/main/java/me/anutley/jdautils/commands/CommandListener.java index 1136b57..a7f3b50 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/CommandListener.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/CommandListener.java @@ -7,7 +7,7 @@ import me.anutley.jdautils.commands.events.*; import me.anutley.jdautils.commands.text.TextCommand; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.StandardGuildMessageChannel; +import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel; import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; diff --git a/commands/src/main/java/me/anutley/jdautils/commands/SlashCommandManager.java b/commands/src/main/java/me/anutley/jdautils/commands/SlashCommandManager.java index 88030fd..7a53467 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/SlashCommandManager.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/SlashCommandManager.java @@ -5,7 +5,7 @@ import me.anutley.jdautils.commands.application.slash.SlashCommand; import me.anutley.jdautils.commands.application.slash.SlashCommandOption; import me.anutley.jdautils.commands.application.slash.annotations.JDASlashCommand; -import net.dv8tion.jda.api.entities.ChannelType; +import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.Command; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -148,7 +148,7 @@ public List getCommandData() { */ public SlashCommand getCommandFromEvent(SlashCommandInteractionEvent event) { - return this.commands.stream().filter(slashCommand -> slashCommand.getAnnotation().name().equals(event.getCommandPath())) + return this.commands.stream().filter(slashCommand -> slashCommand.getAnnotation().name().equals(event.getFullCommandName())) .findFirst() .orElse(null); } diff --git a/commands/src/main/java/me/anutley/jdautils/commands/application/slash/SlashCommand.java b/commands/src/main/java/me/anutley/jdautils/commands/application/slash/SlashCommand.java index 3645411..2e7cbf4 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/application/slash/SlashCommand.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/application/slash/SlashCommand.java @@ -4,7 +4,10 @@ import me.anutley.jdautils.commands.annotations.CommandMeta; import me.anutley.jdautils.commands.application.slash.annotations.JDASlashCommand; import me.anutley.jdautils.commands.events.SlashCommandEvent; -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.*; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; diff --git a/commands/src/main/java/me/anutley/jdautils/commands/application/slash/annotations/SlashOption.java b/commands/src/main/java/me/anutley/jdautils/commands/application/slash/annotations/SlashOption.java index 878eb88..7cacfc7 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/application/slash/annotations/SlashOption.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/application/slash/annotations/SlashOption.java @@ -1,6 +1,6 @@ package me.anutley.jdautils.commands.application.slash.annotations; -import net.dv8tion.jda.api.entities.ChannelType; +import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.interactions.commands.Command.Option; import net.dv8tion.jda.api.interactions.commands.OptionType; diff --git a/commands/src/main/java/me/anutley/jdautils/commands/events/CommandEvent.java b/commands/src/main/java/me/anutley/jdautils/commands/events/CommandEvent.java index d039993..f5b8fed 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/events/CommandEvent.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/events/CommandEvent.java @@ -3,8 +3,8 @@ import me.anutley.jdautils.commands.Command; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.GenericEvent; import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/me/anutley/jdautils/commands/events/MessageContextCommandEvent.java b/commands/src/main/java/me/anutley/jdautils/commands/events/MessageContextCommandEvent.java index 8e49ede..eba49dd 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/events/MessageContextCommandEvent.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/events/MessageContextCommandEvent.java @@ -3,8 +3,8 @@ import me.anutley.jdautils.commands.application.context.MessageContextCommand; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/me/anutley/jdautils/commands/events/SlashCommandEvent.java b/commands/src/main/java/me/anutley/jdautils/commands/events/SlashCommandEvent.java index 5fa6a25..94a6080 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/events/SlashCommandEvent.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/events/SlashCommandEvent.java @@ -3,11 +3,9 @@ import me.anutley.jdautils.commands.application.slash.SlashCommand; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.events.interaction.command.GenericContextInteractionEvent; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.interactions.Interaction; import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/me/anutley/jdautils/commands/events/TextCommandEvent.java b/commands/src/main/java/me/anutley/jdautils/commands/events/TextCommandEvent.java index 281c968..6565eff 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/events/TextCommandEvent.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/events/TextCommandEvent.java @@ -3,8 +3,8 @@ import me.anutley.jdautils.commands.text.TextCommand; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/me/anutley/jdautils/commands/events/UserContextCommandEvent.java b/commands/src/main/java/me/anutley/jdautils/commands/events/UserContextCommandEvent.java index 69a4b08..f56a46d 100644 --- a/commands/src/main/java/me/anutley/jdautils/commands/events/UserContextCommandEvent.java +++ b/commands/src/main/java/me/anutley/jdautils/commands/events/UserContextCommandEvent.java @@ -3,8 +3,8 @@ import me.anutley.jdautils.commands.application.context.UserContextCommand; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import org.jetbrains.annotations.Nullable; diff --git a/eventwaiter/src/main/java/me/anutley/jdautils/eventwaiter/EventWaiter.java b/eventwaiter/src/main/java/me/anutley/jdautils/eventwaiter/EventWaiter.java index b3b8609..eb70827 100644 --- a/eventwaiter/src/main/java/me/anutley/jdautils/eventwaiter/EventWaiter.java +++ b/eventwaiter/src/main/java/me/anutley/jdautils/eventwaiter/EventWaiter.java @@ -2,7 +2,7 @@ import net.dv8tion.jda.api.events.Event; import net.dv8tion.jda.api.events.GenericEvent; -import net.dv8tion.jda.api.events.ShutdownEvent; +import net.dv8tion.jda.api.events.session.ShutdownEvent; import net.dv8tion.jda.api.hooks.EventListener; import org.jetbrains.annotations.NotNull; diff --git a/examples/src/main/java/me/anutley/jdautils/examples/menus/MenuBot.java b/examples/src/main/java/me/anutley/jdautils/examples/menus/MenuBot.java index 0ff5bae..8900406 100644 --- a/examples/src/main/java/me/anutley/jdautils/examples/menus/MenuBot.java +++ b/examples/src/main/java/me/anutley/jdautils/examples/menus/MenuBot.java @@ -18,7 +18,7 @@ public static void main(String[] args) throws LoginException, InterruptedExcepti JDA jda = JDABuilder.createDefault(args[0]) .setEnabledIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_EMOJIS_AND_STICKERS, GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS) .addEventListeners(waiter) - .disableCache(CacheFlag.VOICE_STATE) + .disableCache(CacheFlag.VOICE_STATE, CacheFlag.SCHEDULED_EVENTS) .setMemberCachePolicy(MemberCachePolicy.ALL) .build(); diff --git a/examples/src/main/java/me/anutley/jdautils/examples/menus/MenuCommands.java b/examples/src/main/java/me/anutley/jdautils/examples/menus/MenuCommands.java index b8b21f6..4f11662 100644 --- a/examples/src/main/java/me/anutley/jdautils/examples/menus/MenuCommands.java +++ b/examples/src/main/java/me/anutley/jdautils/examples/menus/MenuCommands.java @@ -5,12 +5,13 @@ import me.anutley.jdautils.commands.application.slash.annotations.JDASlashCommand; import me.anutley.jdautils.commands.events.SlashCommandEvent; import me.anutley.jdautils.menus.ButtonMenu; -import me.anutley.jdautils.menus.SelectionMenu; +import me.anutley.jdautils.menus.StringSelectionMenu; import me.anutley.jdautils.menus.paginator.ButtonPaginator; -import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.buttons.Button; -import net.dv8tion.jda.api.interactions.components.selections.SelectMenu; +import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; import java.util.concurrent.TimeUnit; @@ -24,8 +25,8 @@ public void buttonPaginator(SlashCommandEvent event) { .setEventWaiter(MenuBot.waiter()) .setTimeout(20) .setUnits(TimeUnit.SECONDS) - .addPage(new MessageBuilder().setContent("test").build()) - .addPage(new MessageBuilder().setContent("test2").build()) + .addPage(new MessageCreateBuilder().setContent("test").build()) + .addPage(new MessageCreateBuilder().setContent("test2").build()) .build().show(event.getDiscordEvent()); } @@ -39,16 +40,26 @@ public void buttonMenu(SlashCommandEvent event) { Button.danger("cancel", "Cancel") )) .setAction(aEvent -> { + aEvent.deferEdit().queue(); + if (aEvent.getButton().getId().equals("confirm")) { - aEvent.getMessage().editMessage("Confirmed!").override(true).queue(); + aEvent.getMessage().editMessage(new MessageEditBuilder() + .setContent("Confirmed") + .setComponents() // clear confirm / deny buttons + .build()) + .queue(); // Do some things here } else if (aEvent.getButton().getId().equals("cancel")) { - aEvent.getMessage().editMessage("Cancelled!").override(true).queue(); + aEvent.getMessage().editMessage(new MessageEditBuilder() + .setContent("Cancelled") + .setComponents() // clear confirm / deny buttons + .build()) + .queue(); // Do some other stuff here } }) .setInitialMessage( - new MessageBuilder().setContent("Do you want to confirm or deny?").build() + new MessageCreateBuilder().setContent("Do you want to confirm or deny?").build() ) .setRecursive(false) .build() @@ -58,18 +69,16 @@ public void buttonMenu(SlashCommandEvent event) { @GuildCommand("833042350850441216") @JDASlashCommand(name = "select-menu", description = "A select menu!") public void selectMenu(SlashCommandEvent event) { - new SelectionMenu.Builder() + new StringSelectionMenu.Builder() .setEventWaiter(MenuBot.waiter()) .addActionRows(ActionRow.of( - SelectMenu.create("test") + StringSelectMenu.create("test") .addOption("Cool option 1", "Cool Option 1") .addOption("Even cooler option 2", "Even Cooler Option 2") .build() ) - ).setAction(aEvent -> { - aEvent.reply(aEvent.getUser().getName() + " picked " + aEvent.getValues()).queue(); - }) - .setInitialMessage(new MessageBuilder().setContent("test").build()) + ).setAction(aEvent -> aEvent.reply(aEvent.getUser().getName() + " picked " + aEvent.getValues()).queue()) + .setInitialMessage(new MessageCreateBuilder().setContent("test").build()) .setEphemeral(true) .build().show(event.getDiscordEvent()); } diff --git a/menus/src/main/java/me/anutley/jdautils/menus/ButtonMenu.java b/menus/src/main/java/me/anutley/jdautils/menus/ButtonMenu.java index 994f253..448efcf 100644 --- a/menus/src/main/java/me/anutley/jdautils/menus/ButtonMenu.java +++ b/menus/src/main/java/me/anutley/jdautils/menus/ButtonMenu.java @@ -1,14 +1,14 @@ package me.anutley.jdautils.menus; import me.anutley.jdautils.eventwaiter.EventWaiter; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import java.util.ArrayList; import java.util.Arrays; @@ -18,11 +18,11 @@ public class ButtonMenu extends Menu { - protected final Message initialMessage; + protected final MessageCreateData initialMessage; protected final Consumer action; protected final List actionRows; - public ButtonMenu(EventWaiter eventWaiter, List allowedUsers, List allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, Message initialMessage, Consumer action, List actionRows) { + public ButtonMenu(EventWaiter eventWaiter, List allowedUsers, List allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, MessageCreateData initialMessage, Consumer action, List actionRows) { super(eventWaiter, allowedUsers, allowedRoles, timeout, units, recursive, ephemeral); this.initialMessage = initialMessage; this.action = action; @@ -32,8 +32,8 @@ public ButtonMenu(EventWaiter eventWaiter, List allowedUsers, List a @Override public void show(MessageChannel channel) { channel.sendMessage( - new MessageBuilder(initialMessage) - .setActionRows(actionRows) + MessageCreateBuilder.from(initialMessage) + .setComponents(actionRows) .build() ).queue( success -> waitForClick(success.getIdLong()) @@ -43,8 +43,8 @@ public void show(MessageChannel channel) { @Override public void show(GenericCommandInteractionEvent event) { event.reply( - new MessageBuilder(initialMessage) - .setActionRows(actionRows) + MessageCreateBuilder.from(initialMessage) + .setComponents(actionRows) .build() ).setEphemeral(ephemeral).queue( success -> success.retrieveOriginal().queue(m -> waitForClick(m.getIdLong())) @@ -67,7 +67,7 @@ private void waitForClick(long messageId) { public static class Builder extends Menu.Builder { - protected Message initialMessage = null; + protected MessageCreateData initialMessage = null; protected Consumer action = null; protected List actionRows = new ArrayList<>(); @@ -75,7 +75,7 @@ public static class Builder extends Menu.Builder { public ButtonMenu build() { if (eventWaiter == null) throw new IllegalStateException("The Event Waiter must be set!"); - if (actionRows.size() == 0) throw new IllegalStateException("There must be at least one action row"); + if (actionRows.isEmpty()) throw new IllegalStateException("There must be at least one action row"); if (action == null) throw new IllegalStateException("There must be a callback action"); if (initialMessage == null) throw new IllegalStateException("There must be an initial message"); @@ -97,7 +97,7 @@ public ButtonMenu build() { * @param initialMessage Sets the initial message that should be sent with the components * @return Itself for chaining convenience */ - public Builder setInitialMessage(Message initialMessage) { + public Builder setInitialMessage(MessageCreateData initialMessage) { this.initialMessage = initialMessage; return this; } diff --git a/menus/src/main/java/me/anutley/jdautils/menus/Menu.java b/menus/src/main/java/me/anutley/jdautils/menus/Menu.java index ddb5a66..873fff0 100644 --- a/menus/src/main/java/me/anutley/jdautils/menus/Menu.java +++ b/menus/src/main/java/me/anutley/jdautils/menus/Menu.java @@ -2,9 +2,9 @@ import me.anutley.jdautils.eventwaiter.EventWaiter; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; import org.jetbrains.annotations.Nullable; diff --git a/menus/src/main/java/me/anutley/jdautils/menus/ReactionMenu.java b/menus/src/main/java/me/anutley/jdautils/menus/ReactionMenu.java index 2219e86..50ead76 100644 --- a/menus/src/main/java/me/anutley/jdautils/menus/ReactionMenu.java +++ b/menus/src/main/java/me/anutley/jdautils/menus/ReactionMenu.java @@ -1,14 +1,14 @@ package me.anutley.jdautils.menus; import me.anutley.jdautils.eventwaiter.EventWaiter; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import java.util.ArrayList; import java.util.Arrays; @@ -18,11 +18,11 @@ public class ReactionMenu extends Menu { - protected final Message initialMessage; + protected final MessageCreateData initialMessage; protected final Consumer action; protected final List reactions; - public ReactionMenu(EventWaiter eventWaiter, List allowedUsers, List allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, Message initialMessage, Consumer action, List reactions) { + public ReactionMenu(EventWaiter eventWaiter, List allowedUsers, List allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, MessageCreateData initialMessage, Consumer action, List reactions) { super(eventWaiter, allowedUsers, allowedRoles, timeout, units, recursive, ephemeral); this.initialMessage = initialMessage; this.action = action; @@ -31,7 +31,7 @@ public ReactionMenu(EventWaiter eventWaiter, List allowedUsers, List @Override public void show(MessageChannel channel) { - channel.sendMessage(new MessageBuilder(initialMessage).build()).queue( + channel.sendMessage(MessageCreateBuilder.from(initialMessage).build()).queue( message -> { reactions.forEach(r -> message.addReaction(Emoji.fromUnicode(r)).queue()); waitForClick(message.getIdLong()); @@ -42,7 +42,7 @@ public void show(MessageChannel channel) { @Override public void show(GenericCommandInteractionEvent event) { event.reply( - new MessageBuilder((initialMessage)) + MessageCreateBuilder.from((initialMessage)) .build() ).setEphemeral(ephemeral).queue( success -> success.retrieveOriginal().queue(m -> { @@ -69,7 +69,7 @@ private void waitForClick(long messageId) { public static class Builder extends Menu.Builder { - protected Message initialMessage = null; + protected MessageCreateData initialMessage = null; protected Consumer action = null; protected List reactions = new ArrayList<>(); @@ -99,7 +99,7 @@ public ReactionMenu build() { * @param initialMessage Sets the initial message that should be sent with the components * @return Itself for chaining convenience */ - public Builder setInitialMessage(Message initialMessage) { + public Builder setInitialMessage(MessageCreateData initialMessage) { this.initialMessage = initialMessage; return this; } diff --git a/menus/src/main/java/me/anutley/jdautils/menus/SelectionMenu.java b/menus/src/main/java/me/anutley/jdautils/menus/StringSelectionMenu.java similarity index 69% rename from menus/src/main/java/me/anutley/jdautils/menus/SelectionMenu.java rename to menus/src/main/java/me/anutley/jdautils/menus/StringSelectionMenu.java index 12786eb..2194148 100644 --- a/menus/src/main/java/me/anutley/jdautils/menus/SelectionMenu.java +++ b/menus/src/main/java/me/anutley/jdautils/menus/StringSelectionMenu.java @@ -1,14 +1,14 @@ package me.anutley.jdautils.menus; import me.anutley.jdautils.eventwaiter.EventWaiter; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; -import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent; +import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent; import net.dv8tion.jda.api.interactions.components.ActionRow; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import java.util.ArrayList; import java.util.Arrays; @@ -16,14 +16,14 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -public class SelectionMenu extends Menu { +// TODO implement other types of select menu or make this generic +public class StringSelectionMenu extends Menu { - - protected final Message initialMessage; - protected final Consumer action; + protected final MessageCreateData initialMessage; + protected final Consumer action; protected final List actionRows; - public SelectionMenu(EventWaiter eventWaiter, List allowedUsers, List allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, Message initialMessage, Consumer action, List actionRows) { + public StringSelectionMenu(EventWaiter eventWaiter, List allowedUsers, List allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, MessageCreateData initialMessage, Consumer action, List actionRows) { super(eventWaiter, allowedUsers, allowedRoles, timeout, units, recursive, ephemeral); this.initialMessage = initialMessage; this.action = action; @@ -32,8 +32,8 @@ public SelectionMenu(EventWaiter eventWaiter, List allowedUsers, List waitForClick(success.getIdLong()) ); @@ -42,8 +42,8 @@ public void show(MessageChannel channel) { @Override public void show(GenericCommandInteractionEvent event) { event.reply( - new MessageBuilder(initialMessage) - .setActionRows(actionRows) + MessageCreateBuilder.from(initialMessage) + .setComponents(actionRows) .build() ).setEphemeral(ephemeral).queue( success -> success.retrieveOriginal().queue(m -> waitForClick(m.getIdLong())) @@ -52,7 +52,7 @@ public void show(GenericCommandInteractionEvent event) { private void waitForClick(long messageId) { eventWaiter.wait( - SelectMenuInteractionEvent.class, + StringSelectInteractionEvent.class, event -> { action.accept(event); if (recursive) waitForClick(messageId); @@ -64,21 +64,21 @@ private void waitForClick(long messageId) { ); } - public static class Builder extends Menu.Builder { + public static class Builder extends Menu.Builder { - protected Message initialMessage = null; - protected Consumer action = null; + protected MessageCreateData initialMessage = null; + protected Consumer action = null; protected List actionRows = new ArrayList<>(); @Override - public SelectionMenu build() { + public StringSelectionMenu build() { if (eventWaiter == null) throw new IllegalStateException("The Event Waiter must be set!"); if (actionRows.size() == 0) throw new IllegalStateException("There must be at least one action row"); if (action == null) throw new IllegalStateException("There must be a callback action"); if (initialMessage == null) throw new IllegalStateException("There must be an initial message"); - return new SelectionMenu( + return new StringSelectionMenu( super.eventWaiter, super.allowedUsers, super.allowedRoles, @@ -96,7 +96,7 @@ public SelectionMenu build() { * @param initialMessage Sets the initial message that should be sent with the components * @return Itself for chaining convenience */ - public SelectionMenu.Builder setInitialMessage(Message initialMessage) { + public StringSelectionMenu.Builder setInitialMessage(MessageCreateData initialMessage) { this.initialMessage = initialMessage; return this; } @@ -105,7 +105,7 @@ public SelectionMenu.Builder setInitialMessage(Message initialMessage) { * @param action The consumer that will be accepted after a button is clicked * @return Itself for chaining convenience */ - public SelectionMenu.Builder setAction(Consumer action) { + public StringSelectionMenu.Builder setAction(Consumer action) { this.action = action; return this; } diff --git a/menus/src/main/java/me/anutley/jdautils/menus/paginator/ButtonPaginator.java b/menus/src/main/java/me/anutley/jdautils/menus/paginator/ButtonPaginator.java index ac19fc4..a3c1550 100644 --- a/menus/src/main/java/me/anutley/jdautils/menus/paginator/ButtonPaginator.java +++ b/menus/src/main/java/me/anutley/jdautils/menus/paginator/ButtonPaginator.java @@ -1,16 +1,19 @@ package me.anutley.jdautils.menus.paginator; import me.anutley.jdautils.eventwaiter.EventWaiter; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; +import net.dv8tion.jda.api.exceptions.ErrorHandler; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.buttons.Button; +import net.dv8tion.jda.api.requests.ErrorResponse; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import java.util.List; import java.util.concurrent.TimeUnit; @@ -20,13 +23,13 @@ */ public class ButtonPaginator extends Paginator