[Mod] Use a better converter for Hackban & Unban (#3524)

closes #3523
This commit is contained in:
DiscordLiz
2020-02-08 07:43:03 -05:00
committed by GitHub
parent 9a278213bd
commit 8e3a76186b
3 changed files with 12 additions and 6 deletions

View File

@@ -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))