mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 03:38:53 -05:00
[Cleanup] Pass reason for bulk message deletion to audit log (#5863)
Co-authored-by: Jakub Kuczys <me@jacken.men>
This commit is contained in:
parent
501c2b97dd
commit
64e6044aba
@ -227,7 +227,7 @@ class Cleanup(commands.Cog):
|
|||||||
)
|
)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
await mass_purge(to_delete, channel)
|
await mass_purge(to_delete, channel, reason=reason)
|
||||||
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
||||||
|
|
||||||
@cleanup.command()
|
@cleanup.command()
|
||||||
@ -298,7 +298,7 @@ class Cleanup(commands.Cog):
|
|||||||
)
|
)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
await mass_purge(to_delete, channel)
|
await mass_purge(to_delete, channel, reason=reason)
|
||||||
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
||||||
|
|
||||||
@cleanup.command()
|
@cleanup.command()
|
||||||
@ -351,7 +351,7 @@ class Cleanup(commands.Cog):
|
|||||||
)
|
)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
await mass_purge(to_delete, channel)
|
await mass_purge(to_delete, channel, reason=reason)
|
||||||
await self.send_optional_notification(len(to_delete), channel)
|
await self.send_optional_notification(len(to_delete), channel)
|
||||||
|
|
||||||
@cleanup.command()
|
@cleanup.command()
|
||||||
@ -407,7 +407,7 @@ class Cleanup(commands.Cog):
|
|||||||
)
|
)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
await mass_purge(to_delete, channel)
|
await mass_purge(to_delete, channel, reason=reason)
|
||||||
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
||||||
|
|
||||||
@cleanup.command()
|
@cleanup.command()
|
||||||
@ -460,7 +460,7 @@ class Cleanup(commands.Cog):
|
|||||||
)
|
)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
await mass_purge(to_delete, channel)
|
await mass_purge(to_delete, channel, reason=reason)
|
||||||
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
||||||
|
|
||||||
@cleanup.command()
|
@cleanup.command()
|
||||||
@ -499,7 +499,7 @@ class Cleanup(commands.Cog):
|
|||||||
)
|
)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
await mass_purge(to_delete, channel)
|
await mass_purge(to_delete, channel, reason=reason)
|
||||||
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
||||||
|
|
||||||
@cleanup.command(name="bot")
|
@cleanup.command(name="bot")
|
||||||
@ -586,7 +586,7 @@ class Cleanup(commands.Cog):
|
|||||||
)
|
)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
await mass_purge(to_delete, channel)
|
await mass_purge(to_delete, channel, reason=reason)
|
||||||
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
await self.send_optional_notification(len(to_delete), channel, subtract_invoking=True)
|
||||||
|
|
||||||
@cleanup.command(name="self")
|
@cleanup.command(name="self")
|
||||||
@ -673,7 +673,7 @@ class Cleanup(commands.Cog):
|
|||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
if can_mass_purge:
|
if can_mass_purge:
|
||||||
await mass_purge(to_delete, channel)
|
await mass_purge(to_delete, channel, reason=reason)
|
||||||
else:
|
else:
|
||||||
await slow_deletion(to_delete)
|
await slow_deletion(to_delete)
|
||||||
await self.send_optional_notification(
|
await self.send_optional_notification(
|
||||||
@ -733,7 +733,7 @@ class Cleanup(commands.Cog):
|
|||||||
)
|
)
|
||||||
|
|
||||||
to_delete.append(ctx.message)
|
to_delete.append(ctx.message)
|
||||||
await mass_purge(to_delete, ctx.channel)
|
await mass_purge(to_delete, ctx.channel, "Duplicate message cleanup")
|
||||||
await self.send_optional_notification(len(to_delete), ctx.channel, subtract_invoking=True)
|
await self.send_optional_notification(len(to_delete), ctx.channel, subtract_invoking=True)
|
||||||
|
|
||||||
@commands.group()
|
@commands.group()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import List, Iterable, Union, TYPE_CHECKING, Dict
|
from typing import List, Iterable, Union, TYPE_CHECKING, Dict, Optional
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
@ -12,6 +12,8 @@ if TYPE_CHECKING:
|
|||||||
async def mass_purge(
|
async def mass_purge(
|
||||||
messages: List[discord.Message],
|
messages: List[discord.Message],
|
||||||
channel: Union[discord.TextChannel, discord.VoiceChannel, discord.Thread],
|
channel: Union[discord.TextChannel, discord.VoiceChannel, discord.Thread],
|
||||||
|
*,
|
||||||
|
reason: Optional[str] = None,
|
||||||
):
|
):
|
||||||
"""Bulk delete messages from a channel.
|
"""Bulk delete messages from a channel.
|
||||||
|
|
||||||
@ -29,6 +31,8 @@ async def mass_purge(
|
|||||||
The messages to bulk delete.
|
The messages to bulk delete.
|
||||||
channel : `discord.TextChannel`, `discord.VoiceChannel`, or `discord.Thread`
|
channel : `discord.TextChannel`, `discord.VoiceChannel`, or `discord.Thread`
|
||||||
The channel to delete messages from.
|
The channel to delete messages from.
|
||||||
|
reason : `str`, optional
|
||||||
|
The reason for bulk deletion, which will appear in the audit log.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
------
|
------
|
||||||
@ -43,7 +47,7 @@ async def mass_purge(
|
|||||||
# discord.NotFound can be raised when `len(messages) == 1` and the message does not exist.
|
# discord.NotFound can be raised when `len(messages) == 1` and the message does not exist.
|
||||||
# As a result of this obscure behavior, this error needs to be caught just in case.
|
# As a result of this obscure behavior, this error needs to be caught just in case.
|
||||||
try:
|
try:
|
||||||
await channel.delete_messages(messages[:100])
|
await channel.delete_messages(messages[:100], reason=reason)
|
||||||
except discord.errors.HTTPException:
|
except discord.errors.HTTPException:
|
||||||
pass
|
pass
|
||||||
messages = messages[100:]
|
messages = messages[100:]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user