From d3ac191a674410ac7a2ae9027315172b15fee6e0 Mon Sep 17 00:00:00 2001 From: Nadir Chowdhury Date: Fri, 16 Apr 2021 12:33:44 +0100 Subject: [PATCH] Restrict snowflake regexes to 15-20 digits --- discord/ext/commands/converter.py | 12 ++++++------ discord/message.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 82ea36fd9..b2d280754 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -177,7 +177,7 @@ class MemberConverter(IDConverter[discord.Member]): async def convert(self, ctx: Context, argument: str) -> discord.Member: bot = ctx.bot - match = self._get_id_match(argument) or re.match(r'<@!?([0-9]+)>$', argument) + match = self._get_id_match(argument) or re.match(r'<@!?([0-9]{15,20})>$', argument) guild = ctx.guild result = None user_id = None @@ -230,7 +230,7 @@ class UserConverter(IDConverter[discord.User]): """ async def convert(self, ctx: Context, argument: str) -> discord.User: - match = self._get_id_match(argument) or re.match(r'<@!?([0-9]+)>$', argument) + match = self._get_id_match(argument) or re.match(r'<@!?([0-9]{15,20})>$', argument) result = None state = ctx._state @@ -358,7 +358,7 @@ class TextChannelConverter(IDConverter[discord.TextChannel]): def _resolve_channel(ctx: Context, argument: str, iterable: Iterable[CT], type: Type[CT]) -> CT: bot = ctx.bot - match = IDConverter._get_id_match(argument) or re.match(r'<#([0-9]+)>$', argument) + match = IDConverter._get_id_match(argument) or re.match(r'<#([0-9]{15,20})>$', argument) result = None guild = ctx.guild @@ -570,7 +570,7 @@ class RoleConverter(IDConverter[discord.Role]): if not guild: raise NoPrivateMessage() - match = self._get_id_match(argument) or re.match(r'<@&([0-9]+)>$', argument) + match = self._get_id_match(argument) or re.match(r'<@&([0-9]{15,20})>$', argument) if match: result = guild.get_role(int(match.group(1))) else: @@ -649,7 +649,7 @@ class EmojiConverter(IDConverter[discord.Emoji]): """ async def convert(self, ctx: Context, argument: str) -> discord.Emoji: - match = self._get_id_match(argument) or re.match(r'$', argument) + match = self._get_id_match(argument) or re.match(r'$', argument) result = None bot = ctx.bot guild = ctx.guild @@ -687,7 +687,7 @@ class PartialEmojiConverter(Converter[discord.PartialEmoji]): """ async def convert(self, ctx: Context, argument: str) -> discord.PartialEmoji: - match = re.match(r'<(a?):([a-zA-Z0-9\_]+):([0-9]+)>$', argument) + match = re.match(r'<(a?):([a-zA-Z0-9\_]{1,32}):([0-9]{15,20})>$', argument) if match: emoji_animated = bool(match.group(1)) diff --git a/discord/message.py b/discord/message.py index 513477708..eadd03e52 100644 --- a/discord/message.py +++ b/discord/message.py @@ -763,21 +763,21 @@ class Message(Hashable): This allows you to receive the user IDs of mentioned users even in a private message context. """ - return [int(x) for x in re.findall(r'<@!?([0-9]+)>', self.content)] + return [int(x) for x in re.findall(r'<@!?([0-9]{15,20})>', self.content)] @utils.cached_slot_property('_cs_raw_channel_mentions') def raw_channel_mentions(self): """List[:class:`int`]: A property that returns an array of channel IDs matched with the syntax of ``<#channel_id>`` in the message content. """ - return [int(x) for x in re.findall(r'<#([0-9]+)>', self.content)] + return [int(x) for x in re.findall(r'<#([0-9]{15,20})>', self.content)] @utils.cached_slot_property('_cs_raw_role_mentions') def raw_role_mentions(self): """List[:class:`int`]: A property that returns an array of role IDs matched with the syntax of ``<@&role_id>`` in the message content. """ - return [int(x) for x in re.findall(r'<@&([0-9]+)>', self.content)] + return [int(x) for x in re.findall(r'<@&([0-9]{15,20})>', self.content)] @utils.cached_slot_property('_cs_channel_mentions') def channel_mentions(self):