diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java index 39835bac..51b82c19 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java @@ -24,6 +24,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; +import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; import net.dv8tion.jda.api.requests.RestAction; @@ -101,6 +102,19 @@ public void display(Message message) { paginate(message, 1); } + /** + * Begins pagination on page 1 displaying this by editing the provided {@link InteractionHook} + * + *

Starting on another page is available via + * {@link Paginator#paginate(InteractionHook, int) Paginator#paginate(InteractionHook, int)} + * + * @param hook + * The InteractionHook to display the Menu in + */ + public void display(InteractionHook hook) { + paginate(hook, 1); + } + /** * Begins pagination as a new {@link Message} in the provided {@link MessageChannel}, starting on whatever * page number is provided. @@ -133,6 +147,24 @@ else if (pageNum > embeds.size()) initialize(message.editMessage(msg), pageNum); } + /** + * Begins pagination displaying this by editing the provided + * {@link InteractionHook}, starting on whatever page number is provided. + * + * @param hook + * The InteractionHook to edit + * @param pageNum + * The page number to begin on + */ + public void paginate(InteractionHook hook, int pageNum) { + if(pageNum<1) + pageNum = 1; + else if (pageNum > embeds.size()) + pageNum = embeds.size(); + MessageEditData msg = renderPage(pageNum); + initialize(hook.editOriginal(msg), pageNum); + } + private void initialize(RestAction action, int pageNum) { action.queue(m -> { if (embeds.size() > 1) { diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java index 51f78188..e4ef1ca5 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java @@ -42,7 +42,9 @@ * the menu reactions corresponding to each button. * * @author John Grosh + * @deprecated In favor of ButtonTextMenu */ +@Deprecated public class ButtonMenu extends Menu { private final Color color; diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java index b1590521..811985ff 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java @@ -24,6 +24,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.exceptions.PermissionException; +import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; @@ -106,6 +107,19 @@ public void display(Message message) paginate(message, 1); } + /** + * Begins pagination on page 1 displaying this Pagination by editing the provided {@link InteractionHook} + * + *

Starting on another page is available via + * {@link Paginator#paginate(InteractionHook, int) Paginator#paginate(InteractionHook, int)} + * + * @param hook + * The InteractionHook to display the Menu in + */ + public void display(InteractionHook hook) { + paginate(hook, 1); + } + /** * Begins pagination as a new {@link net.dv8tion.jda.api.entities.Message Message} * in the provided {@link MessageChannel}, starting @@ -146,6 +160,24 @@ else if(pageNum > embeds.size()) initialize(message.editMessage(msg), pageNum); } + /** + * Begins pagination by editing the provided + * {@link InteractionHook}, starting on whatever page number is provided. + * + * @param hook + * The InteractionHook to edit + * @param pageNum + * The page number to begin on + */ + public void paginate(InteractionHook hook, int pageNum) { + if(pageNum < 1) + pageNum = 1; + else if (pageNum > embeds.size()) + pageNum = embeds.size(); + MessageEditData msg = renderPage(pageNum); + initialize(hook.editOriginal(msg), pageNum); + } + private void initialize(RestAction action, int pageNum) { action.queue(m -> { diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java index 1a52cfc4..b095d04d 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java @@ -54,7 +54,9 @@ * and {@link OrderedMenu.Builder#setCancel(Consumer)} methods. * * @author John Grosh + * @deprecated In favor of Select Menus native to Discord and JDA. */ +@Deprecated public class OrderedMenu extends Menu { private final Color color; diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java index 1dcee174..ab49e48e 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java @@ -35,6 +35,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.exceptions.PermissionException; +import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; @@ -140,6 +141,19 @@ public void display(Message message) paginate(message, 1); } + /** + * Begins pagination on page 1 displaying this Pagination by editing the provided {@link InteractionHook} + * + *

Starting on another page is available via + * {@link Paginator#paginate(InteractionHook, int) Paginator#paginate(InteractionHook, int)} + * + * @param hook + * The InteractionHook to display the Menu in + */ + public void display(InteractionHook hook) { + paginate(hook, 1); + } + /** * Begins pagination as a new {@link net.dv8tion.jda.api.entities.Message Message} * in the provided {@link MessageChannel}, starting @@ -180,6 +194,24 @@ else if (pageNum>pages) initialize(message.editMessage(msg), pageNum); } + /** + * Begins pagination displaying this Pagination by editing the provided + * {@link InteractionHook}, starting on whatever page number is provided. + * + * @param hook + * The InteractionHook to edit + * @param pageNum + * The page number to begin on + */ + public void paginate(InteractionHook hook, int pageNum) { + if(pageNum<1) + pageNum = 1; + else if (pageNum>pages) + pageNum = pages; + MessageEditData msg = renderPage(pageNum); + initialize(hook.editOriginal(msg), pageNum); + } + private void initialize(RestAction action, int pageNum) { action.queue(m -> { diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java index bc13dd3d..bbd41206 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java @@ -46,7 +46,9 @@ * using reactions and make selections. * * @author John Grosh + * @deprecated In favor of native Select Menus in Discord and JDA. */ +@Deprecated public class SelectionDialog extends Menu { private final List choices;