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

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

Open
1 of 3 tasks
FixedThink opened this issue Jan 7, 2019 · 3 comments
Labels
Category: Core - API - Utils Package This is related to stuff in `redbot.core.utils` Status: Needs Discussion Needs more discussion. Type: Enhancement Something meant to enhance existing Red features.

Comments

@FixedThink
Copy link
Contributor

FixedThink commented Jan 7, 2019

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.

@Tobotimus Tobotimus added Type: Enhancement Something meant to enhance existing Red features. V3 labels Jan 7, 2019
@Tobotimus
Copy link
Member

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.

@FixedThink
Copy link
Contributor Author

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?

@Tobotimus Tobotimus added the Status: Needs Discussion Needs more discussion. label Feb 6, 2019
@mikeshardmind
Copy link
Contributor

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.

@Tobotimus Tobotimus removed the V3 label Jun 29, 2019
@Jackenmen Jackenmen added Category: Bot Core Category: Core - API - Utils Package This is related to stuff in `redbot.core.utils` and removed Category: Bot Core labels Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Core - API - Utils Package This is related to stuff in `redbot.core.utils` Status: Needs Discussion Needs more discussion. Type: Enhancement Something meant to enhance existing Red features.
Projects
None yet
Development

No branches or pull requests

4 participants