mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
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:
parent
8570971f68
commit
ee53d50c3a
1
changelog.d/3433.feature.rst
Normal file
1
changelog.d/3433.feature.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
Added a ``[p]helpset deletedelay`` command, that lets you set a delay (in seconds) after which help messages / pages will be deleted.
|
||||||
@ -88,6 +88,7 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
|
|||||||
custom_info=None,
|
custom_info=None,
|
||||||
help__page_char_limit=1000,
|
help__page_char_limit=1000,
|
||||||
help__max_pages_in_guild=2,
|
help__max_pages_in_guild=2,
|
||||||
|
help__delete_delay=0,
|
||||||
help__use_menus=False,
|
help__use_menus=False,
|
||||||
help__show_hidden=False,
|
help__show_hidden=False,
|
||||||
help__verify_checks=True,
|
help__verify_checks=True,
|
||||||
|
|||||||
@ -44,6 +44,7 @@ from . import commands
|
|||||||
from .context import Context
|
from .context import Context
|
||||||
from ..i18n import Translator
|
from ..i18n import Translator
|
||||||
from ..utils import menus
|
from ..utils import menus
|
||||||
|
from ..utils.mod import mass_purge
|
||||||
from ..utils._internal_utils import fuzzy_command_search, format_fuzzy_results
|
from ..utils._internal_utils import fuzzy_command_search, format_fuzzy_results
|
||||||
from ..utils.chat_formatting import box, pagify
|
from ..utils.chat_formatting import box, pagify
|
||||||
|
|
||||||
@ -627,18 +628,24 @@ class RedHelpFormatter:
|
|||||||
Sends pages based on settings.
|
Sends pages based on settings.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not (
|
# save on config calls
|
||||||
ctx.channel.permissions_for(ctx.me).add_reactions
|
config_help = await ctx.bot._config.help()
|
||||||
and await ctx.bot._config.help.use_menus()
|
channel_permissions = ctx.channel.permissions_for(ctx.me)
|
||||||
):
|
|
||||||
|
|
||||||
max_pages_in_guild = await ctx.bot._config.help.max_pages_in_guild()
|
if not (channel_permissions.add_reactions and config_help["use_menus"]):
|
||||||
destination = ctx.author if len(pages) > max_pages_in_guild else ctx
|
|
||||||
|
|
||||||
if embed:
|
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:
|
for page in pages:
|
||||||
try:
|
try:
|
||||||
await destination.send(embed=page)
|
if embed:
|
||||||
|
msg = await destination.send(embed=page)
|
||||||
|
else:
|
||||||
|
msg = await destination.send(page)
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
return await ctx.send(
|
return await ctx.send(
|
||||||
T_(
|
T_(
|
||||||
@ -647,16 +654,26 @@ class RedHelpFormatter:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
for page in pages:
|
messages.append(msg)
|
||||||
try:
|
|
||||||
await destination.send(page)
|
# The if statement takes into account that 'destination' will be
|
||||||
except discord.Forbidden:
|
# the context channel in non-DM context, reusing 'channel_permissions' to avoid
|
||||||
return await ctx.send(
|
# computing the permissions twice.
|
||||||
T_(
|
if (
|
||||||
"I couldn't send the help message to you in DM. "
|
not use_DMs # we're not in DMs
|
||||||
"Either you blocked me or you disabled DMs in this server."
|
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:
|
else:
|
||||||
# Specifically ensuring the menu's message is sent prior to returning
|
# 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 (ctx.send(embed=pages[0]) if embed else ctx.send(pages[0]))
|
||||||
|
|||||||
@ -1368,6 +1368,30 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
await ctx.bot._config.help.max_pages_in_guild.set(pages)
|
await ctx.bot._config.help.max_pages_in_guild.set(pages)
|
||||||
await ctx.send(_("Done. The page limit has been set to {}.").format(pages))
|
await ctx.send(_("Done. The page limit has been set to {}.").format(pages))
|
||||||
|
|
||||||
|
@helpset.command(name="deletedelay")
|
||||||
|
@commands.bot_has_permissions(manage_messages=True)
|
||||||
|
async def helpset_deletedelay(self, ctx: commands.Context, seconds: int):
|
||||||
|
"""Set the delay after which help pages will be deleted.
|
||||||
|
|
||||||
|
The setting is disabled by default, and only applies to non-menu help,
|
||||||
|
sent in server text channels.
|
||||||
|
Setting the delay to 0 disables this feature.
|
||||||
|
|
||||||
|
The bot has to have MANAGE_MESSAGES permission for this to work.
|
||||||
|
"""
|
||||||
|
if seconds < 0:
|
||||||
|
await ctx.send(_("You must give a value of zero or greater!"))
|
||||||
|
return
|
||||||
|
if seconds > 60 * 60 * 24 * 14: # 14 days
|
||||||
|
await ctx.send(_("The delay cannot be longer than 14 days!"))
|
||||||
|
return
|
||||||
|
|
||||||
|
await ctx.bot._config.help.delete_delay.set(seconds)
|
||||||
|
if seconds == 0:
|
||||||
|
await ctx.send(_("Done. Help messages will not be deleted now."))
|
||||||
|
else:
|
||||||
|
await ctx.send(_("Done. The delete delay has been set to {} seconds.").format(seconds))
|
||||||
|
|
||||||
@helpset.command(name="tagline")
|
@helpset.command(name="tagline")
|
||||||
async def helpset_tagline(self, ctx: commands.Context, *, tagline: str = None):
|
async def helpset_tagline(self, ctx: commands.Context, *, tagline: str = None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user