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

[V3 Utils] Menu system #1566

Merged
merged 10 commits into from
May 4, 2018

Conversation

palmtree5
Copy link
Member

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

This is a possible implementation for a menu system. Basically, cog devs can pass in context, a list of either strings or embeds and a dict mapping of emoji to functions and the user will get a menu controlled by emoji. An example:

from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
import discord

class MyCog:
    @commands.command()
    async def mycom(self, ctx):
        pages = [discord.Embed(title="blah"), discord.Embed(title="blah 2")]
        await menu(ctx, pages, DEFAULT_CONTROLS)

will yield a menu where users can change pages and close the menu

DEFAULT_CONTROLS is basically a quick way to use the menu system if cog devs are fine using some default functions to handle menu controls (basically, these are a function to move to the next page, a function to move to the previous page, and a function to close the menu (deleting the message that is the menu))

@palmtree5 palmtree5 added the V3 label Apr 24, 2018
@palmtree5 palmtree5 added the Type: Enhancement Something meant to enhance existing Red features. label Apr 24, 2018
except discord.NotFound:
pass
if page == len(pages) - 1:
next_page = 0 # Loop around to the first item
Copy link
Contributor

@bobloy bobloy Apr 24, 2018

Choose a reason for hiding this comment

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

Uses next_page as variable and next_page and function

@bobloy
Copy link
Contributor

bobloy commented Apr 27, 2018

It appears multiple instances of a menu will trigger each other's button presses.
i.e ❌ will close all menus

@Bakersbakebread
Copy link
Contributor

Upvote

await message.edit(content=current_page)

def react_check(r, u):
return u == ctx.author and str(r.emoji) in controls.keys()
Copy link
Contributor

Choose a reason for hiding this comment

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

add and r.message==message


DEFAULT_CONTROLS = {
"➡": next_page,
"⬅": prev_page,
Copy link
Contributor

Choose a reason for hiding this comment

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

Swap order of next_page and prev_page for clearer buttons

@Kowlin Kowlin merged commit fb093b7 into Cog-Creators:V3/develop May 4, 2018
@palmtree5 palmtree5 deleted the V3/enhancement/menu_system branch May 31, 2021 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Something meant to enhance existing Red features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants