[Utils] Improved class-based menu utilities #2809
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2809
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/better_menu"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I did a thing. All of these additions are best understood in the docs, which I have built here.
The old menu remains, however its usage in core is limited to the audio cog, for now. I've decided to leave audio alone this time around 😄
The docs build depends on #2806.i need to look closer at this part before merge
not a full review, just looking at parts right now based on a change to help as a result, im seeing a few things which dont look correct right now, but need to look in more depth to be sure arent.
@ -2,3 +1,1 @@# https://github.com/Lunar-Dust/Dusty-Cogs/blob/master/menu/menu.py## Ported to Red V3 by Palm\_\_ (https://github.com/palmtree5)"""This module provides utilities for assisting in sending common typeslogic here doesnt appear to pass the eye test. the if doesnt check that there arent emojis in constructer. this should determine the default. This should also probably use kwargs.pop with the use of super below
@ -2,3 +1,1 @@# https://github.com/Lunar-Dust/Dusty-Cogs/blob/master/menu/menu.py## Ported to Red V3 by Palm\_\_ (https://github.com/palmtree5)"""This module provides utilities for assisting in sending common typesThanks for pointing this out - should be fixed up now.
I think I need to do some minor tweaks on inheritance of handlers and the way that affects the initial reaction order. Will look into it soon.FixedI found a slight docs issue:
In the line where the role is added to the user (
await member.add_roles(role, "Adding reactrole")), the string is not casted to the reason argument, and is therefore interpreted by discord.py that it is a role, resulting in that eventually erroring and the embed not being deleted when the role is added.I have this code,
I noticed a problem where someone spams a button two times my event will trigger multiple times even though menu should exit and just take first event, is there any way I can avoid this or is this as designed? I have not touched exit_on_selection.
The only thing I edited is _after_timeout to pass rather than delete the menu on timeout.
@ -0,0 +62,4 @@async def _format_page(self) -> str:accounts = self._accounts[self._cur_rank : self._cur_rank + self.ENTRIES_PER_PAGE]bal_colwidth = len(str(accounts[0][1]["balance"])) + 5If there's exactly 10 people in the leaderboard this ends up with a IndexError when trying to view more pages.
@ -2,3 +1,1 @@# https://github.com/Lunar-Dust/Dusty-Cogs/blob/master/menu/menu.py## Ported to Red V3 by Palm\_\_ (https://github.com/palmtree5)"""This module provides utilities for assisting in sending common typesTo keep the typing this should be
Optional[float]since we can also passNoneas a valid type.I am also certain this will be a big topic for discussion as it already has been. Technically changing the default behavior to delete the message after 30 seconds of inactivity breaks all current cog creators expectations. While the default could be changed to
NoneI think leaving it forces cog creators to take a look at their code and simply add the optional timeout kwarg wherever they use menu if they want to change it. That said this will also break regular users expectations if they're not aware of the code and I could see them being upset that the bots messages are automatically deleting when the cog creator has not updated to use this new menu system yet.@ -2,3 +1,1 @@# https://github.com/Lunar-Dust/Dusty-Cogs/blob/master/menu/menu.py## Ported to Red V3 by Palm\_\_ (https://github.com/palmtree5)"""This module provides utilities for assisting in sending common typesYeah, I've talked to Draper about this and I will add another kwarg which changes the timeout action. The default will probably be clearing reactions (or removing the bot's reactions if permissions are missing), and the message deletion will probably be an option too.
This might slightly break expectations with the old menu, but I think it's an improvement. When the menu times out, it should give some sort of indication that the menu's no longer active. Removing reactions should be enough.
Something i found with
PagedOptionsMenuis that the Arrows are always avaliable, even when there's only 1 page, from the docs my understanding is thatarrows_alwaysshould be off by default, this is the code.Will this find its way into the v3.2 release?
Most likely not as it is still a work in progress. It isn't a breaking change so it could make it in 3.2.1.
The documentation and understanding how to subclass them are very easy. One issue I found, correct me if I am wrong but the old menu wouldn't delete itself after the timeout where this one deletes itself.
What I have done is I have added a delete_menu bool that is by default false and can be set to true to delete the menu after timeout. There is some scenarios where you would want a reaction timeout for GC purposes but would want the menu to still stay.
pagenum_in_footer is documented but not implemented.
Setting options_per_page=20 and then spawning the menu results in an error
This is due to it not taking in account the default reactions it adds as well.
propose we close this in favour of #4039
No backlash, #4039 has been merged.
So will be closing this PR, in favour of using d.py menus doing forward.
If you haven't seen d.py menus https://github.com/Cog-Creators/Red-DiscordBot/pull/4062 have some examples as well as https://ptb.discordapp.com/channels/133049272517001216/133251234164375552/731246605113753630 and https://github.com/Rapptz/discord-ext-menus
Pull request closed