ygimenez / Pagination-Utils

A collection of methods to make message pagination with JDA easier.
GNU Lesser General Public License v2.1
27 stars 7 forks source link

Fix paginations in DM channels #12

Closed p5nbTgip0r closed 3 years ago

p5nbTgip0r commented 3 years ago

After the release of 2.1.1 I was still encountering some issues using the library in a DM.

  1. As described in #9, I was experiencing the following error when a page is initialised for a message in a DM while using the timeout feature. 2.1.1 did not seem to fix this (as seen by the version in the jar name):
    java.lang.IllegalStateException: Cannot clear reactions from a message in a Group or PrivateChannel.
    at net.dv8tion.jda.internal.entities.ReceivedMessage.clearReactions(ReceivedMessage.java:175) ~[JDA-4.2.0_225.jar:4.2.0_225]
    at com.github.ygimenez.method.Pages$4.<init>(Pages.java:490) ~[Pagination-Utils-2.1.1.jar:na]
    at com.github.ygimenez.method.Pages.paginate(Pages.java:477) ~[Pagination-Utils-2.1.1.jar:na]
  2. Using the non-timeout paginate methods, I was able to get around this issue but if I had set .shouldRemoveOnReact(true) for the paginator builder then switching pages would only work when a user removed their reaction and then re-added their reaction.

In this PR I believe that I have fixed both of these issues. One thing I want to point out is that, in the Pages.java class, I noticed there were not many methods to cut down on duplicated code in the consumers. In order to maintain the style of the code I decided to create setTimeout() methods inside each consumer instead of making one method in the class and referring to that for all the consumers. If you would like me to change to using the latter style (one method that all the consumers use) I'm happy to change over to that.