Accept mentions in [p]cleanup user (#5169)

* Accept mentions in `[p]cleanup user`

* Updated spacing & formatting on info logging

* Whoops...

Co-authored-by: Kowlin <boxedpp@gmail.com>
This commit is contained in:
jack1142 2021-09-02 01:08:13 +02:00 committed by GitHub
parent b0f93a3ce1
commit 88abe469b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
@ -255,7 +256,7 @@ class Cleanup(commands.Cog):
reason = (
"{}({}) deleted {} messages"
" made by {}({}) in channel {}."
" 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)
@ -540,7 +541,7 @@ class Cleanup(commands.Cog):
reason = (
"{}({}) deleted {}"
" command messages in channel {}."
" command messages in channel #{}."
"".format(
author.name,
author.id,