Red-DiscordBot/redbot/cogs/mod/converters.py
jack1142 adda30cbee
Bump discord.py to 1.7.0 (#4928)
* Bump discord.py, but to the git version for now

* Import GuildConverter from d.py and deprecate our implementation

* Import PartialMessageConverter in our commands extension

* Use newly added `Cog.has_error_handler()` rather than private method

* Update snowflake regex to use 20 as max length

See Rapptz/discord.py#6501

* Use new supported way for custom cooldown buckets

* Include group args in command signature

* Update code to use `Client.close()` over `Client.logout()`

* Add StageChannelConverter and StoreChannelConverter

* Fix AttributeError in licenseinfo
2021-04-05 21:33:19 +02:00

21 lines
718 B
Python

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,20})$")
_mention_regex = re.compile(r"<@!?([0-9]{15,20})>$")
class RawUserIds(Converter):
async def convert(self, ctx, argument):
# This is for the hackban and unban commands, where we receive IDs that
# are most likely not in the guild.
# 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))