From 88abe469b6ade0ac201250c0a6ee9c732e3ab7a2 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Thu, 2 Sep 2021 01:08:13 +0200 Subject: [PATCH] Accept mentions in `[p]cleanup user` (#5169) * Accept mentions in `[p]cleanup user` * Updated spacing & formatting on info logging * Whoops... Co-authored-by: Kowlin --- redbot/cogs/cleanup/cleanup.py | 37 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py index e329c0c37..3d835a070 100644 --- a/redbot/cogs/cleanup/cleanup.py +++ b/redbot/cogs/cleanup/cleanup.py @@ -4,6 +4,7 @@ from typing import Callable, List, Optional, Set, Union import discord +from redbot.cogs.mod.converters import RawUserIds from redbot.core import checks, commands from redbot.core.bot import Red from redbot.core.i18n import Translator, cog_i18n @@ -188,7 +189,7 @@ class Cleanup(commands.Cog): ) to_delete.append(ctx.message) - reason = "{}({}) deleted {} messages containing '{}' in channel {}.".format( + reason = "{}({}) deleted {} messages containing '{}' in channel #{}.".format( author.name, author.id, humanize_number(len(to_delete), override_locale="en_us"), @@ -204,7 +205,11 @@ class Cleanup(commands.Cog): @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def user( - self, ctx: commands.Context, user: str, number: positive_int, delete_pinned: bool = False + self, + ctx: commands.Context, + user: Union[discord.Member, RawUserIds], + number: positive_int, + delete_pinned: bool = False, ): """Delete the last X messages from a specified user in the current channel. @@ -221,15 +226,11 @@ class Cleanup(commands.Cog): channel = ctx.channel member = None - try: - member = await commands.MemberConverter().convert(ctx, user) - except commands.BadArgument: - try: - _id = int(user) - except ValueError: - raise commands.BadArgument() - else: + if isinstance(user, discord.Member): + member = user _id = member.id + else: + _id = user author = ctx.author @@ -254,8 +255,8 @@ class Cleanup(commands.Cog): to_delete.append(ctx.message) reason = ( - "{}({}) deleted {} messages " - " made by {}({}) in channel {}." + "{}({}) deleted {} messages" + " made by {}({}) in channel #{}." "".format( author.name, author.id, @@ -311,7 +312,7 @@ class Cleanup(commands.Cog): channel=channel, number=None, after=after, delete_pinned=delete_pinned ) - reason = "{}({}) deleted {} messages in channel {}.".format( + reason = "{}({}) deleted {} messages in channel #{}.".format( author.name, author.id, humanize_number(len(to_delete), override_locale="en_US"), @@ -366,7 +367,7 @@ class Cleanup(commands.Cog): ) to_delete.append(ctx.message) - reason = "{}({}) deleted {} messages in channel {}.".format( + reason = "{}({}) deleted {} messages in channel #{}.".format( author.name, author.id, humanize_number(len(to_delete), override_locale="en_US"), @@ -418,7 +419,7 @@ class Cleanup(commands.Cog): channel=channel, before=mtwo, after=mone, delete_pinned=delete_pinned ) to_delete.append(ctx.message) - reason = "{}({}) deleted {} messages in channel {}.".format( + reason = "{}({}) deleted {} messages in channel #{}.".format( author.name, author.id, humanize_number(len(to_delete), override_locale="en_US"), @@ -459,7 +460,7 @@ class Cleanup(commands.Cog): ) to_delete.append(ctx.message) - reason = "{}({}) deleted {} messages in channel {}.".format( + reason = "{}({}) deleted {} messages in channel #{}.".format( author.name, author.id, len(to_delete), channel.name ) log.info(reason) @@ -539,8 +540,8 @@ class Cleanup(commands.Cog): to_delete.append(ctx.message) reason = ( - "{}({}) deleted {} " - " command messages in channel {}." + "{}({}) deleted {}" + " command messages in channel #{}." "".format( author.name, author.id,