typings/fix(MessageEmbed): add interfaces for props, fix copy constructor (#3492)

* updated typings

* Updated docs

* fixed types for MessageEmbedOptions

* added curly bracket spaces

* fix(MessageEmbed): make copy constructor work properly

* fix(MessageEmbed): copy the provider too

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Tenpi
2020-02-24 05:44:54 -05:00
committed by GitHub
parent 28490e84b0
commit e57ef25082
2 changed files with 95 additions and 29 deletions

View File

@@ -67,81 +67,108 @@ class MessageEmbed {
this.fields = data.fields ? data.fields.map(Util.cloneObject) : []; this.fields = data.fields ? data.fields.map(Util.cloneObject) : [];
/** /**
* The thumbnail of this embed (if there is one) * @typedef {Object} MessageEmbedThumbnail
* @type {?Object}
* @property {string} url URL for this thumbnail * @property {string} url URL for this thumbnail
* @property {string} proxyURL ProxyURL for this thumbnail * @property {string} proxyURL ProxyURL for this thumbnail
* @property {number} height Height of this thumbnail * @property {number} height Height of this thumbnail
* @property {number} width Width of this thumbnail * @property {number} width Width of this thumbnail
*/ */
/**
* The thumbnail of this embed (if there is one)
* @type {?MessageEmbedThumbnail}
*/
this.thumbnail = data.thumbnail ? { this.thumbnail = data.thumbnail ? {
url: data.thumbnail.url, url: data.thumbnail.url,
proxyURL: data.thumbnail.proxy_url, proxyURL: data.thumbnail.proxyURL || data.thumbnail.proxy_url,
height: data.thumbnail.height, height: data.thumbnail.height,
width: data.thumbnail.width, width: data.thumbnail.width,
} : null; } : null;
/** /**
* The image of this embed, if there is one * @typedef {Object} MessageEmbedImage
* @type {?Object}
* @property {string} url URL for this image * @property {string} url URL for this image
* @property {string} proxyURL ProxyURL for this image * @property {string} proxyURL ProxyURL for this image
* @property {number} height Height of this image * @property {number} height Height of this image
* @property {number} width Width of this image * @property {number} width Width of this image
*/ */
/**
* The image of this embed, if there is one
* @type {?MessageEmbedImage}
*/
this.image = data.image ? { this.image = data.image ? {
url: data.image.url, url: data.image.url,
proxyURL: data.image.proxy_url, proxyURL: data.image.proxyURL || data.image.proxy_url,
height: data.image.height, height: data.image.height,
width: data.image.width, width: data.image.width,
} : null; } : null;
/** /**
* The video of this embed (if there is one) * @typedef {Object} MessageEmbedVideo
* @type {?Object}
* @property {string} url URL of this video * @property {string} url URL of this video
* @property {string} proxyURL ProxyURL for this video * @property {string} proxyURL ProxyURL for this video
* @property {number} height Height of this video * @property {number} height Height of this video
* @property {number} width Width of this video * @property {number} width Width of this video
*/
/**
* The video of this embed (if there is one)
* @type {?MessageEmbedVideo}
* @readonly * @readonly
*/ */
this.video = data.video ? { this.video = data.video ? {
url: data.video.url, url: data.video.url,
proxyURL: data.video.proxy_url, proxyURL: data.video.proxyURL || data.video.proxy_url,
height: data.video.height, height: data.video.height,
width: data.video.width, width: data.video.width,
} : null; } : null;
/** /**
* The author of this embed (if there is one) * @typedef {Object} MessageEmbedAuthor
* @type {?Object}
* @property {string} name The name of this author * @property {string} name The name of this author
* @property {string} url URL of this author * @property {string} url URL of this author
* @property {string} iconURL URL of the icon for this author * @property {string} iconURL URL of the icon for this author
* @property {string} proxyIconURL Proxied URL of the icon for this author * @property {string} proxyIconURL Proxied URL of the icon for this author
*/ */
/**
* The author of this embed (if there is one)
* @type {?MessageEmbedAuthor}
*/
this.author = data.author ? { this.author = data.author ? {
name: data.author.name, name: data.author.name,
url: data.author.url, url: data.author.url,
iconURL: data.author.iconURL || data.author.icon_url, iconURL: data.author.iconURL || data.author.icon_url,
proxyIconURL: data.author.proxyIconUrl || data.author.proxy_icon_url, proxyIconURL: data.author.proxyIconURL || data.author.proxy_icon_url,
} : null; } : null;
/** /**
* The provider of this embed (if there is one) * @typedef {Object} MessageEmbedProvider
* @type {?Object}
* @property {string} name The name of this provider * @property {string} name The name of this provider
* @property {string} url URL of this provider * @property {string} url URL of this provider
*/ */
this.provider = data.provider;
/** /**
* The footer of this embed * The provider of this embed (if there is one)
* @type {?Object} * @type {?MessageEmbedProvider}
*/
this.provider = data.provider ? {
name: data.provider.name,
url: data.provider.name,
} : null;
/**
* @typedef {Object} MessageEmbedFooter
* @property {string} text The text of this footer * @property {string} text The text of this footer
* @property {string} iconURL URL of the icon for this footer * @property {string} iconURL URL of the icon for this footer
* @property {string} proxyIconURL Proxied URL of the icon for this footer * @property {string} proxyIconURL Proxied URL of the icon for this footer
*/ */
/**
* The footer of this embed
* @type {?MessageEmbedFooter}
*/
this.footer = data.footer ? { this.footer = data.footer ? {
text: data.footer.text, text: data.footer.text,
iconURL: data.footer.iconURL || data.footer.icon_url, iconURL: data.footer.iconURL || data.footer.icon_url,

63
typings/index.d.ts vendored
View File

@@ -1051,23 +1051,23 @@ declare module 'discord.js' {
export class MessageEmbed { export class MessageEmbed {
constructor(data?: MessageEmbed | MessageEmbedOptions); constructor(data?: MessageEmbed | MessageEmbedOptions);
public author: { name?: string; url?: string; iconURL?: string; proxyIconURL?: string } | null; public author: MessageEmbedAuthor | null;
public color: number; public color: number;
public readonly createdAt: Date | null; public readonly createdAt: Date | null;
public description: string; public description: string;
public fields: EmbedField[]; public fields: EmbedField[];
public files: (MessageAttachment | string | FileOptions)[]; public files: (MessageAttachment | string | FileOptions)[];
public footer: { text?: string; iconURL?: string; proxyIconURL?: string } | null; public footer: MessageEmbedFooter | null;
public readonly hexColor: string | null; public readonly hexColor: string | null;
public image: { url: string; proxyURL?: string; height?: number; width?: number; } | null; public image: MessageEmbedImage | null;
public readonly length: number; public readonly length: number;
public provider: { name: string; url: string; }; public provider: MessageEmbedProvider | null;
public thumbnail: { url: string; proxyURL?: string; height?: number; width?: number; } | null; public thumbnail: MessageEmbedThumbnail | null;
public timestamp: number | null; public timestamp: number | null;
public title: string; public title: string;
public type: string; public type: string;
public url: string; public url: string;
public readonly video: { url?: string; proxyURL?: string; height?: number; width?: number } | null; public readonly video: MessageEmbedVideo | null;
public addFields(...fields: EmbedField[] | EmbedField[][]): this; public addFields(...fields: EmbedField[] | EmbedField[][]): this;
public attachFiles(file: (MessageAttachment | FileOptions | string)[]): this; public attachFiles(file: (MessageAttachment | FileOptions | string)[]): this;
public setAuthor(name: StringResolvable, iconURL?: string, url?: string): this; public setAuthor(name: StringResolvable, iconURL?: string, url?: string): this;
@@ -2449,13 +2449,52 @@ declare module 'discord.js' {
url?: string; url?: string;
timestamp?: Date | number; timestamp?: Date | number;
color?: ColorResolvable; color?: ColorResolvable;
fields?: { name: string; value: string; inline?: boolean; }[]; fields?: EmbedField[];
files?: (MessageAttachment | string | FileOptions)[]; files?: (MessageAttachment | string | FileOptions)[];
author?: { name?: string; url?: string; icon_url?: string; iconURL?: string; }; author?: Partial<MessageEmbedAuthor> & { icon_url?: string; proxy_icon_url?: string };
thumbnail?: { url?: string; height?: number; width?: number; }; thumbnail?: Partial<MessageEmbedThumbnail> & { proxy_url?: string };
image?: { url?: string; proxy_url?: string; proxyURL?: string; height?: number; width?: number; }; image?: Partial<MessageEmbedImage> & { proxy_url?: string };
video?: { url?: string; height?: number; width?: number; }; video?: Partial<MessageEmbedVideo> & { proxy_url?: string };
footer?: { text?: string; icon_url?: string; iconURL?: string; }; footer?: Partial<MessageEmbedFooter> & { icon_url?: string; proxy_icon_url?: string };
}
interface MessageEmbedAuthor {
name?: string;
url?: string;
iconURL?: string;
proxyIconURL?: string;
}
interface MessageEmbedThumbnail {
url: string;
proxyURL?: string;
height?: number;
width?: number;
}
interface MessageEmbedFooter {
text?: string;
iconURL?: string;
proxyIconURL?: string;
}
interface MessageEmbedImage {
url: string;
proxyURL?: string;
height?: number;
width?: number;
}
interface MessageEmbedProvider {
name: string;
url: string;
}
interface MessageEmbedVideo {
url?: string;
proxyURL?: string;
height?: number;
width?: number;
} }
interface MessageOptions { interface MessageOptions {