From 594c4c3ce1d51be9a3381edacdf0a2cbbc4763bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Thu, 13 Sep 2018 15:36:31 +0200 Subject: [PATCH] Convert emojis in extra commands --- clients/discord.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clients/discord.py b/clients/discord.py index 0e770db..82bda32 100644 --- a/clients/discord.py +++ b/clients/discord.py @@ -18,6 +18,8 @@ ANNOUNCEMENT_PATTERN = re.compile(r'''^ Come\s+and\s+say\s+hi\s+at\s+(?P.+)\s+! $''', re.VERBOSE) +EMOJI_PATTERN = re.compile(r'lilial1\w+') + def cooldown(retries, timeout, failure): def do_cooldown(function): @@ -80,6 +82,12 @@ class DiscordClient(discord.Client): await action(server, message.author.id, message, **m.groupdict()) for cmd, resp in self.extra_commands.items(): if cmd == message.content: + def repl(m): + emoji = discord.utils.get(message.server.emojis, name=m.group(0)) + if not emoji: + emoji = discord.utils.get(self.get_all_emojis(), name=m.group(0)) + return str(emoji) if emoji else m.string + resp = EMOJI_PATTERN.sub(repl, resp) await self.send_message(message.channel, resp.format(user=message.author.mention)) def _guess_gifted_subs(self, nick, time, threshold):