Make controls in menu() optional (#5678)

* 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
This commit is contained in:
Jakub Kuczys
2022-04-16 21:29:12 +02:00
committed by GitHub
parent 955b40ac6d
commit 27bed5010f
15 changed files with 59 additions and 45 deletions

View File

@@ -14,7 +14,7 @@ from redbot.core import bank, commands
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
@@ -102,7 +102,7 @@ class AudioSetCommands(MixinMeta, metaclass=CompositeMetaClass):
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):
@@ -196,7 +196,7 @@ class AudioSetCommands(MixinMeta, metaclass=CompositeMetaClass):
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):
@@ -292,7 +292,7 @@ class AudioSetCommands(MixinMeta, metaclass=CompositeMetaClass):
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):
@@ -385,7 +385,7 @@ class AudioSetCommands(MixinMeta, metaclass=CompositeMetaClass):
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):

View File

@@ -10,7 +10,7 @@ from red_commons.logging import getLogger
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
@@ -141,7 +141,7 @@ class EqualizerCommands(MixinMeta, metaclass=CompositeMetaClass):
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):

View File

@@ -8,7 +8,7 @@ from red_commons.logging import getLogger
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
@@ -113,7 +113,7 @@ class LocalTrackCommands(MixinMeta, metaclass=CompositeMetaClass):
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)

View File

@@ -12,7 +12,7 @@ from redbot.core import commands
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
@@ -92,7 +92,7 @@ class MiscellaneousCommands(MixinMeta, metaclass=CompositeMetaClass):
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()

View File

@@ -15,7 +15,7 @@ from redbot.core import commands
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 (
@@ -930,6 +930,6 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
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)

View File

@@ -19,7 +19,7 @@ from redbot.core.data_manager import cog_data_path
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
@@ -899,7 +899,7 @@ class PlaylistCommands(MixinMeta, metaclass=CompositeMetaClass):
)
)
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)
@@ -1052,7 +1052,7 @@ class PlaylistCommands(MixinMeta, metaclass=CompositeMetaClass):
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)
@@ -1742,7 +1742,7 @@ class PlaylistCommands(MixinMeta, metaclass=CompositeMetaClass):
),
)
if embeds:
await menu(ctx, embeds, DEFAULT_CONTROLS)
await menu(ctx, embeds)
@command_playlist.command(name="upload", usage="[args]")
@commands.is_owner()

View File

@@ -14,7 +14,6 @@ from redbot.core import commands
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,
@@ -304,7 +303,7 @@ class QueueCommands(MixinMeta, metaclass=CompositeMetaClass):
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)