fix(*): typedefs and typings for image & webhook options (#5805)

This commit is contained in:
Shubham Parihar
2021-06-12 03:52:01 +05:30
committed by GitHub
parent 19d0405aa5
commit a5a6e22316
10 changed files with 71 additions and 58 deletions

View File

@@ -426,7 +426,7 @@ class Guild extends BaseGuild {
/**
* The URL to this guild's banner.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
bannerURL({ format, size } = {}) {
@@ -445,7 +445,7 @@ class Guild extends BaseGuild {
/**
* The URL to this guild's invite splash image.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
splashURL({ format, size } = {}) {
@@ -455,7 +455,7 @@ class Guild extends BaseGuild {
/**
* The URL to this guild's discovery splash image.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
discoverySplashURL({ format, size } = {}) {

View File

@@ -93,7 +93,7 @@ class GuildPreview extends Base {
/**
* The URL to this guild's splash.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
splashURL({ format, size } = {}) {
@@ -103,7 +103,7 @@ class GuildPreview extends Base {
/**
* The URL to this guild's discovery splash.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
discoverySplashURL({ format, size } = {}) {

View File

@@ -26,7 +26,7 @@ class PartialGroupDMChannel extends Channel {
/**
* The URL to this channel's icon.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
iconURL({ format, size } = {}) {

View File

@@ -335,9 +335,7 @@ class RichPresenceAssets {
/**
* Gets the URL of the small image asset
* @param {Object} [options] Options for the image url
* @param {string} [options.format] Format of the image
* @param {number} [options.size] Size of the image
* @param {StaticImageURLOptions} [options] Options for the image url
* @returns {?string} The small image URL
*/
smallImageURL({ format, size } = {}) {
@@ -350,9 +348,7 @@ class RichPresenceAssets {
/**
* Gets the URL of the large image asset
* @param {Object} [options] Options for the image url
* @param {string} [options.format] Format of the image
* @param {number} [options.size] Size of the image
* @param {StaticImageURLOptions} [options] Options for the image url
* @returns {?string} The large image URL
*/
largeImageURL({ format, size } = {}) {

View File

@@ -81,7 +81,7 @@ class Team extends Base {
/**
* A link to the teams's icon.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string} URL to the icon
*/
iconURL({ format, size } = {}) {

View File

@@ -126,12 +126,17 @@ class TextChannel extends GuildChannel {
});
}
/**
* Options used to create a {@link Webhook} for {@link TextChannel} and {@link NewsChannel}.
* @typedef {Object} ChannelWebhookCreateOptions
* @property {BufferResolvable|Base64Resolvable} [avatar] Avatar for the webhook
* @property {string} [reason] Reason for creating the webhook
*/
/**
* Creates a webhook for the channel.
* @param {string} name The name of the webhook
* @param {Object} [options] Options for creating the webhook
* @param {BufferResolvable|Base64Resolvable} [options.avatar] Avatar for the webhook
* @param {string} [options.reason] Reason for creating the webhook
* @param {ChannelWebhookCreateOptions} [options] Options for creating the webhook
* @returns {Promise<Webhook>} webhook The created webhook
* @example
* // Create a webhook for the current channel

View File

@@ -211,12 +211,17 @@ class Webhook {
}
/**
* Edits the webhook.
* @param {Object} options Options
* @param {string} [options.name=this.name] New name for this webhook
* @param {BufferResolvable} [options.avatar] New avatar for this webhook
* @param {ChannelResolvable} [options.channel] New channel for this webhook
* @param {string} [reason] Reason for editing this webhook
* Options used to edit a {@link Webhook}.
* @typedef {Object} WebhookEditData
* @property {string} [name=this.name] The new name for the webhook
* @property {BufferResolvable} [avatar] The new avatar for the webhook
* @property {ChannelResolvable} [channel] The new channel for the webhook
*/
/**
* Edits this webhook.
* @param {WebhookEditData} options Options for editing the webhook
* @param {string} [reason] Reason for editing the webhook
* @returns {Promise<Webhook>}
*/
async edit({ name = this.name, avatar, channel }, reason) {
@@ -334,7 +339,7 @@ class Webhook {
/**
* A link to the webhook's avatar.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
avatarURL({ format, size } = {}) {

View File

@@ -62,7 +62,7 @@ class Application extends Base {
/**
* A link to the application's icon.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string} URL to the icon
*/
iconURL({ format, size } = {}) {
@@ -72,7 +72,7 @@ class Application extends Base {
/**
* A link to this application's cover image.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @param {StaticImageURLOptions} [options={}] Options for the Image URL
* @returns {?string} URL to the cover image
*/
coverURL({ format, size } = {}) {

View File

@@ -136,11 +136,16 @@ function makeImageUrl(root, { format = 'webp', size } = {}) {
/**
* Options for Image URLs.
* @typedef {Object} ImageURLOptions
* @property {string} [format] One of `webp`, `png`, `jpg`, `jpeg`, `gif`. If no format is provided,
* defaults to `webp`.
* @typedef {StaticImageURLOptions} ImageURLOptions
* @property {boolean} [dynamic] If true, the format will dynamically change to `gif` for
* animated avatars; the default is false.
* animated avatars; the default is false
*/
/**
* Options for static Image URLs.
* @typedef {Object} StaticImageURLOptions
* @property {string} [format] One of `webp`, `png`, `jpg`, `jpeg`, `gif`. If no format is provided,
* defaults to `webp`
* @property {number} [size] One of `16`, `32`, `64`, `128`, `256`, `512`, `1024`, `2048`, `4096`
*/

60
typings/index.d.ts vendored
View File

@@ -169,9 +169,9 @@ declare module 'discord.js' {
public icon: string | null;
public id: Snowflake;
public name: string | null;
public coverURL(options?: ImageURLOptions): string | null;
public coverURL(options?: StaticImageURLOptions): string | null;
public fetchAssets(): Promise<ApplicationAsset[]>;
public iconURL(options?: ImageURLOptions): string | null;
public iconURL(options?: StaticImageURLOptions): string | null;
public toJSON(): unknown;
public toString(): string | null;
}
@@ -240,7 +240,7 @@ declare module 'discord.js' {
public readonly partnered: boolean;
public readonly verified: boolean;
public fetch(): Promise<Guild>;
public iconURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null;
public iconURL(options?: ImageURLOptions): string | null;
public toString(): string;
}
@@ -770,11 +770,11 @@ declare module 'discord.js' {
public widgetChannelID: Snowflake | null;
public widgetEnabled: boolean | null;
public addMember(user: UserResolvable, options: AddGuildMemberOptions): Promise<GuildMember>;
public bannerURL(options?: ImageURLOptions): string | null;
public bannerURL(options?: StaticImageURLOptions): string | null;
public createIntegration(data: IntegrationData, reason?: string): Promise<Guild>;
public createTemplate(name: string, description?: string): Promise<GuildTemplate>;
public delete(): Promise<Guild>;
public discoverySplashURL(options?: ImageURLOptions): string | null;
public discoverySplashURL(options?: StaticImageURLOptions): string | null;
public edit(data: GuildEditData, reason?: string): Promise<Guild>;
public equals(guild: Guild): boolean;
public fetchAuditLogs(options?: GuildAuditLogsFetchOptions): Promise<GuildAuditLogs>;
@@ -813,7 +813,7 @@ declare module 'discord.js' {
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
public setVerificationLevel(verificationLevel: VerificationLevel | number, reason?: string): Promise<Guild>;
public setWidget(widget: GuildWidgetData, reason?: string): Promise<Guild>;
public splashURL(options?: ImageURLOptions): string | null;
public splashURL(options?: StaticImageURLOptions): string | null;
public toJSON(): unknown;
}
@@ -982,9 +982,9 @@ declare module 'discord.js' {
public id: Snowflake;
public name: string;
public splash: string | null;
public discoverySplashURL(options?: ImageURLOptions): string | null;
public iconURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null;
public splashURL(options?: ImageURLOptions): string | null;
public discoverySplashURL(options?: StaticImageURLOptions): string | null;
public iconURL(options?: ImageURLOptions): string | null;
public splashURL(options?: StaticImageURLOptions): string | null;
public fetch(): Promise<GuildPreview>;
public toJSON(): unknown;
public toString(): string;
@@ -1436,10 +1436,7 @@ declare module 'discord.js' {
public nsfw: boolean;
public topic: string | null;
public type: 'news';
public createWebhook(
name: string,
options?: { avatar?: BufferResolvable | Base64Resolvable; reason?: string },
): Promise<Webhook>;
public createWebhook(name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>;
public setNSFW(nsfw: boolean, reason?: string): Promise<NewsChannel>;
public setType(type: Pick<typeof ChannelType, 'text' | 'news'>, reason?: string): Promise<GuildChannel>;
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
@@ -1455,7 +1452,7 @@ declare module 'discord.js' {
constructor(client: Client, data: unknown);
public name: string;
public icon: string | null;
public iconURL(options?: ImageURLOptions): string | null;
public iconURL(options?: StaticImageURLOptions): string | null;
}
export class PermissionOverwrites {
@@ -1549,8 +1546,8 @@ declare module 'discord.js' {
public largeText: string | null;
public smallImage: Snowflake | null;
public smallText: string | null;
public largeImageURL(options?: ImageURLOptions): string | null;
public smallImageURL(options?: ImageURLOptions): string | null;
public largeImageURL(options?: StaticImageURLOptions): string | null;
public smallImageURL(options?: StaticImageURLOptions): string | null;
}
export class Role extends Base {
@@ -1740,7 +1737,7 @@ declare module 'discord.js' {
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public iconURL(options?: ImageURLOptions): string;
public iconURL(options?: StaticImageURLOptions): string;
public toJSON(): unknown;
public toString(): string;
}
@@ -1763,10 +1760,7 @@ declare module 'discord.js' {
public type: 'text';
public rateLimitPerUser: number;
public topic: string | null;
public createWebhook(
name: string,
options?: { avatar?: BufferResolvable | Base64Resolvable; reason?: string },
): Promise<Webhook>;
public createWebhook(name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>;
public setNSFW(nsfw: boolean, reason?: string): Promise<TextChannel>;
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<TextChannel>;
public setType(type: Pick<typeof ChannelType, 'text' | 'news'>, reason?: string): Promise<GuildChannel>;
@@ -1790,10 +1784,10 @@ declare module 'discord.js' {
public system: boolean | null;
public readonly tag: string;
public username: string;
public avatarURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null;
public avatarURL(options?: ImageURLOptions): string | null;
public createDM(): Promise<DMChannel>;
public deleteDM(): Promise<DMChannel>;
public displayAvatarURL(options?: ImageURLOptions & { dynamic?: boolean }): string;
public displayAvatarURL(options?: ImageURLOptions): string;
public equals(user: User): boolean;
public fetch(force?: boolean): Promise<User>;
public fetchFlags(force?: boolean): Promise<UserFlags>;
@@ -1913,7 +1907,7 @@ declare module 'discord.js' {
export class Webhook extends WebhookMixin() {
constructor(client: Client, data?: unknown);
public avatar: string;
public avatarURL(options?: ImageURLOptions): string | null;
public avatarURL(options?: StaticImageURLOptions): string | null;
public channelID: Snowflake;
public client: Client;
public guildID: Snowflake;
@@ -2340,7 +2334,7 @@ declare module 'discord.js' {
readonly createdAt: Date;
readonly createdTimestamp: number;
delete(reason?: string): Promise<void>;
edit(options: WebhookEditData): Promise<Webhook>;
edit(options: WebhookEditData, reason?: string): Promise<Webhook>;
sendSlackMessage(body: object): Promise<boolean>;
}
@@ -2576,6 +2570,11 @@ declare module 'discord.js' {
type ChannelResolvable = Channel | Snowflake;
interface ChannelWebhookCreateOptions {
avatar?: BufferResolvable | Base64Resolvable;
reason?: string;
}
interface ClientEvents {
applicationCommandCreate: [command: ApplicationCommand];
applicationCommandDelete: [command: ApplicationCommand];
@@ -3077,9 +3076,8 @@ declare module 'discord.js' {
type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
interface ImageURLOptions {
format?: AllowedImageFormat;
size?: ImageSize;
interface ImageURLOptions extends StaticImageURLOptions {
dynamic?: boolean;
}
interface IntegrationData {
@@ -3633,6 +3631,11 @@ declare module 'discord.js' {
append?: string;
}
interface StaticImageURLOptions {
format?: AllowedImageFormat;
size?: ImageSize;
}
type Status = number;
export class Sticker extends Base {
@@ -3699,7 +3702,6 @@ declare module 'discord.js' {
name?: string;
avatar?: BufferResolvable;
channel?: ChannelResolvable;
reason?: string;
}
type WebhookEditMessageOptions = Pick<