From 289fdc0eb54de61c67a909cc5348e42e1611d3a8 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sat, 10 Jun 2017 03:43:23 +0000 Subject: [PATCH] Fix emoji not replacing or rendering, also fix visitor fetching 429 error --- webapp/titanembeds/blueprints/api/api.py | 9 ++------- webapp/titanembeds/static/js/embed.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index 4ba5aba..106446c 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -100,17 +100,12 @@ def check_user_in_guild(guild_id): return dbUser is not None and not checkUserRevoke(guild_id) def parse_emoji(textToParse, guild_id): - emojis = [] - emojis = re.findall(":(.*?):", textToParse) guild_emojis = get_guild_emojis(guild_id) - newText = textToParse for gemoji in guild_emojis: emoji_name = gemoji["name"] emoji_id = gemoji["id"] - for usremote in emojis: - if usremote == emoji_name: - newText = newText.replace(":{}:".format(emoji_name), "<:{}:{}>".format(emoji_name, emoji_id)) - return newText + textToParse = textToParse.replace(":{}:".format(emoji_name), "<:{}:{}>".format(emoji_name, emoji_id)) + return textToParse def format_post_content(guild_id, message): diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 19802ec..42c1c73 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -37,6 +37,10 @@ return ((elementTop <= pageBottom) && (elementBottom >= pageTop)); } } + + String.prototype.replaceAll = function(target, replacement) { + return this.split(target).join(replacement); + }; function query_guild() { var url = "/api/query_guild"; @@ -533,7 +537,7 @@ var emoji = emoji_store[i]; var emoji_format = "<:" + emoji.name + ":" + emoji.id + ">"; var rendered = Mustache.render(template, {"id": emoji.id, "name": emoji.name}).trim(); - message.content = message.content.replace(emoji_format, rendered); + message.content = message.content.replaceAll(emoji_format, rendered); } return message; } @@ -621,9 +625,12 @@ $('#loginmodal').modal('open'); Materialize.toast('Session expired! You have been logged out.', 10000); } - setVisitorMode(true); - if (visitor_mode) { - fetchtimeout = setTimeout(run_fetch_routine, 5000); + + if (data.status != 429) { + setVisitorMode(true); + if (visitor_mode) { + fetchtimeout = setTimeout(run_fetch_routine, 5000); + } } }); fet.catch(function(data) {