From 68d8882d3e786399b98f740941c27882b1015d88 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Thu, 10 Aug 2017 02:56:45 +0000 Subject: [PATCH] Fix mentions with nicknames --- discordbot/titanembeds/database/__init__.py | 2 -- webapp/titanembeds/database/messages.py | 5 +++++ webapp/titanembeds/static/js/embed.js | 8 ++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py index 1911793..3c22c11 100644 --- a/discordbot/titanembeds/database/__init__.py +++ b/discordbot/titanembeds/database/__init__.py @@ -81,8 +81,6 @@ class DatabaseInterface(object): def get_message_mentions(self, mentions): ments = [] for author in mentions: - if author.nick: - author.name = author.nick ments.append({ "username": author.name, "discriminator": author.discriminator, diff --git a/webapp/titanembeds/database/messages.py b/webapp/titanembeds/database/messages.py index 16f1f04..fbe497f 100644 --- a/webapp/titanembeds/database/messages.py +++ b/webapp/titanembeds/database/messages.py @@ -54,5 +54,10 @@ def get_channel_messages(guild_id, channel_id, after_snowflake=None): message["author"]["nickname"] = None if member: message["author"]["nickname"] = member.nickname + for mention in message["mentions"]: + author = get_guild_member(guild_id, mention["id"]) + mention["nickname"] = None + if author: + mention["nickname"] = author.nickname msgs.append(message) return msgs diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 64e5de5..cc20b0b 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -510,8 +510,12 @@ var mentions = message.mentions; for (var i = 0; i < mentions.length; i++) { var mention = mentions[i]; - message.content = message.content.replace(new RegExp("<@" + mention.id + ">", 'g'), "@" + mention.username + "#" + mention.discriminator); - message.content = message.content.replace(new RegExp("<@!" + mention.id + ">", 'g'), "@" + mention.username + "#" + mention.discriminator); + var username = mention.username; + if (mention.nickname) { + username = mention.nickname; + } + message.content = message.content.replace(new RegExp("<@" + mention.id + ">", 'g'), "@" + username + "#" + mention.discriminator); + message.content = message.content.replace(new RegExp("<@!" + mention.id + ">", 'g'), "@" + username + "#" + mention.discriminator); message.content = message.content.replace("<@&" + guild_id + ">", "@everyone"); } return message;