[Feature Request] Allow passing on **kwargs to red.menu to be used in custom button actions. #2362

Closed
opened 2019-01-07 23:09:36 +01:00 by FixedThink · 4 comments
FixedThink commented 2019-01-07 23:09:36 +01:00 (Migrated from github.com)

Feature request

Select the type of feature you are requesting:

  • Cog
  • Command
  • API functionality

Describe your requested feature

In addition to just browsing between different page in the page list, it should be possible to (properly) use custom-made actions on a Red Menu. For this, one should be able to pass on **kwargs to the Red Menu, so that they can be caught and used by the custom button actions. Especially since Red is meant to be modular, I think adding this would be handy. Also because this makes the menu usable in a lot more scenarios.

Think about...

  • Output the embed's contents to a file. This is actually what I would personally use this for. In some of my commands, I make an embed of a certain list, which due its size is split across pages. However, in addition to just browsing it, I want to make people able to download that list in .csv if they click on a certain emoji, like ⏬.
  • Selection of a specific embed in the page list by using number emojis 1️⃣ 2️⃣ 3️⃣ 4️⃣ . An example usage for this would be a FAQ command, where one could see some frequently asked questions on the first embed along with a number, and the answer to the pages on the numbers
  • Nested selection menus. If you click on an emoji in a certain embed, it returns a new series of embeds to do things with. An example would be a command that would go through recently created cases in a moderation log, and by clicking e.g. a 👤 button, you switch to a view where you only see the cases of that specific user.

Technically this can already be achieved in a "hacky" way, namely by making an asynchronous function inside a command, making a custom embed control dict, and calling that internal command in one of the values. However, it forces someone to rewrite this function inside every command that they would like to have it for, and that for every single function. Also, it would either force people to (temporarily) store values in class attributes, or to call a nonlocal inside the nested function to use certain variables.

Being able to pass on **kwargs and catch those inside the custom functions would be much more convenient (and cleaner) than the above.

# Feature request #### Select the type of feature you are requesting: - [ ] Cog - [ ] Command - [X] API functionality #### Describe your requested feature In addition to just browsing between different page in the page list, it should be possible to (properly) use custom-made actions on a Red Menu. For this, one should be able to pass on **kwargs to the Red Menu, so that they can be caught and used by the custom button actions. Especially since Red is meant to be modular, I think adding this would be handy. Also because this makes the menu usable in a lot more scenarios. Think about... - Output the embed's contents to a file. This is actually what I would personally use this for. In some of my commands, I make an embed of a certain list, which due its size is split across pages. However, in addition to just browsing it, I want to make people able to download that list in `.csv` if they click on a certain emoji, like ⏬. - Selection of a specific embed in the page list by using number emojis 1️⃣ 2️⃣ 3️⃣ 4️⃣ . An example usage for this would be a FAQ command, where one could see some frequently asked questions on the first embed along with a number, and the answer to the pages on the numbers - Nested selection menus. If you click on an emoji in a certain embed, it returns a new series of embeds to do things with. An example would be a command that would go through recently created cases in a moderation log, and by clicking e.g. a 👤 button, you switch to a view where you only see the cases of that specific user. Technically this can already be achieved in a "hacky" way, namely by making an asynchronous function inside a command, making a custom embed control dict, and calling that internal command in one of the values. However, it forces someone to rewrite this function inside every command that they would like to have it for, and that for every single function. Also, it would either force people to (temporarily) store values in class attributes, or to call a `nonlocal` inside the nested function to use certain variables. Being able to pass on `**kwargs` and catch those inside the custom functions would be much more convenient (and cleaner) than the above.
Tobotimus commented 2019-01-08 00:31:12 +01:00 (Migrated from github.com)

Hi, I see where you're coming from when you speak to your complaints about the menu system and how it can be customised in its current form. I've been thinking about creating a new system (to prevent breaking the old one) which involves a class-based approach with decorators to assign actions to emojis. Creating a custom menu would simply involve subclassing the base menu, or an existing custom menu, and then adding methods. I would also aim to include some common custom menus in the core utils module. Here might be an example, just brainstorming:

import discord
from redbot.core.utils import menu

class CSVMenu(menu.Menu):

    @menu.action("⏬")
    async def download_csv(self, user: discord.abc.User):
        # Send CSV file to user...

This way a menu can be defined in a declarative style, outside the scope of wherever you're sending it, and it's all nicely grouped together in the code, so I think it's an improvement stylistically as well.

Hi, I see where you're coming from when you speak to your complaints about the menu system and how it can be customised in its current form. I've been thinking about creating a new system (to prevent breaking the old one) which involves a class-based approach with decorators to assign actions to emojis. Creating a custom menu would simply involve subclassing the base menu, or an existing custom menu, and then adding methods. I would also aim to include some common custom menus in the core utils module. Here might be an example, just brainstorming: ```py import discord from redbot.core.utils import menu class CSVMenu(menu.Menu): @menu.action("⏬") async def download_csv(self, user: discord.abc.User): # Send CSV file to user... ``` This way a menu can be defined in a declarative style, outside the scope of wherever you're sending it, and it's all nicely grouped together in the code, so I think it's an improvement stylistically as well.
FixedThink commented 2019-01-08 02:42:23 +01:00 (Migrated from github.com)

Making a new class system like that sounds like an interesting idea.

One potential issue I foresee (if I understood you right, correct me if I'm wrong), is that by using another custom menu as basis, you will be bound to all the methods that the author in question added to their method.
In other words, if another user made a class with a tutorial action (❓), and a "go back" action (↩️), you will not be able to use their ↩️ action without adding their ❓ action too. That is, without recycling their code.
Similarly, cherry-picking decorators between different custom menu classes should become possible as well.

Maybe adding a bare-bones menu as a base option to the system, which only provides the menu logic without also supplying any actions, could solve such problems.

I do like the idea though, and I'd definitely make use of such a class if it would be added as a util to Red. I would be curious to see how it develops, and how others would like to use such a class.

I know that this is just a brainstorm, but do you have any ideas on how such an implementation would look like inside commands? For example, do you expect the embed call to still be a one-liner like it is now?

Making a new class system like that sounds like an interesting idea. One potential issue I foresee (if I understood you right, correct me if I'm wrong), is that by using another custom menu as basis, you will be bound to all the methods that the author in question added to their method. In other words, if another user made a class with a tutorial action (❓), and a "go back" action (↩️), you will not be able to use their ↩️ action without adding their ❓ action too. That is, without recycling their code. Similarly, cherry-picking decorators between different custom menu classes should become possible as well. Maybe adding a bare-bones menu as a base option to the system, which only provides the menu logic without also supplying any actions, could solve such problems. I do like the idea though, and I'd definitely make use of such a class if it would be added as a util to Red. I would be curious to see how it develops, and how others would like to use such a class. I know that this is just a brainstorm, but do you have any ideas on how such an implementation would look like inside commands? For example, do you expect the embed call to still be a one-liner like it is now?
mikeshardmind commented 2019-05-21 22:55:09 +02:00 (Migrated from github.com)

As of #2720 you can properly use functools.partial with menus. This should be included in 3.1.2

I'm leaving this open for now given the direction this took about adding an additional class based menu for use.

As of #2720 you can properly use functools.partial with menus. This should be included in 3.1.2 I'm leaving this open for now given the direction this took about adding an additional class based menu for use.
Owner

Offene Diskussion bzw. Feature-Wunsch mit geringem Nutzen im Verhältnis zum Aufwand (oder Nischenfall), der seit Langem ohne Ergebnis offen ist. Ich schließe das Issue; bei konkretem Bedarf kann es gern wieder geöffnet werden.


Generated by Claude Code

Offene Diskussion bzw. Feature-Wunsch mit geringem Nutzen im Verhältnis zum Aufwand (oder Nischenfall), der seit Langem ohne Ergebnis offen ist. Ich schließe das Issue; bei konkretem Bedarf kann es gern wieder geöffnet werden. --- _Generated by [Claude Code](https://claude.ai/code)_
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
2 participants
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#2362
No description provided.