Fix a crash when an embed has a title but no description

This commit is contained in:
chylex 2018-02-08 21:23:27 +01:00
parent 33ad6fcba5
commit 6186bcea37
3 changed files with 15 additions and 4 deletions

View File

@ -22,6 +22,7 @@ var DISCORD = (function(){
var templateMessage; var templateMessage;
var templateEmbedImage; var templateEmbedImage;
var templateEmbedRich; var templateEmbedRich;
var templateEmbedRichNoDescription;
var templateEmbedRichUnsupported; var templateEmbedRichUnsupported;
var templateEmbedDownload; var templateEmbedDownload;
@ -53,7 +54,11 @@ var DISCORD = (function(){
].join("")); ].join(""));
templateEmbedRich = new TEMPLATE([ templateEmbedRich = new TEMPLATE([
"<div class='embed download'><a href='{url}' class='title'>{t}</a><p>{d}</p></div>" "<div class='embed download'><a href='{url}' class='title'>{t}</a><p class='desc'>{d}</p></div>"
].join(""));
templateEmbedRichNoDescription = new TEMPLATE([
"<div class='embed download'><a href='{url}' class='title'>{t}</a></div>"
].join("")); ].join(""));
templateEmbedRichUnsupported = new TEMPLATE([ templateEmbedRichUnsupported = new TEMPLATE([
@ -123,7 +128,7 @@ var DISCORD = (function(){
return STATE.settings.enableImagePreviews ? templateEmbedImage.apply(embed) : ""; return STATE.settings.enableImagePreviews ? templateEmbedImage.apply(embed) : "";
case "rich": case "rich":
return (embed.t ? templateEmbedRich : templateEmbedRichUnsupported).apply(embed); return (embed.t ? (embed.d ? templateEmbedRich : templateEmbedRichNoDescription) : templateEmbedRichUnsupported).apply(embed);
} }
}).join(""); }).join("");
} }

View File

@ -73,7 +73,10 @@
.message .embed .title { .message .embed .title {
font-weight: bold; font-weight: bold;
display: inline-block; display: inline-block;
margin-bottom: 4px; }
.message .embed .desc {
margin-top: 4px;
} }
.message .thumbnail { .message .thumbnail {

View File

@ -179,8 +179,11 @@ SAVEFILE.prototype.convertToMessageObject = function(discordMessage){
if (embed.type === "rich"){ if (embed.type === "rich"){
if (Array.isArray(embed.title) && embed.title.length === 1){ if (Array.isArray(embed.title) && embed.title.length === 1){
conv.t = embed.title[0]; conv.t = embed.title[0];
if (Array.isArray(embed.description) && embed.description.length === 1){
conv.d = embed.description[0]; conv.d = embed.description[0];
} }
}
else{ else{
conv.t = ""; conv.t = "";
} }