Implement join messages

This commit is contained in:
Jeremy Zhang 2018-08-19 02:55:31 +00:00
parent 38bf9133da
commit 3e27b156a8
4 changed files with 71 additions and 2 deletions

View File

@ -18,6 +18,7 @@ def get_formatted_message(message):
"author": get_message_author(message), "author": get_message_author(message),
"timestamp": format_datetime(message.created_at), "timestamp": format_datetime(message.created_at),
"edited_timestamp": edit_ts, "edited_timestamp": edit_ts,
"type": message.type.value,
} }
if hasattr(message, "mentions"): if hasattr(message, "mentions"):
msg["mentions"] = get_message_mentions(message.mentions) msg["mentions"] = get_message_mentions(message.mentions)

View File

@ -59,7 +59,8 @@ class RedisQueue:
"channel_id": str(x["channel_id"]), "channel_id": str(x["channel_id"]),
"mentions": x["mentions"], "mentions": x["mentions"],
"embeds": x["embeds"], "embeds": x["embeds"],
"reactions": x["reactions"] "reactions": x["reactions"],
"type": x.get("type", 0),
} }
if message["author"]["id"] not in guild_members: if message["author"]["id"] not in guild_members:
member = self.get_guild_member(guild_id, message["author"]["id"]) member = self.get_guild_member(guild_id, message["author"]["id"])

View File

@ -231,6 +231,20 @@ nav .brand-logo {
/* display: table-row*/ /* 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 { ::-webkit-input-placeholder {
color: #636363; color: #636363;
color: var(--placeholder); color: var(--placeholder);

View File

@ -1334,6 +1334,53 @@
$("main").scrollTop($("#chatcontent").outerHeight()); $("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!",
"Wheres {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 "<i class=\"material-icons new-member-arrow\">arrow_forward</i> " + formatted;
}
function fill_discord_messages(messages, jumpscroll, replace) { function fill_discord_messages(messages, jumpscroll, replace) {
if (replace === undefined) { if (replace === undefined) {
@ -1364,6 +1411,9 @@
message = parse_emoji_in_message(message); message = parse_emoji_in_message(message);
message.content = message.content.replace(/&lt;https:\/\/(.*?)&gt;/g, "https://$1"); message.content = message.content.replace(/&lt;https:\/\/(.*?)&gt;/g, "https://$1");
message.content = message.content.replace(/&lt;http:\/\/(.*?)&gt;/g, "http://$1"); message.content = message.content.replace(/&lt;http:\/\/(.*?)&gt;/g, "http://$1");
if (message.type == 7) {
message.content = format_new_member_message(message);
}
var username = message.author.username; var username = message.author.username;
if (message.author.nickname) { if (message.author.nickname) {
username = message.author.nickname; username = message.author.nickname;
@ -1384,6 +1434,9 @@
$("#chatcontent p:last-child").find(".channellink").click(function () { $("#chatcontent p:last-child").find(".channellink").click(function () {
select_channel($(this).attr("channelid"), true); select_channel($(this).attr("channelid"), true);
}); });
if (message.type == 7) {
$("#chatcontent p:last-child").addClass("new-member");
}
} else { } else {
replace.html($(rendered).html()); replace.html($(rendered).html());
replace.find(".blockcode").find("br").remove(); replace.find(".blockcode").find("br").remove();
@ -1558,7 +1611,7 @@
for (var i = 1; i < allMessages.length; i++) { for (var i = 1; i < allMessages.length; i++) {
var last = $(allMessages[i - 1]); var last = $(allMessages[i - 1]);
var current = $(allMessages[i]); 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"); current.addClass("collapsed");
} else { } else {
current.removeClass("collapsed"); current.removeClass("collapsed");