1
0
mirror of https://github.com/chylex/Discord-History-Tracker.git synced 2025-04-10 17:15:43 +02:00

Add support for basic rich embeds and webhooks

Closes 
This commit is contained in:
chylex 2018-02-05 16:03:59 +01:00
parent a298061098
commit 5d06f5f181
4 changed files with 46 additions and 6 deletions

View File

@ -21,6 +21,8 @@ m
f
e
a
t
d
author
id
username
@ -30,6 +32,8 @@ editedTimestamp
mentions
embeds
attachments
title
description
toDate
memoizedProps
props

View File

@ -21,6 +21,8 @@ var DISCORD = (function(){
var templateChannelPrivate;
var templateMessage;
var templateEmbedImage;
var templateEmbedRich;
var templateEmbedRichUnsupported;
var templateEmbedDownload;
return {
@ -50,6 +52,14 @@ var DISCORD = (function(){
"<a href='{url}' class='embed thumbnail'><img src='{url}' alt='(image attachment not found)'></a><br>"
].join(""));
templateEmbedRich = new TEMPLATE([
"<div class='embed download'><a href='{url}' class='title'>{t}</a><p>{d}</p></div>"
].join(""));
templateEmbedRichUnsupported = new TEMPLATE([
"<div class='embed download'><p>(Formatted embeds are currently not supported)</p></div>"
].join(""));
templateEmbedDownload = new TEMPLATE([
"<a href='{url}' class='embed download'>Download {filename}</a>"
].join(""));
@ -108,7 +118,13 @@ var DISCORD = (function(){
}
return value.map(embed => {
return embed.type === "image" && STATE.settings.enableImagePreviews ? templateEmbedImage.apply(embed) : "";
switch(embed.type){
case "image":
return STATE.settings.enableImagePreviews ? templateEmbedImage.apply(embed) : "";
case "rich":
return (embed.t ? templateEmbedRich : templateEmbedRichUnsupported).apply(embed);
}
}).join("");
}
else if (property === "attachments"){

View File

@ -70,6 +70,12 @@
margin-top: 8px;
}
.message .embed .title {
font-weight: bold;
display: inline-block;
margin-bottom: 4px;
}
.message .thumbnail {
max-width: calc(100% - 20px);
max-height: 320px;

View File

@ -170,15 +170,29 @@ SAVEFILE.prototype.convertToMessageObject = function(discordMessage){
}
if (discordMessage.embeds.length > 0){
obj.e = discordMessage.embeds.map(embed => ({
"url": embed.url,
"type": embed.type
}));
obj.e = discordMessage.embeds.map(embed => {
let conv = {
url: embed.url,
type: embed.type
};
if (embed.type === "rich"){
if (Array.isArray(embed.title) && embed.title.length === 1){
conv.t = embed.title[0];
conv.d = embed.description[0];
}
else{
conv.t = "";
}
}
return conv;
});
}
if (discordMessage.attachments.length > 0){
obj.a = discordMessage.attachments.map(attachment => ({
"url": attachment.url
url: attachment.url
}));
}