Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBrick authored Sep 7, 2023
2 parents 138e823 + a86d4de commit 1a1a078
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
*
* <p>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.
Expand Down Expand Up @@ -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<Message> action, int pageNum) {
action.queue(m -> {
if (embeds.size() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
*
* <p>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
Expand Down Expand Up @@ -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<Message> action, int pageNum)
{
action.queue(m -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
*
* <p>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
Expand Down Expand Up @@ -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<Message> action, int pageNum)
{
action.queue(m -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> choices;
Expand Down

0 comments on commit 1a1a078

Please sign in to comment.