From 63979835ab4757409dba9177b4f1f4a43ffab4e3 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Thu, 1 Mar 2018 07:57:45 +0000 Subject: [PATCH] Animated Emoji Support, Closes #85 --- discordbot/titanembeds/utils.py | 3 ++- webapp/titanembeds/blueprints/api/api.py | 6 +++++- webapp/titanembeds/static/js/embed.js | 11 ++++++++--- webapp/titanembeds/templates/embed.html.j2 | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/discordbot/titanembeds/utils.py b/discordbot/titanembeds/utils.py index 847f9a4..23dabf8 100644 --- a/discordbot/titanembeds/utils.py +++ b/discordbot/titanembeds/utils.py @@ -44,7 +44,8 @@ def get_emojis_list(guildemojis): "require_colons": emote.require_colons, "managed": emote.managed, "roles": list_role_ids(emote.roles), - "url": emote.url + "url": emote.url, + "animated": emote.animated }) return emojis diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index 8a9f685..6ac5610 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -21,7 +21,11 @@ def parse_emoji(textToParse, guild_id): for gemoji in guild_emojis: emoji_name = gemoji["name"] emoji_id = gemoji["id"] - textToParse = textToParse.replace(":{}:".format(emoji_name), "<:{}:{}>".format(emoji_name, emoji_id)) + emoji_animated = gemoji["animated"] + if emoji_animated: + textToParse = textToParse.replace(":{}:".format(emoji_name), "".format(emoji_name, emoji_id)) + else: + textToParse = textToParse.replace(":{}:".format(emoji_name), "<:{}:{}>".format(emoji_name, emoji_id)) return textToParse diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 77c5793..27e0095 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -212,7 +212,7 @@ Mustache.parse(template); for (var i = 0; i < emoji_store.length; i++) { var emoji = emoji_store[i]; - var rendered = Mustache.render(template, {"id": emoji.id, "name": emoji.name}).trim(); + var rendered = Mustache.render(template, {"id": emoji.id, "name": emoji.name, "animated": emoji.animated}).trim(); var jqueryed = $(rendered); jqueryed.click(function () { var emote_name = $(this).attr("data-tooltip"); @@ -995,8 +995,13 @@ Mustache.parse(template); for (var i = 0; i < emoji_store.length; i++) { var emoji = emoji_store[i]; - var emoji_format = "<:" + emoji.name + ":" + emoji.id + ">"; - var rendered = Mustache.render(template, {"id": emoji.id, "name": emoji.name}).trim(); + var emoji_format = ""; + if (emoji.animated) { + emoji_format = "<a:" + emoji.name + ":" + emoji.id + ">"; + } else { + emoji_format = "<:" + emoji.name + ":" + emoji.id + ">"; + } + var rendered = Mustache.render(template, {"id": emoji.id, "name": emoji.name, "animated": emoji.animated}).trim(); message.content = message.content.replaceAll(emoji_format, rendered); } var rendered = Mustache.render(template, {"id": "$2", "name": "$1"}).trim(); diff --git a/webapp/titanembeds/templates/embed.html.j2 b/webapp/titanembeds/templates/embed.html.j2 index 757898b..921591c 100644 --- a/webapp/titanembeds/templates/embed.html.j2 +++ b/webapp/titanembeds/templates/embed.html.j2 @@ -322,7 +322,7 @@