refactor(Embed): Add all the types (#8254)

This commit is contained in:
Jiralite
2022-07-17 20:13:40 +01:00
committed by GitHub
parent 33a7a5cbdc
commit 64f814066c
4 changed files with 70 additions and 104 deletions

View File

@@ -6,14 +6,9 @@ const isEqual = require('fast-deep-equal');
* Represents an embed. * Represents an embed.
*/ */
class Embed { class Embed {
/**
* Creates a new embed object
* @param {APIEmbed} data API embed data
* @private
*/
constructor(data) { constructor(data) {
/** /**
* The API embed data * The API embed data.
* @type {APIEmbed} * @type {APIEmbed}
* @readonly * @readonly
*/ */
@@ -21,16 +16,16 @@ class Embed {
} }
/** /**
* An array of fields of this embed * An array of fields of this embed.
* @type {?Array<APIEmbedField>} * @type {Array<APIEmbedField>}
* @readonly * @readonly
*/ */
get fields() { get fields() {
return this.data.fields ?? null; return this.data.fields ?? [];
} }
/** /**
* The embed title * The title of this embed.
* @type {?string} * @type {?string}
* @readonly * @readonly
*/ */
@@ -39,7 +34,7 @@ class Embed {
} }
/** /**
* The embed description * The description of this embed.
* @type {?string} * @type {?string}
* @readonly * @readonly
*/ */
@@ -48,7 +43,7 @@ class Embed {
} }
/** /**
* The embed URL * The URL of this embed.
* @type {?string} * @type {?string}
* @readonly * @readonly
*/ */
@@ -57,7 +52,7 @@ class Embed {
} }
/** /**
* The embed color * The color of this embed.
* @type {?number} * @type {?number}
* @readonly * @readonly
*/ */
@@ -66,7 +61,7 @@ class Embed {
} }
/** /**
* The timestamp of the embed in an ISO 8601 format * The timestamp of this embed. This is in an ISO 8601 format.
* @type {?string} * @type {?string}
* @readonly * @readonly
*/ */
@@ -75,8 +70,16 @@ class Embed {
} }
/** /**
* The embed thumbnail data * @typedef {Object} EmbedAssetData
* @type {?EmbedImageData} * @property {?string} url The URL of the image
* @property {?string} proxyURL The proxy URL of the image
* @property {?string} height The height of the image
* @property {?string} width The width of the image
*/
/**
* The thumbnail of this embed.
* @type {?EmbedAssetData}
* @readonly * @readonly
*/ */
get thumbnail() { get thumbnail() {
@@ -90,8 +93,8 @@ class Embed {
} }
/** /**
* The embed image data * The image of this embed.
* @type {?EmbedImageData} * @type {?EmbedAssetData}
* @readonly * @readonly
*/ */
get image() { get image() {
@@ -105,16 +108,30 @@ class Embed {
} }
/** /**
* Received video data * The video of this embed.
* @type {?EmbedVideoData} * @type {?EmbedAssetData}
* @readonly * @readonly
*/ */
get video() { get video() {
return this.data.video ?? null; if (!this.data.video) return null;
return {
url: this.data.image.url,
proxyURL: this.data.image.proxy_url,
height: this.data.image.height,
width: this.data.image.width,
};
} }
/** /**
* The embed author data * @typedef {Object} EmbedAuthorData
* @property {string} name The name of the author
* @property {?string} url The URL of the author
* @property {?string} iconURL The icon URL of the author
* @property {?string} proxyIconURL The proxy icon URL of the author
*/
/**
* The author of this embed.
* @type {?EmbedAuthorData} * @type {?EmbedAuthorData}
* @readonly * @readonly
*/ */
@@ -129,8 +146,8 @@ class Embed {
} }
/** /**
* Received data about the embed provider * The provider of this embed.
* @type {?EmbedProvider} * @type {?APIEmbedProvider}
* @readonly * @readonly
*/ */
get provider() { get provider() {
@@ -138,7 +155,14 @@ class Embed {
} }
/** /**
* The embed footer data * @typedef {Object} EmbedFooterData
* @property {string} text The text of the footer
* @property {?string} iconURL The URL of the icon
* @property {?string} proxyIconURL The proxy URL of the icon
*/
/**
* The footer of this embed.
* @type {?EmbedFooterData} * @type {?EmbedFooterData}
* @readonly * @readonly
*/ */
@@ -152,7 +176,7 @@ class Embed {
} }
/** /**
* The accumulated length for the embed title, description, fields, footer text, and author name * The accumulated length for the embed title, description, fields, footer text, and author name.
* @type {number} * @type {number}
* @readonly * @readonly
*/ */
@@ -167,7 +191,7 @@ class Embed {
} }
/** /**
* The hex color of the current color of the embed * The hex color of this embed.
* @type {?string} * @type {?string}
* @readonly * @readonly
*/ */
@@ -178,7 +202,7 @@ class Embed {
} }
/** /**
* Returns the API-compatible JSON for this embed * Returns the API-compatible JSON for this embed.
* @returns {APIEmbed} * @returns {APIEmbed}
*/ */
toJSON() { toJSON() {
@@ -186,7 +210,7 @@ class Embed {
} }
/** /**
* Whether or not the given embeds are equal * Whether the given embeds are equal.
* @param {Embed|APIEmbed} other The embed to compare against * @param {Embed|APIEmbed} other The embed to compare against
* @returns {boolean} * @returns {boolean}
*/ */

View File

@@ -48,6 +48,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmbedField} * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmbedField}
*/ */
/**
* @external APIEmbedProvider
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmbedProvider}
*/
/** /**
* @external APIEmoji * @external APIEmoji
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmoji} * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmoji}

View File

@@ -1,48 +0,0 @@
'use strict';
/**
* @typedef {Object} EmbedData
* @property {?string} title The title of the embed
* @property {?EmbedType} type The type of the embed
* @property {?string} description The description of the embed
* @property {?string} url The URL of the embed
* @property {?string} timestamp The timestamp on the embed
* @property {?number} color The color of the embed
* @property {?EmbedFooterData} footer The footer of the embed
* @property {?EmbedImageData} image The image of the embed
* @property {?EmbedImageData} thumbnail The thumbnail of the embed
* @property {?EmbedProviderData} provider The provider of the embed
* @property {?EmbedAuthorData} author The author in the embed
* @property {?EmbedFieldData[]} fields The fields in this embed
*/
/**
* @typedef {Object} EmbedFooterData
* @property {string} text The text of the footer
* @property {?string} iconURL The URL of the icon
*/
/**
* @typedef {Object} EmbedImageData
* @property {?string} url The URL of the image
*/
/**
* @typedef {Object} EmbedProviderData
* @property {?string} name The name of the provider
* @property {?string} url The URL of the provider
*/
/**
* @typedef {Object} EmbedAuthorData
* @property {string} name The name of the author
* @property {?string} url The URL of the author
* @property {?string} iconURL The icon URL of the author
*/
/**
* @typedef {Object} EmbedFieldData
* @property {string} name The name of the field
* @property {string} value The value of the field
* @property {?boolean} inline Whether to inline this field
*/

View File

@@ -113,7 +113,6 @@ import {
APIEmbedAuthor, APIEmbedAuthor,
APIEmbedFooter, APIEmbedFooter,
APIEmbedImage, APIEmbedImage,
APIEmbedVideo,
VideoQualityMode, VideoQualityMode,
LocalizationMap, LocalizationMap,
LocaleString, LocaleString,
@@ -122,6 +121,7 @@ import {
APIChannel, APIChannel,
ThreadAutoArchiveDuration, ThreadAutoArchiveDuration,
FormattingPatterns, FormattingPatterns,
APIEmbedProvider,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process'; import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events'; import { EventEmitter } from 'node:events';
@@ -667,12 +667,12 @@ export interface EmbedData {
timestamp?: string | number | Date; timestamp?: string | number | Date;
color?: number; color?: number;
footer?: EmbedFooterData; footer?: EmbedFooterData;
image?: EmbedImageData; image?: EmbedAssetData;
thumbnail?: EmbedImageData; thumbnail?: EmbedAssetData;
provider?: EmbedProviderData; provider?: APIEmbedProvider;
author?: EmbedAuthorData; author?: EmbedAuthorData;
fields?: EmbedFieldData[]; fields?: APIEmbedField[];
video?: EmbedVideoData; video?: EmbedAssetData;
} }
export interface IconData { export interface IconData {
@@ -684,16 +684,7 @@ export type EmbedAuthorData = Omit<APIEmbedAuthor, 'icon_url' | 'proxy_icon_url'
export type EmbedFooterData = Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'> & IconData; export type EmbedFooterData = Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'> & IconData;
export interface EmbedProviderData { export interface EmbedAssetData extends Omit<APIEmbedImage, 'proxy_url'> {
name?: string;
url?: string;
}
export interface EmbedImageData extends Omit<APIEmbedImage, 'proxy_url'> {
proxyURL?: string;
}
export interface EmbedVideoData extends Omit<APIEmbedVideo, 'proxy_url'> {
proxyURL?: string; proxyURL?: string;
} }
@@ -706,7 +697,7 @@ export class EmbedBuilder extends BuildersEmbed {
export class Embed { export class Embed {
private constructor(data: APIEmbed); private constructor(data: APIEmbed);
public readonly data: Readonly<APIEmbed>; public readonly data: Readonly<APIEmbed>;
public get fields(): APIEmbedField[] | null; public get fields(): APIEmbedField[];
public get footer(): EmbedFooterData | null; public get footer(): EmbedFooterData | null;
public get title(): string | null; public get title(): string | null;
public get description(): string | null; public get description(): string | null;
@@ -714,11 +705,11 @@ export class Embed {
public get color(): number | null; public get color(): number | null;
public get hexColor(): string | null; public get hexColor(): string | null;
public get timestamp(): string | null; public get timestamp(): string | null;
public get thumbnail(): EmbedImageData | null; public get thumbnail(): EmbedAssetData | null;
public get image(): EmbedImageData | null; public get image(): EmbedAssetData | null;
public get author(): EmbedAuthorData | null; public get author(): EmbedAuthorData | null;
public get provider(): EmbedProviderData | null; public get provider(): APIEmbedProvider | null;
public get video(): EmbedVideoData | null; public get video(): EmbedAssetData | null;
public get length(): number; public get length(): number;
public equals(other: Embed | APIEmbed): boolean; public equals(other: Embed | APIEmbed): boolean;
public toJSON(): APIEmbed; public toJSON(): APIEmbed;
@@ -4413,12 +4404,6 @@ export interface EmbedField {
inline: boolean; inline: boolean;
} }
export interface EmbedFieldData {
name: string;
value: string;
inline?: boolean;
}
export type EmojiIdentifierResolvable = string | EmojiResolvable; export type EmojiIdentifierResolvable = string | EmojiResolvable;
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji; export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;