Titan/webapp/titanembeds/EmojiParser.py

20 lines
745 B
Python
Raw Normal View History

from titanembeds.utils import discord_api
import re
def parseEmoji(textToParse, guild_id):
_endpoint = "/guilds/{guild_id}".format(guild_id=guild_id)
_method = "GET"
response = discord_api.request(_method, _endpoint)
2017-05-29 02:51:55 +02:00
if 'code' not in response['content']:
return textToParse
emojis = []
2017-05-29 02:51:55 +02:00
emojis = re.findall("<:(.*?):(.*)?>", textToParse)
newText = textToParse
2017-05-29 02:51:55 +02:00
for emoji in response['content']['emojis']:
name = emoji['name']
emojiId = emoji['id']
for emoji2 in emojis:
if name.lower is emoji2.replace(":", "").lower():
2017-05-29 02:51:55 +02:00
newText = newText.replace("<:{}}:{}>".format(name, emojiId), "<img src='https://cdn.discordapp.com/emojis/{}.png'></img>".format(emojiId))
return newText