Skip to content

Commit

Permalink
chore: make requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Mar 2, 2022
1 parent e0d975b commit 611805a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/ActionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Components = require('../util/Components');
* @extends {Component}
*/
class ActionRow extends Component {
constructor({ components, ...data } = {}) {
constructor({ components, ...data }) {
super(data);
/**
* The components in this action row
Expand Down
10 changes: 5 additions & 5 deletions packages/discord.js/src/structures/ButtonComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ButtonComponent extends Component {
* @readonly
*/
get label() {
return this.data.label;
return this.data.label ?? null;
}

/**
Expand All @@ -31,7 +31,7 @@ class ButtonComponent extends Component {
* @readonly
*/
get emoji() {
return this.data.emoji;
return this.data.emoji ?? null;
}

/**
Expand All @@ -40,7 +40,7 @@ class ButtonComponent extends Component {
* @readonly
*/
get disabled() {
return this.data.disabled;
return this.data.disabled ?? null;
}

/**
Expand All @@ -49,7 +49,7 @@ class ButtonComponent extends Component {
* @readonly
*/
get customId() {
return this.data.custom_id;
return this.data.custom_id ?? null;
}

/**
Expand All @@ -58,7 +58,7 @@ class ButtonComponent extends Component {
* @readonly
*/
get url() {
return this.data.url;
return this.data.url ?? null;
}
}

Expand Down
30 changes: 16 additions & 14 deletions packages/discord.js/src/structures/Embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Embed {
* @param {APIEmbed} data API embed data
* @private
*/
constructor(data = {}) {
constructor(data) {
/**
* The API embed data
* @type {APIEmbed}
Expand All @@ -23,7 +23,7 @@ class Embed {
* @readonly
*/
get fields() {
return this.data.fields;
return this.data.fields ?? null;
}

/**
Expand All @@ -32,7 +32,7 @@ class Embed {
* @readonly
*/
get title() {
return this.data.title;
return this.data.title ?? null;
}

/**
Expand All @@ -41,7 +41,7 @@ class Embed {
* @readonly
*/
get description() {
return this.data.description;
return this.data.description ?? null;
}

/**
Expand All @@ -50,7 +50,7 @@ class Embed {
* @readonly
*/
get url() {
return this.data.url;
return this.data.url ?? null;
}

/**
Expand All @@ -59,7 +59,7 @@ class Embed {
* @readonly
*/
get color() {
return this.data.color;
return this.data.color ?? null;
}

/**
Expand All @@ -68,7 +68,7 @@ class Embed {
* @readonly
*/
get timestamp() {
return this.data.timestamp;
return this.data.timestamp ?? null;
}

/**
Expand All @@ -77,7 +77,7 @@ class Embed {
* @readonly
*/
get thumbnail() {
if (!this.data.thumbnail) return undefined;
if (!this.data.thumbnail) return null;
return {
url: this.data.thumbnail.url,
proxyURL: this.data.thumbnail.proxy_url,
Expand All @@ -92,7 +92,7 @@ class Embed {
* @readonly
*/
get image() {
if (!this.data.image) return undefined;
if (!this.data.image) return null;
return {
url: this.data.image.url,
proxyURL: this.data.image.proxy_url,
Expand All @@ -107,7 +107,7 @@ class Embed {
* @readonly
*/
get video() {
return this.data.video;
return this.data.video ?? null;
}

/**
Expand All @@ -116,7 +116,7 @@ class Embed {
* @readonly
*/
get author() {
if (!this.data.author) return undefined;
if (!this.data.author) return null;
return {
name: this.data.author.name,
url: this.data.author.url,
Expand All @@ -131,7 +131,7 @@ class Embed {
* @readonly
*/
get provider() {
return this.data.provider;
return this.data.provider ?? null;
}

/**
Expand All @@ -140,7 +140,7 @@ class Embed {
* @readonly
*/
get footer() {
if (!this.data.footer) return undefined;
if (!this.data.footer) return null;
return {
text: this.data.footer.text,
iconURL: this.data.footer.icon_url,
Expand Down Expand Up @@ -169,7 +169,9 @@ class Embed {
* @readonly
*/
get hexColor() {
return typeof this.data.color === 'number' ? `#${this.data.color.toString(16).padStart(6, '0')}` : this.data.color;
return typeof this.data.color === 'number'
? `#${this.data.color.toString(16).padStart(6, '0')}`
: this.data.color ?? null;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/structures/SelectMenuComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SelectMenuComponent extends Component {
* @readonly
*/
get placeholder() {
return this.data.placeholder;
return this.data.placeholder ?? null;
}

/**
Expand All @@ -22,7 +22,7 @@ class SelectMenuComponent extends Component {
* @readonly
*/
get maxValues() {
return this.data.max_values;
return this.data.max_values ?? null;
}

/**
Expand All @@ -31,7 +31,7 @@ class SelectMenuComponent extends Component {
* @readonly
*/
get minValues() {
return this.data.min_values;
return this.data.min_values ?? null;
}

/**
Expand All @@ -49,7 +49,7 @@ class SelectMenuComponent extends Component {
* @readonly
*/
get disabled() {
return this.data.disabled;
return this.data.disabled ?? null;
}

/**
Expand Down
47 changes: 25 additions & 22 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class ActionRowBuilder<
export type MessageActionRowComponent = ButtonComponent | SelectMenuComponent;

export class ActionRow<T extends MessageActionRowComponent> {
private constructor(data?: APIActionRowComponent<APIMessageActionRowComponent>);
private constructor(data: APIActionRowComponent<APIMessageActionRowComponent>);
public readonly components: T[];
}

Expand Down Expand Up @@ -494,20 +494,20 @@ export class ButtonInteraction<Cached extends CacheType = CacheType> extends Mes
}

export class Component<T extends APIMessageComponent = APIMessageComponent> {
public data: T;
public readonly data: Readonly<T>;
public get type(): T['type'];
public toJSON(): T;
public equals(other: this | T): boolean;
}

export class ButtonComponent extends Component<APIButtonComponent> {
private constructor(data?: APIButtonComponent);
private constructor(data: APIButtonComponent);
public get style(): ButtonStyle;
public get label(): string | undefined;
public get emoji(): APIMessageComponentEmoji | undefined;
public get disabled(): boolean | undefined;
public get customId(): string | undefined;
public get url(): string | undefined;
public get label(): string | null;
public get emoji(): APIMessageComponentEmoji | null;
public get disabled(): boolean | null;
public get customId(): string | null;
public get url(): string | null;
}

export class ButtonBuilder extends BuilderButtonComponent {
Expand All @@ -521,12 +521,12 @@ export class SelectMenuBuilder extends BuilderSelectMenuComponent {
}

export class SelectMenuComponent extends Component<APISelectMenuComponent> {
private constructor(data?: APISelectMenuComponent);
public get placeholder(): string | undefined;
public get maxValues(): number | undefined;
public get minValues(): number | undefined;
private constructor(data: APISelectMenuComponent);
public get placeholder(): string | null;
public get maxValues(): number | null;
public get minValues(): number | null;
public get customId(): string;
public get disabled(): boolean | undefined;
public get disabled(): boolean | null;
public get options(): APISelectMenuOption[];
}

Expand Down Expand Up @@ -568,15 +568,18 @@ export class EmbedBuilder extends BuildersEmbed {
}

export class Embed {
private constructor(data?: APIEmbed);
public get fields(): APIEmbedField[] | undefined;
public get title(): string | undefined;
public get description(): string | undefined;
public get url(): string | undefined;
public get color(): number | undefined;
public get timestamp(): string | undefined;
public get thumbnail(): EmbedImageData | undefined;
public get image(): EmbedImageData | undefined;
private constructor(data: APIEmbed);
public readonly data: Readonly<APIEmbed>;
public get fields(): APIEmbedField[] | null;
public get title(): string | null;
public get description(): string | null;
public get url(): string | null;
public get color(): number | null;
public get timestamp(): string | null;
public get thumbnail(): EmbedImageData | null;
public get image(): EmbedImageData | null;
public equals(other: Embed | APIEmbed): boolean;
public toJSON(): APIEmbed;
}

export interface MappedChannelCategoryTypes {
Expand Down

0 comments on commit 611805a

Please sign in to comment.