Help delete pages delay feature (#3433)

* Added 'deletedelay' feature for help

* Fixes

* More fixes

* Use better message when disabling

* Added changelog entry

* Addressed feedback

* Improved the pages check

* Added additional command check

* Improved command description

* Final feedback improvements
This commit is contained in:
DevilXD
2020-01-22 23:15:51 +01:00
committed by Michael H
parent 8570971f68
commit ee53d50c3a
4 changed files with 75 additions and 32 deletions

View File

@@ -44,6 +44,7 @@ from . import commands
from .context import Context
from ..i18n import Translator
from ..utils import menus
from ..utils.mod import mass_purge
from ..utils._internal_utils import fuzzy_command_search, format_fuzzy_results
from ..utils.chat_formatting import box, pagify
@@ -627,36 +628,52 @@ class RedHelpFormatter:
Sends pages based on settings.
"""
if not (
ctx.channel.permissions_for(ctx.me).add_reactions
and await ctx.bot._config.help.use_menus()
):
# save on config calls
config_help = await ctx.bot._config.help()
channel_permissions = ctx.channel.permissions_for(ctx.me)
max_pages_in_guild = await ctx.bot._config.help.max_pages_in_guild()
destination = ctx.author if len(pages) > max_pages_in_guild else ctx
if not (channel_permissions.add_reactions and config_help["use_menus"]):
if embed:
for page in pages:
try:
await destination.send(embed=page)
except discord.Forbidden:
return await ctx.send(
T_(
"I couldn't send the help message to you in DM. "
"Either you blocked me or you disabled DMs in this server."
)
)
else:
for page in pages:
try:
await destination.send(page)
except discord.Forbidden:
return await ctx.send(
T_(
"I couldn't send the help message to you in DM. "
"Either you blocked me or you disabled DMs in this server."
)
max_pages_in_guild = config_help["max_pages_in_guild"]
use_DMs = len(pages) > max_pages_in_guild
destination = ctx.author if use_DMs else ctx.channel
delete_delay = config_help["delete_delay"]
messages: List[discord.Message] = []
for page in pages:
try:
if embed:
msg = await destination.send(embed=page)
else:
msg = await destination.send(page)
except discord.Forbidden:
return await ctx.send(
T_(
"I couldn't send the help message to you in DM. "
"Either you blocked me or you disabled DMs in this server."
)
)
else:
messages.append(msg)
# The if statement takes into account that 'destination' will be
# the context channel in non-DM context, reusing 'channel_permissions' to avoid
# computing the permissions twice.
if (
not use_DMs # we're not in DMs
and delete_delay > 0 # delete delay is enabled
and channel_permissions.manage_messages # we can manage messages here
):
# We need to wrap this in a task to not block after-sending-help interactions.
# The channel has to be TextChannel as we can't bulk-delete from DMs
async def _delete_delay_help(
channel: discord.TextChannel, messages: List[discord.Message], delay: int
):
await asyncio.sleep(delay)
await mass_purge(messages, channel)
asyncio.create_task(_delete_delay_help(destination, messages, delete_delay))
else:
# 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]))