Skip to content

Commit

Permalink
Make controls in menu() optional (#5678)
Browse files Browse the repository at this point in the history
* Make `controls` in `menu()` optional

You might wonder, shouldn't we pass `None` to functions from controls?
No, we shouldn't because when `None` is passed, only DEFAULT_CONTROLS
can be used and that means that the length of pages list won't change.

* Update usage in core and core cogs

* Add missing docstrings to `redbot.core.utils.menus` module
  • Loading branch information
Jackenmen authored Apr 16, 2022
1 parent 955b40a commit 27bed50
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 45 deletions.
4 changes: 2 additions & 2 deletions redbot/cogs/alias/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from redbot.core import Config, commands, checks
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.chat_formatting import box, pagify
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
from redbot.core.utils.menus import menu

from redbot.core.bot import Red
from .alias_entry import AliasEntry, AliasCache, ArgParseError
Expand Down Expand Up @@ -185,7 +185,7 @@ async def paginate_alias_list(
if len(alias_list) == 1:
await ctx.send(alias_list[0])
return
await menu(ctx, alias_list, DEFAULT_CONTROLS)
await menu(ctx, alias_list)

@commands.group()
async def alias(self, ctx: commands.Context):
Expand Down
10 changes: 5 additions & 5 deletions redbot/cogs/audio/core/commands/audioset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from redbot.core.data_manager import cog_data_path
from redbot.core.i18n import Translator
from redbot.core.utils.chat_formatting import box, humanize_number
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu, start_adding_reactions
from redbot.core.utils.menus import menu, start_adding_reactions
from redbot.core.utils.predicates import MessagePredicate, ReactionPredicate

from ...audio_dataclasses import LocalPath
Expand Down Expand Up @@ -102,7 +102,7 @@ async def command_audioset_perms_global_whitelist_list(self, ctx: commands.Conte
discord.Embed(title=_("Global Whitelist"), description=page, colour=embed_colour)
for page in pages
)
await menu(ctx, pages, DEFAULT_CONTROLS)
await menu(ctx, pages)

@command_audioset_perms_global_whitelist.command(name="clear")
async def command_audioset_perms_global_whitelist_clear(self, ctx: commands.Context):
Expand Down Expand Up @@ -196,7 +196,7 @@ async def command_audioset_perms_global_blacklist_list(self, ctx: commands.Conte
discord.Embed(title=_("Global Blacklist"), description=page, colour=embed_colour)
for page in pages
)
await menu(ctx, pages, DEFAULT_CONTROLS)
await menu(ctx, pages)

@command_audioset_perms_global_blacklist.command(name="clear")
async def command_audioset_perms_global_blacklist_clear(self, ctx: commands.Context):
Expand Down Expand Up @@ -292,7 +292,7 @@ async def command_audioset_perms_whitelist_list(self, ctx: commands.Context):
discord.Embed(title=_("Whitelist"), description=page, colour=embed_colour)
for page in pages
)
await menu(ctx, pages, DEFAULT_CONTROLS)
await menu(ctx, pages)

@command_audioset_perms_whitelist.command(name="clear")
async def command_audioset_perms_whitelist_clear(self, ctx: commands.Context):
Expand Down Expand Up @@ -385,7 +385,7 @@ async def command_audioset_perms_blacklist_list(self, ctx: commands.Context):
discord.Embed(title=_("Blacklist"), description=page, colour=embed_colour)
for page in pages
)
await menu(ctx, pages, DEFAULT_CONTROLS)
await menu(ctx, pages)

@command_audioset_perms_blacklist.command(name="clear")
async def command_audioset_perms_blacklist_clear(self, ctx: commands.Context):
Expand Down
4 changes: 2 additions & 2 deletions redbot/cogs/audio/core/commands/equalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from redbot.core import commands
from redbot.core.i18n import Translator
from redbot.core.utils.chat_formatting import box, humanize_number, pagify
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu, start_adding_reactions
from redbot.core.utils.menus import menu, start_adding_reactions
from redbot.core.utils.predicates import MessagePredicate, ReactionPredicate

from ...equalizer import Equalizer
Expand Down Expand Up @@ -141,7 +141,7 @@ async def command_equalizer_list(self, ctx: commands.Context):
text=_("{num} preset(s)").format(num=humanize_number(len(list(eq_presets.keys()))))
)
page_list.append(embed)
await menu(ctx, page_list, DEFAULT_CONTROLS)
await menu(ctx, page_list)

@command_equalizer.command(name="load")
async def command_equalizer_load(self, ctx: commands.Context, eq_preset: str):
Expand Down
4 changes: 2 additions & 2 deletions redbot/cogs/audio/core/commands/localtracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from redbot.core import commands
from redbot.core.i18n import Translator
from redbot.core.utils.menus import DEFAULT_CONTROLS, close_menu, menu, next_page, prev_page
from redbot.core.utils.menus import close_menu, menu, next_page, prev_page

from ...audio_dataclasses import LocalPath, Query
from ..abc import MixinMeta
Expand Down Expand Up @@ -113,7 +113,7 @@ async def _local_folder_menu(

dj_enabled = await self.config.guild(ctx.guild).dj_enabled()
if dj_enabled and not await self._can_instaskip(ctx, ctx.author):
return await menu(ctx, folder_page_list, DEFAULT_CONTROLS)
return await menu(ctx, folder_page_list)
else:
await menu(ctx, folder_page_list, local_folder_controls)

Expand Down
4 changes: 2 additions & 2 deletions redbot/cogs/audio/core/commands/miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from redbot.core.i18n import Translator
from redbot.core.utils import AsyncIter
from redbot.core.utils.chat_formatting import humanize_number, pagify
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
from redbot.core.utils.menus import menu

from ..abc import MixinMeta
from ..cog_utils import CompositeMetaClass
Expand Down Expand Up @@ -92,7 +92,7 @@ async def command_audiostats(self, ctx: commands.Context):
pages += 1
servers_embed.append(em)

await menu(ctx, servers_embed, DEFAULT_CONTROLS)
await menu(ctx, servers_embed)

@commands.command(name="percent")
@commands.guild_only()
Expand Down
4 changes: 2 additions & 2 deletions redbot/cogs/audio/core/commands/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from redbot.core.commands import UserInputOptional
from redbot.core.i18n import Translator
from redbot.core.utils import AsyncIter
from redbot.core.utils.menus import DEFAULT_CONTROLS, close_menu, menu, next_page, prev_page
from redbot.core.utils.menus import close_menu, menu, next_page, prev_page

from ...audio_dataclasses import _PARTIALLY_SUPPORTED_MUSIC_EXT, Query
from ...errors import (
Expand Down Expand Up @@ -930,6 +930,6 @@ async def _search_menu(
search_page_list.append(embed)

if dj_enabled and not can_skip:
return await menu(ctx, search_page_list, DEFAULT_CONTROLS)
return await menu(ctx, search_page_list)

await menu(ctx, search_page_list, search_controls)
8 changes: 4 additions & 4 deletions redbot/cogs/audio/core/commands/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from redbot.core.i18n import Translator
from redbot.core.utils import AsyncIter
from redbot.core.utils.chat_formatting import bold, pagify
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
from redbot.core.utils.menus import menu
from redbot.core.utils.predicates import MessagePredicate

from ...apis.api_utils import FakePlaylist
Expand Down Expand Up @@ -899,7 +899,7 @@ async def command_playlist_info(
)
)
page_list.append(embed)
await menu(ctx, page_list, DEFAULT_CONTROLS)
await menu(ctx, page_list)

@commands.cooldown(1, 15, commands.BucketType.guild)
@command_playlist.command(name="list", usage="[args]", cooldown_after_parsing=True)
Expand Down Expand Up @@ -1052,7 +1052,7 @@ async def command_playlist_list(
async for page_num in AsyncIter(range(1, len_playlist_list_pages + 1)):
embed = await self._build_playlist_list_page(ctx, page_num, abc_names, name)
playlist_embeds.append(embed)
await menu(ctx, playlist_embeds, DEFAULT_CONTROLS)
await menu(ctx, playlist_embeds)

@command_playlist.command(name="queue", usage="<name> [args]", cooldown_after_parsing=True)
@commands.cooldown(1, 300, commands.BucketType.member)
Expand Down Expand Up @@ -1742,7 +1742,7 @@ async def command_playlist_update(
),
)
if embeds:
await menu(ctx, embeds, DEFAULT_CONTROLS)
await menu(ctx, embeds)

@command_playlist.command(name="upload", usage="[args]")
@commands.is_owner()
Expand Down
3 changes: 1 addition & 2 deletions redbot/cogs/audio/core/commands/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from redbot.core.i18n import Translator
from redbot.core.utils import AsyncIter
from redbot.core.utils.menus import (
DEFAULT_CONTROLS,
close_menu,
menu,
next_page,
Expand Down Expand Up @@ -304,7 +303,7 @@ async def command_queue_search(self, ctx: commands.Context, *, search_words: str
async for page_num in AsyncIter(range(1, len_search_pages + 1)):
embed = await self._build_queue_search_page(ctx, page_num, search_list)
search_page_list.append(embed)
await menu(ctx, search_page_list, DEFAULT_CONTROLS)
await menu(ctx, search_page_list)

@command_queue.command(name="shuffle")
@commands.cooldown(1, 30, commands.BucketType.guild)
Expand Down
6 changes: 3 additions & 3 deletions redbot/cogs/customcom/customcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async def cc_raw(self, ctx: commands.Context, command: str.lower):
if len(msg) > 2000:
msg = f"{msg[:1997]}..."
msglist.append(msg)
await menus.menu(ctx, msglist, menus.DEFAULT_CONTROLS)
await menus.menu(ctx, msglist)

@customcom.command(name="search")
@commands.guild_only()
Expand Down Expand Up @@ -572,11 +572,11 @@ async def cc_list(self, ctx: commands.Context):
)
embed.set_footer(text=_("Page {num}/{total}").format(num=idx, total=len(pages)))
embed_pages.append(embed)
await menus.menu(ctx, embed_pages, menus.DEFAULT_CONTROLS)
await menus.menu(ctx, embed_pages)
else:
content = "\n".join(map("{0[0]:<12} : {0[1]}".format, results))
pages = list(map(box, pagify(content, page_length=2000, shorten_by=10)))
await menus.menu(ctx, pages, menus.DEFAULT_CONTROLS)
await menus.menu(ctx, pages)

@customcom.command(name="show")
async def cc_show(self, ctx, command_name: str):
Expand Down
8 changes: 2 additions & 6 deletions redbot/cogs/economy/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils import AsyncIter
from redbot.core.utils.chat_formatting import box, humanize_number
from redbot.core.utils.menus import close_menu, menu, DEFAULT_CONTROLS
from redbot.core.utils.menus import close_menu, menu
from .converters import positive_int

T_ = Translator("Economy", __file__)
Expand Down Expand Up @@ -516,11 +516,7 @@ async def leaderboard(self, ctx: commands.Context, top: int = 10, show_global: b
highscores.append(box(temp_msg, lang="md"))

if highscores:
await menu(
ctx,
highscores,
DEFAULT_CONTROLS if len(highscores) > 1 else {"\N{CROSS MARK}": close_menu},
)
await menu(ctx, highscores)
else:
await ctx.send(_("No balances found."))

Expand Down
4 changes: 1 addition & 3 deletions redbot/cogs/general/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from redbot.core import commands
from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
from redbot.core.utils.menus import menu
from redbot.core.utils.chat_formatting import (
bold,
escape,
Expand Down Expand Up @@ -511,7 +511,6 @@ async def urban(self, ctx, *, word):
await menu(
ctx,
pages=embeds,
controls=DEFAULT_CONTROLS,
message=None,
page=0,
timeout=30,
Expand All @@ -537,7 +536,6 @@ async def urban(self, ctx, *, word):
await menu(
ctx,
pages=messages,
controls=DEFAULT_CONTROLS,
message=None,
page=0,
timeout=30,
Expand Down
6 changes: 3 additions & 3 deletions redbot/cogs/modlog/modlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.chat_formatting import bold, box, pagify
from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
from redbot.core.utils.menus import menu
from redbot.core.utils.predicates import MessagePredicate

_ = Translator("ModLog", __file__)
Expand Down Expand Up @@ -84,7 +84,7 @@ async def casesfor(self, ctx: commands.Context, *, member: Union[discord.Member,
)
rendered_cases.append(message)

await menu(ctx, rendered_cases, DEFAULT_CONTROLS)
await menu(ctx, rendered_cases)

@commands.command()
@commands.guild_only()
Expand Down Expand Up @@ -119,7 +119,7 @@ async def listcases(self, ctx: commands.Context, *, member: Union[discord.Member
)
for page in pagify(message, ["\n\n", "\n"], priority=True):
rendered_cases.append(page)
await menu(ctx, rendered_cases, DEFAULT_CONTROLS)
await menu(ctx, rendered_cases)

@commands.command()
@commands.guild_only()
Expand Down
6 changes: 3 additions & 3 deletions redbot/cogs/warnings/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils import AsyncIter
from redbot.core.utils.chat_formatting import warning, pagify
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
from redbot.core.utils.menus import menu


_ = Translator("Warnings", __file__)
Expand Down Expand Up @@ -324,7 +324,7 @@ async def reasonlist(self, ctx: commands.Context):
).format(reason_name=r, **v)
)
if msg_list:
await menu(ctx, msg_list, DEFAULT_CONTROLS)
await menu(ctx, msg_list)
else:
await ctx.send(_("There are no reasons configured!"))

Expand Down Expand Up @@ -359,7 +359,7 @@ async def actionlist(self, ctx: commands.Context):
).format(**r)
)
if msg_list:
await menu(ctx, msg_list, DEFAULT_CONTROLS)
await menu(ctx, msg_list)
else:
await ctx.send(_("There are no actions configured!"))

Expand Down
4 changes: 2 additions & 2 deletions redbot/core/core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import traceback
from pathlib import Path
from redbot.core import data_manager
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
from redbot.core.utils.menus import menu
from redbot.core.commands import GuildConverter, RawUserIdConverter
from string import ascii_letters, digits
from typing import TYPE_CHECKING, Union, Tuple, List, Optional, Iterable, Sequence, Dict, Set
Expand Down Expand Up @@ -1659,7 +1659,7 @@ async def servers(self, ctx: commands.Context):
if len(pages) == 1:
await ctx.send(pages[0])
else:
await menu(ctx, pages, DEFAULT_CONTROLS)
await menu(ctx, pages)

@commands.command(require_var_positional=True)
@checks.is_owner()
Expand Down
Loading

0 comments on commit 27bed50

Please sign in to comment.