mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Cleanup] Hotfix for [p]cleanup after (#2004)
* [Cleanup] Hotfix for [p]cleanup after * Reformat * Log warning for any 3rd party devs using broken helper
This commit is contained in:
parent
dc9a85ca98
commit
7959654dc8
@ -68,6 +68,12 @@ class Cleanup:
|
|||||||
- The message is less than 14 days old
|
- The message is less than 14 days old
|
||||||
- The message is not pinned
|
- The message is not pinned
|
||||||
"""
|
"""
|
||||||
|
if after is not None:
|
||||||
|
log.error(
|
||||||
|
"The `after` parameter for the `Cleanup.get_messages_for_deletion` method is "
|
||||||
|
"currently broken, see PRs #1980 and #2004 for details."
|
||||||
|
)
|
||||||
|
|
||||||
to_delete = []
|
to_delete = []
|
||||||
too_old = False
|
too_old = False
|
||||||
|
|
||||||
@ -238,23 +244,35 @@ class Cleanup:
|
|||||||
await ctx.send(_("This command can only be used on bots with bot accounts."))
|
await ctx.send(_("This command can only be used on bots with bot accounts."))
|
||||||
return
|
return
|
||||||
|
|
||||||
after = await channel.get_message(message_id)
|
try:
|
||||||
|
message = await channel.get_message(message_id)
|
||||||
if not after:
|
except discord.NotFound:
|
||||||
await ctx.send(_("Message not found."))
|
await ctx.send(_("Message not found."))
|
||||||
return
|
return
|
||||||
|
|
||||||
to_delete = await self.get_messages_for_deletion(
|
if (ctx.message.created_at - message.created_at).days >= 14:
|
||||||
ctx, channel, 0, limit=None, after=after, delete_pinned=delete_pinned
|
await ctx.send("The specified message must be less than 14 days old.")
|
||||||
)
|
return
|
||||||
|
|
||||||
|
if not delete_pinned:
|
||||||
|
pinned_msgs = await channel.pins()
|
||||||
|
to_exclude = set(m for m in pinned_msgs if m.created_at > message.created_at)
|
||||||
|
else:
|
||||||
|
to_exclude = None
|
||||||
|
|
||||||
|
if to_exclude:
|
||||||
|
to_delete = await channel.history(limit=None, after=message).flatten()
|
||||||
|
to_delete = set(to_delete) - to_exclude
|
||||||
|
await channel.delete_messages(to_delete)
|
||||||
|
num_deleted = len(to_delete)
|
||||||
|
else:
|
||||||
|
num_deleted = len(await channel.purge(limit=None, after=message))
|
||||||
|
|
||||||
reason = "{}({}) deleted {} messages in channel {}.".format(
|
reason = "{}({}) deleted {} messages in channel {}.".format(
|
||||||
author.name, author.id, len(to_delete), channel.name
|
author.name, author.id, num_deleted, channel.name
|
||||||
)
|
)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
await mass_purge(to_delete, channel)
|
|
||||||
|
|
||||||
@cleanup.command()
|
@cleanup.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def messages(self, ctx: commands.Context, number: int, delete_pinned: bool = False):
|
async def messages(self, ctx: commands.Context, number: int, delete_pinned: bool = False):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user