diff --git a/changelog.d/mod/3523.bugfix.rst b/changelog.d/mod/3523.bugfix.rst new file mode 100644 index 000000000..e4bc1d9e2 --- /dev/null +++ b/changelog.d/mod/3523.bugfix.rst @@ -0,0 +1,2 @@ +Allow mentions in hackban and ban commands. +Have the correct lower bound on length of a snowflake for the converter. \ No newline at end of file diff --git a/redbot/cogs/mod/converters.py b/redbot/cogs/mod/converters.py index 8bed65c77..9bb9da7df 100644 --- a/redbot/cogs/mod/converters.py +++ b/redbot/cogs/mod/converters.py @@ -1,16 +1,20 @@ +import re from redbot.core.commands import Converter, BadArgument from redbot.core.i18n import Translator _ = Translator("Mod", __file__) +_id_regex = re.compile(r"([0-9]{15,21})$") +_mention_regex = re.compile(r"<@!?([0-9]{15,21})>$") + class RawUserIds(Converter): async def convert(self, ctx, argument): - # This is for the hackban command, where we receive IDs that + # This is for the hackban and unban commands, where we receive IDs that # are most likely not in the guild. - # As long as it's numeric and long enough, it makes a good candidate - # to attempt a ban on - if argument.isnumeric() and len(argument) >= 17: - return int(argument) + # Mentions are supported, but most likely won't ever be in cache. + + if match := _id_regex.match(argument) or _mention_regex.match(argument): + return int(match.group(1)) raise BadArgument(_("{} doesn't look like a valid user ID.").format(argument)) diff --git a/redbot/cogs/mod/kickban.py b/redbot/cogs/mod/kickban.py index 5b710f15e..8757f23f2 100644 --- a/redbot/cogs/mod/kickban.py +++ b/redbot/cogs/mod/kickban.py @@ -581,7 +581,7 @@ class KickBanMixin(MixinMeta): @commands.guild_only() @commands.bot_has_permissions(ban_members=True) @checks.admin_or_permissions(ban_members=True) - async def unban(self, ctx: commands.Context, user_id: int, *, reason: str = None): + async def unban(self, ctx: commands.Context, user_id: RawUserIds, *, reason: str = None): """Unban a user from this server. Requires specifying the target user's ID. To find this, you may either: