From f8664a4e8a8a491f2543ee733d76346c722f33ca Mon Sep 17 00:00:00 2001 From: Vexed Date: Wed, 1 Sep 2021 17:35:11 +0100 Subject: [PATCH] [Help] Let owners set menu reaction timeout (#5205) * initial help reaction timeout with min 15, max 300 * slight wording change * docs! * aaa * Suggestions from code review, thank Jack! Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- docs/cog_guides/core.rst | 28 ++++++++++++++++++++++++++++ redbot/core/bot.py | 1 + redbot/core/commands/help.py | 6 +++++- redbot/core/core_commands.py | 26 ++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/docs/cog_guides/core.rst b/docs/cog_guides/core.rst index 14f8cfbbe..a29b650f7 100644 --- a/docs/cog_guides/core.rst +++ b/docs/cog_guides/core.rst @@ -1190,6 +1190,34 @@ mean some pages will exceed this limit. **Arguments:** - ```` - The max amount of characters to show per page in the help message. +.. _core-command-helpset-reacttimeout: + +"""""""""""""""""""" +helpset reacttimeout +"""""""""""""""""""" + +**Syntax** + +.. code-block:: none + + [p]helpset reacttimeout + +**Description** + +Set the timeout for reactions, if menus are enabled. + +The default is 30 seconds. +The timeout has to be between 15 and 300 seconds. + +**Examples:** + - ``[p]helpset reacttimeout 30`` - The default timeout. + - ``[p]helpset reacttimeout 60`` - Timeout of 1 minute. + - ``[p]helpset reacttimeout 15`` - Minimum allowed timeout. + - ``[p]helpset reacttimeout 300`` - Max allowed timeout (5 mins). + +**Arguments:** + - ```` - The timeout, in seconds, of the reactions. + .. _core-command-helpset-resetformatter: """""""""""""""""""""" diff --git a/redbot/core/bot.py b/redbot/core/bot.py index e7a48431e..78aff3d1a 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -115,6 +115,7 @@ class RedBase( help__verify_exists=False, help__tagline="", help__use_tick=False, + help__react_timeout=30, description="Red V3", invite_public=False, invite_perm=0, diff --git a/redbot/core/commands/help.py b/redbot/core/commands/help.py index afd13e891..41e34f5f6 100644 --- a/redbot/core/commands/help.py +++ b/redbot/core/commands/help.py @@ -78,6 +78,7 @@ class HelpSettings: tagline: str = "" delete_delay: int = 0 use_tick: bool = False + react_timeout: int = 30 # Contrib Note: This is intentional to not accept the bot object # There are plans to allow guild and user specific help settings @@ -131,6 +132,7 @@ class HelpSettings: "\nHelp shows unusable commands when asked directly: {verify_exists}" "\nDelete delay: {delete_delay}" "\nReact with a checkmark when help is sent via DM: {use_tick}" + "\nReaction timeout (only used if menus are used): {react_timeout} seconds" "{tagline_info}" ).format_map(data) @@ -857,7 +859,9 @@ class RedHelpFormatter(HelpFormatterABC): m = await (ctx.send(embed=pages[0]) if embed else ctx.send(pages[0])) c = menus.DEFAULT_CONTROLS if len(pages) > 1 else {"\N{CROSS MARK}": menus.close_menu} # Allow other things to happen during menu timeout/interaction. - asyncio.create_task(menus.menu(ctx, pages, c, message=m)) + asyncio.create_task( + menus.menu(ctx, pages, c, message=m, timeout=help_settings.react_timeout) + ) # menu needs reactions added manually since we fed it a message menus.start_adding_reactions(m, c.keys()) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index e85115c41..7309434ec 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -3340,6 +3340,32 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): else: await ctx.send(_("Done. The delete delay has been set to {} seconds.").format(seconds)) + @helpset.command(name="reacttimeout") + async def helpset_reacttimeout(self, ctx: commands.Context, seconds: int): + """Set the timeout for reactions, if menus are enabled. + + The default is 30 seconds. + The timeout has to be between 15 and 300 seconds. + + **Examples:** + - `[p]helpset reacttimeout 30` - The default timeout. + - `[p]helpset reacttimeout 60` - Timeout of 1 minute. + - `[p]helpset reacttimeout 15` - Minimum allowed timeout. + - `[p]helpset reacttimeout 300` - Max allowed timeout (5 mins). + + **Arguments:** + - `` - The timeout, in seconds, of the reactions. + """ + if seconds < 15: + await ctx.send(_("You must give a value of at least 15 seconds!")) + return + if seconds > 300: + await ctx.send(_("The timeout cannot be greater than 5 minutes!")) + return + + await ctx.bot._config.help.react_timeout.set(seconds) + await ctx.send(_("Done. The reaction timeout has been set to {} seconds.").format(seconds)) + @helpset.command(name="tagline") async def helpset_tagline(self, ctx: commands.Context, *, tagline: str = None): """