Skip to content

Commit

Permalink
feat: typings for missing methods and general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
monbrey committed May 27, 2021
1 parent fddbda5 commit da340c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/structures/BaseMessageComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BaseMessageComponent {
/**
* Options for a BaseMessageComponent
* @typedef {Object} BaseMessageComponentOptions
* @property {MessageComponentType} type The type of this component
* @property {MessageComponentTypeResolvable} type The type of this component
*/

/**
Expand Down Expand Up @@ -53,6 +53,12 @@ class BaseMessageComponent {
return this;
}

/**
* Constructs a MessageComponent based on the type of the incoming data
* @param {MessageComponentOptions} data Data for a MessageComponent
* @returns {MessageComponent}
* @private
*/
static create(data) {
let component;
let type = data.type;
Expand All @@ -77,7 +83,8 @@ class BaseMessageComponent {
/**
* Resolves the type of a MessageComponent
* @param {MessageComponentTypeResolvable} type The type to resolve
* @returns {any}
* @returns {MessageComponentType}
* @private
*/
static resolveType(type) {
return typeof type === 'string' ? type : MessageComponentTypes[type];
Expand Down
10 changes: 8 additions & 2 deletions src/structures/MessageButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MessageButton extends BaseMessageComponent {
* @typedef {BaseMessageComponentOptions} MessageButtonOptions
* @property {string} [label] The text to be displayed on this button
* @property {string} [customID] A unique string to be sent in the interaction when clicked
* @property {MessageButtonStyle} [style] The style of this button
* @property {MessageButtonStyleResolvable} [style] The style of this button
* @property {Emoji} [emoji] The emoji to be displayed to the left of the text
* @property {string} [url] Optional URL for link-style buttons
* @property {boolean} [disabled=false] Disables the button to prevent interactions
Expand Down Expand Up @@ -103,7 +103,7 @@ class MessageButton extends BaseMessageComponent {

/**
* Sets the style of this button
* @param {MessageButtonStyle} style The style of this button
* @param {MessageButtonStyleResolvable} style The style of this button
* @returns {MessageButton}
*/
setStyle(style) {
Expand All @@ -121,6 +121,12 @@ class MessageButton extends BaseMessageComponent {
return this;
}

/**
* Resolves the style of a MessageButton
* @param {MessageButtonStyleResolvable} style The style to resolve
* @returns {MessageButtonStyle}
* @private
*/
static resolveStyle(style) {
return typeof style === 'string' ? style : MessageButtonStyles[style];
}
Expand Down
15 changes: 12 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ declare module 'discord.js' {
export class BaseMessageComponent {
constructor(data?: BaseMessageComponent | BaseMessageComponentOptions);
public type: MessageComponentType | null;
public setType(type: MessageComponentType | number): this;
public setType(type: MessageComponentTypeResolvable): this;
private static create(data: MessageComponentOptions): MessageComponent;
private static resolveType(type: MessageComponentTypeResolvable): MessageComponentType;
private static transform(component: MessageComponentResolvable): object;
}

interface BaseMessageComponentOptions {
Expand Down Expand Up @@ -1276,8 +1279,9 @@ declare module 'discord.js' {
public setDisabled(disabled: boolean): this;
public setEmoji(emoji: EmojiIdentifierResolvable): this;
public setLabel(label: string): this;
public setStyle(style: MessageButtonStyle | MessageButtonStyles): this;
public setStyle(style: MessageButtonStyleResolvable): this;
public setURL(url: string): this;
private static resolveStyle(style: MessageButtonStyleResolvable): MessageButtonStyle;
}

export class MessageCollector extends Collector<Snowflake, Message> {
Expand Down Expand Up @@ -3230,12 +3234,15 @@ declare module 'discord.js' {
disabled?: boolean;
emoji?: RawEmoji;
label?: string;
style?: MessageButtonStyle | MessageButtonStyles;
style: MessageButtonStyleResolvable;
type: 'BUTTON' | MessageComponentTypes.BUTTON;
url?: string;
}

type MessageButtonStyle = keyof typeof MessageButtonStyles;

type MessageButtonStyleResolvable = MessageButtonStyle | MessageButtonStyles | string | number;

interface MessageCollectorOptions extends CollectorOptions {
max?: number;
maxProcessed?: number;
Expand All @@ -3249,6 +3256,8 @@ declare module 'discord.js' {

type MessageComponentType = keyof typeof MessageComponentTypes;

type MessageComponentTypeResolvable = MessageComponentType | MessageComponentTypes | string | number;

interface MessageEditOptions {
content?: StringResolvable;
embed?: MessageEmbed | MessageEmbedOptions | null;
Expand Down

0 comments on commit da340c3

Please sign in to comment.