[commands] Address incorrect use of subclass (from type perspective)

This is a follow up from #6641
This commit is contained in:
Michael H 2021-04-05 21:39:17 -04:00 committed by GitHub
parent d0476e98df
commit 682b73abb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -263,7 +263,7 @@ class UserConverter(IDConverter[discord.User]):
return result return result
class PartialMessageConverter(IDConverter[discord.PartialMessage], Generic[T]): class PartialMessageConverter(Converter[discord.PartialMessage]):
"""Converts to a :class:`discord.PartialMessage`. """Converts to a :class:`discord.PartialMessage`.
.. versionadded:: 1.7 .. versionadded:: 1.7
@ -274,7 +274,8 @@ class PartialMessageConverter(IDConverter[discord.PartialMessage], Generic[T]):
2. By message ID (The message is assumed to be in the context channel.) 2. By message ID (The message is assumed to be in the context channel.)
3. By message URL 3. By message URL
""" """
def _get_id_matches(self, argument): @staticmethod
def _get_id_matches(argument):
id_regex = re.compile(r'(?:(?P<channel_id>[0-9]{15,20})-)?(?P<message_id>[0-9]{15,20})$') id_regex = re.compile(r'(?:(?P<channel_id>[0-9]{15,20})-)?(?P<message_id>[0-9]{15,20})$')
link_regex = re.compile( link_regex = re.compile(
r'https?://(?:(ptb|canary|www)\.)?discord(?:app)?\.com/channels/' r'https?://(?:(ptb|canary|www)\.)?discord(?:app)?\.com/channels/'
@ -294,7 +295,7 @@ class PartialMessageConverter(IDConverter[discord.PartialMessage], Generic[T]):
raise ChannelNotFound(channel_id) raise ChannelNotFound(channel_id)
return discord.PartialMessage(channel=channel, id=message_id) return discord.PartialMessage(channel=channel, id=message_id)
class MessageConverter(PartialMessageConverter[discord.Message]): class MessageConverter(IDConverter[discord.Message]):
"""Converts to a :class:`discord.Message`. """Converts to a :class:`discord.Message`.
.. versionadded:: 1.1 .. versionadded:: 1.1
@ -309,7 +310,7 @@ class MessageConverter(PartialMessageConverter[discord.Message]):
Raise :exc:`.ChannelNotFound`, :exc:`.MessageNotFound` or :exc:`.ChannelNotReadable` instead of generic :exc:`.BadArgument` Raise :exc:`.ChannelNotFound`, :exc:`.MessageNotFound` or :exc:`.ChannelNotReadable` instead of generic :exc:`.BadArgument`
""" """
async def convert(self, ctx: Context, argument: str) -> discord.Message: async def convert(self, ctx: Context, argument: str) -> discord.Message:
message_id, channel_id = self._get_id_matches(argument) message_id, channel_id = PartialMessageConverter._get_id_matches(argument)
message = ctx.bot._connection._get_message(message_id) message = ctx.bot._connection._get_message(message_id)
if message: if message:
return message return message