backport: fix circular conversion in RichEmbed

This commit is contained in:
Lewdcario
2018-07-23 22:41:07 -06:00
parent e4da97e058
commit 6d70da5b1e
3 changed files with 36 additions and 2 deletions

View File

@@ -39,7 +39,7 @@ class RichEmbed {
/**
* Timestamp for this Embed
* @type {Date}
* @type {number}
*/
this.timestamp = data.timestamp;
@@ -133,7 +133,7 @@ class RichEmbed {
/**
* Sets the timestamp of this embed.
* @param {Date} [timestamp=current date] The timestamp
* @param {Date} [timestamp=new Date()] The timestamp
* @returns {RichEmbed} This embed
*/
setTimestamp(timestamp = new Date()) {
@@ -215,6 +215,36 @@ class RichEmbed {
this.file = file;
return this;
}
/**
* Transforms the embed object to be processed.
* @returns {Object} The raw data of this embed
* @private
*/
_apiTransform() {
return {
title: this.title,
type: 'rich',
description: this.description,
url: this.url,
timestamp: this.timestamp ? new Date(this.timestamp) : null,
color: this.color,
fields: this.fields,
thumbnail: this.thumbnail,
image: this.image ? {
url: this.image.url,
} : null,
author: this.author ? {
name: this.author.name,
url: this.author.url,
icon_url: this.author.iconURL,
} : null,
footer: this.footer ? {
text: this.footer.text,
icon_url: this.footer.iconURL,
} : null,
};
}
}
module.exports = RichEmbed;

View File

@@ -178,6 +178,8 @@ class Webhook {
else options.files = files;
}
if (options.embeds) options.embeds = options.embeds.map(e => new RichEmbed(e)._apiTransform());
if (options.files) {
for (let i = 0; i < options.files.length; i++) {
let file = options.files[i];

View File

@@ -135,6 +135,8 @@ class TextBasedChannel {
else options.files = [options.file];
}
if (options.embed) options.embed = new RichEmbed(options.embed)._apiTransform();
if (options.files) {
for (let i = 0; i < options.files.length; i++) {
let file = options.files[i];