[Utils] Improved class-based menu utilities #2809

Closed
Tobotimus wants to merge 21 commits from V3/better_menu into V3/develop
Tobotimus commented 2019-06-27 11:06:35 +02:00 (Migrated from github.com)

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 did a thing. All of these additions are best understood in the docs, which I have built [here](https://red-discordbot-toby.readthedocs.io/en/v3-better_menu/framework_utils.html#module-redbot.core.utils.menus). 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 :smile: ~~The docs build depends on #2806.~~
palmtree5 (Migrated from github.com) reviewed 2019-06-27 11:06:35 +02:00
tekulvw (Migrated from github.com) reviewed 2019-06-27 11:06:35 +02:00
Twentysix26 (Migrated from github.com) reviewed 2019-06-27 11:06:35 +02:00
mikeshardmind (Migrated from github.com) reviewed 2019-06-27 12:37:07 +02:00
mikeshardmind (Migrated from github.com) commented 2019-06-27 12:36:44 +02:00

i need to look closer at this part before merge

i need to look closer at this part before merge
mikeshardmind (Migrated from github.com) reviewed 2019-06-27 13:38:11 +02:00
mikeshardmind (Migrated from github.com) left a comment

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.

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 types
mikeshardmind (Migrated from github.com) commented 2019-06-27 13:36:08 +02:00

logic 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

logic 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
Tobotimus (Migrated from github.com) reviewed 2019-06-27 14:27:06 +02:00
@ -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 types
Tobotimus (Migrated from github.com) commented 2019-06-27 14:27:06 +02:00

Thanks for pointing this out - should be fixed up now.

Thanks for pointing this out - should be fixed up now.
Tobotimus commented 2019-06-27 16:30:09 +02:00 (Migrated from github.com)

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. Fixed

~~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.~~ Fixed
NeuroAssassin commented 2019-08-06 17:51:07 +02:00 (Migrated from github.com)

I found a slight docs issue:

image
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 found a slight docs issue: ![image](https://user-images.githubusercontent.com/42872277/62555090-4ebdf380-b840-11e9-8dc3-4f1e5b913267.png) 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.
Stonedestroyer commented 2019-08-09 21:26:00 +02:00 (Migrated from github.com)

I have this code,

        async def fetchanime(user, selection):
            nonlocal number
            number = selection
            await self.id_lookup(ctx, cmd, number)

        menu_instance = await PagedOptionsMenu.send_and_wait(
            ctx,
            timeout=30,
            pagenum_in_footer=1,
            footer_text=f"Requested by: {str(ctx.author)}",
            options=animelist,
            callback=fetchanime,
        )

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.

I have this code, ```py async def fetchanime(user, selection): nonlocal number number = selection await self.id_lookup(ctx, cmd, number) menu_instance = await PagedOptionsMenu.send_and_wait( ctx, timeout=30, pagenum_in_footer=1, footer_text=f"Requested by: {str(ctx.author)}", options=animelist, callback=fetchanime, ) ``` 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.
TrustyJAID (Migrated from github.com) reviewed 2019-08-19 22:26:11 +02:00
@ -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"])) + 5
TrustyJAID (Migrated from github.com) commented 2019-08-19 20:49:31 +02:00

If there's exactly 10 people in the leaderboard this ends up with a IndexError when trying to view more pages.

If 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 types
TrustyJAID (Migrated from github.com) commented 2019-08-19 20:49:21 +02:00

To keep the typing this should be Optional[float] since we can also pass None as 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 None I 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.

To keep the typing this should be `Optional[float]` since we can also pass `None` as 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 `None` I 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.
Tobotimus (Migrated from github.com) reviewed 2019-08-20 00:26:22 +02:00
@ -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 types
Tobotimus (Migrated from github.com) commented 2019-08-20 00:26:22 +02:00

Yeah, 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.

Yeah, 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.
Drapersniper commented 2019-08-20 14:00:43 +02:00 (Migrated from github.com)

image

Something i found with PagedOptionsMenu is that the Arrows are always avaliable, even when there's only 1 page, from the docs my understanding is that arrows_always should be off by default, this is the code.

await PagedOptionsMenu.send_and_wait(
            ctx,
            timeout=60,
            pagenum_in_footer=True,
            options=folder_page_list,
            title=title,
            embed=True,
            footer_text=footer,
        )
![image](https://user-images.githubusercontent.com/27962761/63345236-31ae1800-c34a-11e9-8e94-63a12867ce8e.png) Something i found with `PagedOptionsMenu` is that the Arrows are always avaliable, even when there's only 1 page, from the docs my understanding is that `arrows_always` should be off by default, this is the code. ```py await PagedOptionsMenu.send_and_wait( ctx, timeout=60, pagenum_in_footer=True, options=folder_page_list, title=title, embed=True, footer_text=footer, ) ```
DevilXD commented 2019-11-21 18:25:01 +01:00 (Migrated from github.com)

Will this find its way into the v3.2 release?

Will this find its way into the v3.2 release?
Flame442 commented 2019-11-21 18:42:19 +01:00 (Migrated from github.com)

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.

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.
Stonedestroyer commented 2020-01-06 21:49:40 +01:00 (Migrated from github.com)

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.

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.
Stonedestroyer commented 2020-03-30 14:53:02 +02:00 (Migrated from github.com)

pagenum_in_footer is documented but not implemented.

pagenum_in_footer is documented but not implemented.
Stonedestroyer commented 2020-05-19 01:06:29 +02:00 (Migrated from github.com)

Setting options_per_page=20 and then spawning the menu results in an error

    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 30010): Maximum number of reactions reached (20)

This is due to it not taking in account the default reactions it adds as well.

Setting options_per_page=20 and then spawning the menu results in an error ```py raise Forbidden(r, data) discord.errors.Forbidden: 403 Forbidden (error code: 30010): Maximum number of reactions reached (20) ``` This is due to it not taking in account the default reactions it adds as well.
Drapersniper commented 2020-07-06 18:19:17 +02:00 (Migrated from github.com)

propose we close this in favour of #4039

propose we close this in favour of #4039
Drapersniper commented 2020-07-23 13:55:02 +02:00 (Migrated from github.com)

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

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

Sign in to join this conversation.
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
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!2809
No description provided.