From f6b3062ecd7813873285fe6f03b1e5b5e1029de1 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Wed, 12 Apr 2017 06:15:05 -0700 Subject: [PATCH] Simple mention highlighting --- titanembeds/blueprints/api/api.py | 1 + titanembeds/static/js/embed.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/titanembeds/blueprints/api/api.py b/titanembeds/blueprints/api/api.py index 970e147..98cdb64 100644 --- a/titanembeds/blueprints/api/api.py +++ b/titanembeds/blueprints/api/api.py @@ -80,6 +80,7 @@ def update_user_status(guild_id, username, user_key=None): 'avatar': session["avatar"], 'manage_embed': check_user_can_administrate_guild(guild_id), 'username': username, + 'discriminator': session['discriminator'], 'guild_id': guild_id, 'user_id': session['user_id'], 'banned': checkUserBanned(guild_id), diff --git a/titanembeds/static/js/embed.js b/titanembeds/static/js/embed.js index a19230e..7162f74 100644 --- a/titanembeds/static/js/embed.js +++ b/titanembeds/static/js/embed.js @@ -240,6 +240,7 @@ function replace_message_mentions(message) { 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); + message.content = message.content.replace("<@&" + guild_id + ">", "@everyone"); } return message; } @@ -277,6 +278,16 @@ function parse_message_attachments(message) { return message; } +function handle_last_message_mention() { + var lastmsg = $("#chatcontent p:last-child"); + var content = lastmsg.text().toLowerCase(); + var username_discrim = $("#currentusername").text().toLowerCase(); + if (content.includes("@everyone") || content.includes("@" + username_discrim)) { + lastmsg.css( "color", "#ff5252" ); + lastmsg.css( "font-weight", "bold" ); + } +} + function fill_discord_messages(messages, jumpscroll) { if (messages.length == 0) { return last_message_id; @@ -293,6 +304,7 @@ function fill_discord_messages(messages, jumpscroll) { var rendered = Mustache.render(template, {"id": message.id, "full_timestamp": message.formatted_timestamp, "time": message.formatted_time, "username": message.author.username, "discriminator": message.author.discriminator, "content": message.content}); $("#chatcontent").append(rendered); last = message.id; + handle_last_message_mention(); } $("html, body").animate({ scrollTop: $(document).height() }, "slow"); $('#chatcontent').linkify({ @@ -315,7 +327,7 @@ function run_fetch_routine() { } fet.done(function(data) { var status = data.status; - update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id); + update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id, status.discriminator); last_message_id = fill_discord_messages(data.messages, jumpscroll); if (status.manage_embed) { $("#administrate_link").show(); @@ -347,11 +359,11 @@ function run_fetch_routine() { }); } -function update_embed_userchip(authenticated, avatar, username, userid) { +function update_embed_userchip(authenticated, avatar, username, userid, discrim=null) { if (authenticated) { $("#currentuserimage").show(); $("#currentuserimage").attr("src", avatar); - $("#currentusername").text(username); + $("#currentusername").text(username + "#" + discrim); } else { $("#currentuserimage").hide(); $("#currentusername").text(username + "#" + userid);