diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py index d2bbf39..bca6b8b 100644 --- a/discordbot/titanembeds/database/__init__.py +++ b/discordbot/titanembeds/database/__init__.py @@ -69,6 +69,8 @@ class DatabaseInterface(object): def get_message_author(self, message): author = message.author + if author.nick is not None: + author.name = author.nick obj = { "username": author.name, "discriminator": author.discriminator, @@ -81,6 +83,8 @@ 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, @@ -264,7 +268,7 @@ class DatabaseInterface(object): dbmember.active = active dbmember.username = member.name dbmember.discriminator = member.discriminator - dbmember.nick = member.nick + dbmember.nickname = member.nick dbmember.avatar = member.avatar dbmember.roles = json.dumps(self.list_role_ids(member.roles)) session.commit() diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index c61e7c4..11a315e 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -109,7 +109,7 @@ def parse_emoji(textToParse, guild_id): return textToParse -def format_post_content(guild_id, channel_id, message): +def format_post_content(guild_id, channel_id, message, dbUser): illegal_post = False illegal_reasons = [] message = message.replace("<", "\<") @@ -140,7 +140,11 @@ def format_post_content(guild_id, channel_id, message): if (session['unauthenticated']): message = u"**[{}#{}]** {}".format(session['username'], session['user_id'], message) else: - message = u"**<{}#{}>** {}".format(session['username'], session['discriminator'], message) # I would like to do a @ mention, but i am worried about notif spam + username = session['username'] + if dbUser: + if dbUser.nickname: + username = dbUser.nickname + message = u"**<{}#{}>** {}".format(username, session['discriminator'], message) # I would like to do a @ mention, but i am worried about notify spam return (message, illegal_post, illegal_reasons) def format_everyone_mention(channel, content): @@ -364,11 +368,15 @@ def post(): guild_id = request.form.get("guild_id") channel_id = request.form.get('channel_id') content = request.form.get('content') - content, illegal_post, illegal_reasons = format_post_content(guild_id, channel_id, content) + if "user_id" in session: + dbUser = GuildMembers.query.filter(GuildMembers.guild_id == guild_id).filter(GuildMembers.user_id == session['user_id']).first() + else: + dbUser = None if user_unauthenticated(): key = session['user_keys'][guild_id] else: key = None + content, illegal_post, illegal_reasons = format_post_content(guild_id, channel_id, content, dbUser) status = update_user_status(guild_id, session['username'], key) message = {} if illegal_post: @@ -392,6 +400,9 @@ def post(): avatar = url_for('static', filename='img/titanembeds_round.png', _external=True) else: username = session["username"] + if dbUser: + if dbUser.nickname: + username = dbUser.nickname if content.startswith("(Titan Dev) "): content = content[12:] username = "(Titan Dev) " + username