Skip to content

Commit

Permalink
[Help] Send menus to dm if maxpages is 0 (Cog-Creators#5375)
Browse files Browse the repository at this point in the history
Co-authored-by: Dav <[email protected]>
Co-authored-by: Michael Oliveira <[email protected]>
  • Loading branch information
3 people authored Jan 19, 2024
1 parent 409ece4 commit dbd71db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 1 addition & 4 deletions docs/cog_guides/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1475,9 +1475,6 @@ helpset maxpages

Set the maximum number of help pages sent in a server channel.

.. Note:: This setting does not apply to menu help.


If a help message contains more pages than this value, the help message will
be sent to the command author via DM. This is to help reduce spam in server
text channels.
Expand Down Expand Up @@ -4378,4 +4375,4 @@ uptime
**Description**

Shows Red's uptime.
Shows Red's uptime.
21 changes: 17 additions & 4 deletions redbot/core/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,23 +856,36 @@ async def send_pages(
if help_settings.use_menus.value >= HelpMenuSetting.buttons.value:
use_select = help_settings.use_menus.value == 3
select_only = help_settings.use_menus.value == 4
await SimpleMenu(
menu = SimpleMenu(
pages,
timeout=help_settings.react_timeout,
use_select_menu=use_select,
use_select_only=select_only,
).start(ctx)
)
# Send menu to DMs if max pages is 0
if help_settings.max_pages_in_guild == 0:
await menu.start_dm(ctx.author)
else:
await menu.start(ctx)

elif (
can_user_react_in(ctx.me, ctx.channel)
and help_settings.use_menus is HelpMenuSetting.reactions
):
use_DMs = help_settings.max_pages_in_guild == 0
destination = ctx.author if use_DMs else ctx.channel
# Specifically ensuring the menu's message is sent prior to returning
m = await (ctx.send(embed=pages[0]) if embed else ctx.send(pages[0]))
m = await (destination.send(embed=pages[0]) if embed else destination.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.
if use_DMs:
menu_ctx = await ctx.bot.get_context(m)
# Monkeypatch so help listens for reactions from the original author, not the bot
menu_ctx.author = ctx.author
else:
menu_ctx = ctx
asyncio.create_task(
menus.menu(ctx, pages, c, message=m, timeout=help_settings.react_timeout)
menus.menu(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())
Expand Down
2 changes: 0 additions & 2 deletions redbot/core/core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4446,8 +4446,6 @@ async def helpset_pagecharlimt(self, ctx: commands.Context, limit: int):
async def helpset_maxpages(self, ctx: commands.Context, pages: int):
"""Set the maximum number of help pages sent in a server channel.
Note: This setting does not apply to menu help.
If a help message contains more pages than this value, the help message will
be sent to the command author via DM. This is to help reduce spam in server
text channels.
Expand Down

0 comments on commit dbd71db

Please sign in to comment.