From 04d9dd9c0dc82b4d870c6269ecc3a9e46cd7292e Mon Sep 17 00:00:00 2001 From: Gorialis Date: Tue, 2 Jan 2018 07:59:51 +0900 Subject: Change PartialReactionEmoji to PartialEmoji, add a PartialEmojiConverter --- discord/ext/commands/converter.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'discord/ext') diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index e2397ad2..9e3718b0 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -35,8 +35,8 @@ from .view import StringView __all__ = [ 'Converter', 'MemberConverter', 'UserConverter', 'TextChannelConverter', 'InviteConverter', 'RoleConverter', 'GameConverter', 'ColourConverter', 'VoiceChannelConverter', - 'EmojiConverter','CategoryChannelConverter', 'IDConverter', - 'clean_content' ] + 'EmojiConverter', 'PartialEmojiConverter', 'CategoryChannelConverter', + 'IDConverter', 'clean_content' ] def _get_from_guilds(bot, getter, argument): result = None @@ -397,6 +397,25 @@ class EmojiConverter(IDConverter): return result +class PartialEmojiConverter(Converter): + """Converts to a :class:`PartialEmoji`. + + + This is done by extracting the animated flag, name and ID from the emoji. + """ + @asyncio.coroutine + def convert(self, ctx, argument): + match = re.match(r'<(a?):([a-zA-Z0-9\_]+):([0-9]+)>$', argument) + + if match: + emoji_animated = bool(match.group(1)) + emoji_name = match.group(2) + emoji_id = int(match.group(3)) + + return discord.PartialEmoji(animated=emoji_animated, name=emoji_name, id=emoji_id) + + raise BadArgument('Couldn\'t convert "{}" to PartialEmoji.'.format(argument)) + class clean_content(Converter): """Converts the argument to mention scrubbed version of said content. -- cgit v1.2.3