From fadf7e93972aea9a33564fc694723c4251218b83 Mon Sep 17 00:00:00 2001 From: gmcaguilar Date: Thu, 25 Jan 2018 20:52:59 +1000 Subject: [PATCH] applied fix for acceptance of both unicode and custom emojis #47 --- rolecall/rolecall.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rolecall/rolecall.py b/rolecall/rolecall.py index 6a6066a..ca8dd16 100644 --- a/rolecall/rolecall.py +++ b/rolecall/rolecall.py @@ -10,6 +10,7 @@ import json import threading from random import randint +import re log = logging.getLogger("red.rolecall") @@ -52,7 +53,8 @@ def __init__(self, bot): def _record_entry(self, entry: Entry): """ record entry to settings file """ - + if type(entry.emoji) is discord.Emoji: + entry.emoji = entry.emoji.name server = self.settings[entry.server.id] server.setdefault(entry.roleboard_channel.id, {}) server[entry.roleboard_channel.id].setdefault(entry.content_or_message_id, {}) @@ -156,12 +158,18 @@ async def rolecall_add(self, ctx, channel: discord.Channel, await self.bot.send_message(channel, err_msg) return - # get emoji name - emoji_name = emoji.replace(':', '') + # get emoji name(if unicode emoji) or get emoji object(if custom emoji) + emoji_name_or_obj = emoji.strip(':') + try: + potential_custom_emoji_id = re.findall('\d+', emoji_name_or_obj)[0] + if potential_custom_emoji_id in [e.id for e in server.emojis]: + emoji_name_or_obj = discord.utils.get(server.emojis, id=potential_custom_emoji_id) + except Exception as e: + pass # determined to be a unicode emoji # make Entry object entry = Entry(server, channel, content_or_message_id, author, - role=role_object, emoji=emoji_name) + role=role_object, emoji=emoji_name_or_obj) # check if message ID was provided. If yes, post the new role to the # message associated with the ID, if not, post the new entry to the