[commands] Update MessageConverter link regex

Remove redundant parts of the MessageConverter regexes and support www
This commit is contained in:
Jonathan Feenstra 2020-11-03 16:07:38 +01:00 committed by Rapptz
parent 873ed87caa
commit c54d6f03c5

View File

@ -254,12 +254,11 @@ class MessageConverter(Converter):
.. versionchanged:: 1.5
Raise :exc:`.ChannelNotFound`, `MessageNotFound` or `ChannelNotReadable` instead of generic :exc:`.BadArgument`
"""
async def convert(self, ctx, argument):
id_regex = re.compile(r'^(?:(?P<channel_id>[0-9]{15,21})-)?(?P<message_id>[0-9]{15,21})$')
id_regex = re.compile(r'(?:(?P<channel_id>[0-9]{15,21})-)?(?P<message_id>[0-9]{15,21})$')
link_regex = re.compile(
r'^https?://(?:(ptb|canary)\.)?discord(?:app)?\.com/channels/'
r'(?:([0-9]{15,21})|(@me))'
r'https?://(?:(ptb|canary|www)\.)?discord(?:app)?\.com/channels/'
r'(?:[0-9]{15,21}|@me)'
r'/(?P<channel_id>[0-9]{15,21})/(?P<message_id>[0-9]{15,21})/?$'
)
match = id_regex.match(argument) or link_regex.match(argument)