aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2021-08-28 23:33:32 +0300
committerGravatar mbaruh <[email protected]>2021-08-28 23:33:32 +0300
commit7b0cb52bc05261200a03428a51a48813eb3ccf0b (patch)
tree68a76c964099b945abf46be8181572cebe3d2098
parentAdd checkmark after command completes in mod channels (diff)
Send message when no messages found
This commit changes the clean command to send a message instead of raising BadArgument when no messages are found. Not finding messages is not an error, and doesn't necessarily require the help embed to spring up, just that the parameters might need tweaking.
-rw-r--r--bot/exts/moderation/clean.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/bot/exts/moderation/clean.py b/bot/exts/moderation/clean.py
index f8526b1b9..1d323fa0b 100644
--- a/bot/exts/moderation/clean.py
+++ b/bot/exts/moderation/clean.py
@@ -209,15 +209,17 @@ class Clean(Cog):
return deleted
- async def _log_clean(self, messages: list[Message], channels: CleanChannels, invoker: User) -> None:
- """Log the deleted messages to the modlog."""
+ async def _log_clean(self, messages: list[Message], channels: CleanChannels, ctx: Context) -> bool:
+ """Log the deleted messages to the modlog. Return True if logging was successful."""
if not messages:
# Can't build an embed, nothing to clean!
- raise BadArgument("No matching messages could be found.")
+ delete_after = None if is_mod_channel(ctx.channel) else 5
+ await ctx.send(":x: No matching messages could be found.", delete_after=delete_after)
+ return False
# Reverse the list to have reverse chronological order
log_messages = reversed(messages)
- log_url = await self.mod_log.upload_log(log_messages, invoker.id)
+ log_url = await self.mod_log.upload_log(log_messages, ctx.author.id)
# Build the embed and send it
if channels == "*":
@@ -227,7 +229,7 @@ class Clean(Cog):
message = (
f"**{len(messages)}** messages deleted in {target_channels} by "
- f"{invoker.mention}\n\n"
+ f"{ctx.author.mention}\n\n"
f"A log of the deleted messages can be found [here]({log_url})."
)
@@ -239,6 +241,8 @@ class Clean(Cog):
channel_id=Channels.mod_log,
)
+ return True
+
# endregion
async def _clean_messages(
@@ -345,9 +349,9 @@ class Clean(Cog):
deleted_messages = await self._delete_found(message_mappings)
self.cleaning = False
- await self._log_clean(deleted_messages, channels, ctx.author)
+ logged = await self._log_clean(deleted_messages, channels, ctx)
- if is_mod_channel(ctx.channel):
+ if logged and is_mod_channel(ctx.channel):
await ctx.message.add_reaction(Emojis.check_mark)
# region: Commands