From 3e27b156a89cadbcca1b0cd8c44965a7eb4b660d Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sun, 19 Aug 2018 02:55:31 +0000 Subject: [PATCH] Implement join messages --- discordbot/titanembeds/utils.py | 1 + webapp/titanembeds/redisqueue.py | 3 +- webapp/titanembeds/static/css/embed.css | 14 +++++++ webapp/titanembeds/static/js/embed.js | 55 ++++++++++++++++++++++++- 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/discordbot/titanembeds/utils.py b/discordbot/titanembeds/utils.py index 1bf7a6e..0ef463b 100644 --- a/discordbot/titanembeds/utils.py +++ b/discordbot/titanembeds/utils.py @@ -18,6 +18,7 @@ def get_formatted_message(message): "author": get_message_author(message), "timestamp": format_datetime(message.created_at), "edited_timestamp": edit_ts, + "type": message.type.value, } if hasattr(message, "mentions"): msg["mentions"] = get_message_mentions(message.mentions) diff --git a/webapp/titanembeds/redisqueue.py b/webapp/titanembeds/redisqueue.py index 8d41fe3..2ef7ea2 100644 --- a/webapp/titanembeds/redisqueue.py +++ b/webapp/titanembeds/redisqueue.py @@ -59,7 +59,8 @@ class RedisQueue: "channel_id": str(x["channel_id"]), "mentions": x["mentions"], "embeds": x["embeds"], - "reactions": x["reactions"] + "reactions": x["reactions"], + "type": x.get("type", 0), } if message["author"]["id"] not in guild_members: member = self.get_guild_member(guild_id, message["author"]["id"]) diff --git a/webapp/titanembeds/static/css/embed.css b/webapp/titanembeds/static/css/embed.css index b6cf1bd..9112f3e 100644 --- a/webapp/titanembeds/static/css/embed.css +++ b/webapp/titanembeds/static/css/embed.css @@ -231,6 +231,20 @@ nav .brand-logo { /* display: table-row*/ /*}*/ +#chatcontent .new-member .new-member-arrow { + color: green; + cursor: pointer; + vertical-align: bottom; +} + +#chatcontent .new-member .chatusername, #chatcontent .new-member .authoravatar{ + display: none; +} + +#chatcontent .new-member .chatmessage { + display: inline; +} + ::-webkit-input-placeholder { color: #636363; color: var(--placeholder); diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 83633b5..79bfad0 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -1334,6 +1334,53 @@ $("main").scrollTop($("#chatcontent").outerHeight()); } } + + function format_new_member_message(message) { + var formats = [ + "{0} just joined the server - glhf!", + "{0} just joined. Everyone, look busy!", + "{0} just joined. Can I get a heal?", + "{0} joined your party.", + "{0} joined. You must construct additional pylons.", + "Ermagherd. {0} is here.", + "Welcome, {0}. Stay awhile and listen.", + "Welcome, {0}. We were expecting you ( ͡° ͜ʖ ͡°)", + "Welcome, {0}. We hope you brought pizza.", + "Welcome {0}. Leave your weapons by the door.", + "A wild {0} appeared.", + "Swoooosh. {0} just landed.", + "Brace yourselves. {0} just joined the server.", + "{0} just joined. Hide your bananas.", + "{0} just arrived. Seems OP - please nerf.", + "{0} just slid into the server.", + "A {0} has spawned in the server.", + "Big {0} showed up!", + "Where’s {0}? In the server!", + "{0} hopped into the server. Kangaroo!!", + "{0} just showed up. Hold my beer.", + "Challenger approaching - {0} has appeared!", + "It's a bird! It's a plane! Nevermind, it's just {0}.", + "It's {0}! Praise the sun! [T]/", + "Never gonna give {0} up. Never gonna let {0} down.", + "Ha! {0} has joined! You activated my trap card!", + "Cheers, love! {0}'s here!", + "Hey! Listen! {0} has joined!", + "We've been expecting you {0}", + "It's dangerous to go alone, take {0}!", + "{0} has joined the server! It's super effective!", + "Cheers, love! {0} is here!", + "{0} is here, as the prophecy foretold.", + "{0} has arrived. Party's over.", + "Ready player {0}", + "{0} is here to kick butt and chew bubblegum. And {0} is all out of gum.", + "Hello. Is it {0} you're looking for?", + "{0} has joined. Stay a while and listen!", + "Roses are red, violets are blue, {0} joined this server with you", + ]; + var index = moment(message.timestamp).unix() % formats.length; + var formatted = formats[index].replace(/\{0\}/g, message.author.username); + return "arrow_forward " + formatted; + } function fill_discord_messages(messages, jumpscroll, replace) { if (replace === undefined) { @@ -1364,6 +1411,9 @@ message = parse_emoji_in_message(message); message.content = message.content.replace(/<https:\/\/(.*?)>/g, "https://$1"); message.content = message.content.replace(/<http:\/\/(.*?)>/g, "http://$1"); + if (message.type == 7) { + message.content = format_new_member_message(message); + } var username = message.author.username; if (message.author.nickname) { username = message.author.nickname; @@ -1384,6 +1434,9 @@ $("#chatcontent p:last-child").find(".channellink").click(function () { select_channel($(this).attr("channelid"), true); }); + if (message.type == 7) { + $("#chatcontent p:last-child").addClass("new-member"); + } } else { replace.html($(rendered).html()); replace.find(".blockcode").find("br").remove(); @@ -1558,7 +1611,7 @@ for (var i = 1; i < allMessages.length; i++) { var last = $(allMessages[i - 1]); var current = $(allMessages[i]); - if (last.attr("discord_userid") == current.attr("discord_userid") && current.attr("discord_userid") && moment(current.attr("timestamp")).isSame(moment(last.attr("timestamp")), "hour")) { + if (!last.hasClass("new-member") && last.attr("discord_userid") == current.attr("discord_userid") && current.attr("discord_userid") && moment(current.attr("timestamp")).isSame(moment(last.attr("timestamp")), "hour")) { current.addClass("collapsed"); } else { current.removeClass("collapsed");