Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Clear buttons before sending if one page async iterator source #39

Merged

Conversation

DenverCoder1
Copy link
Collaborator

@DenverCoder1 DenverCoder1 commented May 26, 2022

Summary

There is a small issue with AsyncIterator page sources where if a menu requires only 1 page, the buttons will be created but then removed within a second. This happens because is_paginating is not able to determine if more than 1 page is needed until the first page is read. This will also apply to any custom page sources where the former applies. Currently the buttons are cleared in start(), after the menu has been sent.

This PR makes it so that the buttons are removed from the view after the page is read, but before it is sent so that it doesn't need to be edited afterwards.

Additionally, ButtonMenu.clear() was updated to only remove nextcord.ui.Button objects. This was done since it is what is already written in the docstring and is consistent with disable() and enable().

Changes

  • Moves the call to self.clear() into send_initial_message instead of start so that with async iterator page source, it will not send the buttons if there is only one page.

  • ButtonMenu.clear() was fixed to only clear buttons and not all items, and additionally not call message.edit if message is None.

  • For consistency and performance, ButtonMenu.disable() and ButtonMenu.enable() similarly will not edit the message if the view has not changed.

Potentially breaking

  • ButtonMenu.clear() will now only clear Buttons. The docstring for this method already said that it would clear Buttons, but the implementation has been changed to make it so that other types of items (eg. select menus) will no longer be removed.

  • If a user is overriding send_initial_message in a subclass of ButtonMenuPages and sends a pagination menu that only requires 1 page, the buttons may no longer be cleared since the clearing now only happens in the default implementation of ButtonMenuPages.send_initial_message.

Gifs

Before old
After old

Moves the call to clear into send_initial_message instead of start so that with async iterator page source, it will not send the buttons if there is only one page.

Menu.clear() was fixed to only clear buttons and not all items, and additionally not call message.edit if message is None.

For consistency and performance, ButtonMenu.disable() and ButtonMenu.enable() similarly will not edit the message if the view has not changed.
Copy link
Contributor

@Skelmis Skelmis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested but lgtm

@DenverCoder1 DenverCoder1 merged commit b505a20 into nextcord:master Jun 1, 2022
@DenverCoder1 DenverCoder1 deleted the fix-aips-one-page-and-clear branch June 1, 2022 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants