mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
refactor: Don't return builders from API data (#7584)
* refactor: don't return builders from API data * Update packages/discord.js/src/structures/ActionRow.js Co-authored-by: Antonio Román <kyradiscord@gmail.com> * fix: circular dependency * fix: circular dependency pt.2 * chore: make requested changes * chore: bump dapi-types * chore: convert text input * chore: convert text input * feat: handle cases of unknown component types better * refactor: refactor modal to builder * feat: add #from for easy builder conversions * refactor: make requested changes * chore: make requested changes * style: fix linting error Co-authored-by: Antonio Román <kyradiscord@gmail.com> Co-authored-by: almeidx <almeidx@pm.me>
This commit is contained in:
@@ -6,59 +6,18 @@ import {
|
||||
type APIButtonComponentWithURL,
|
||||
type APIButtonComponentWithCustomId,
|
||||
} from 'discord-api-types/v9';
|
||||
import { Component } from '../Component';
|
||||
import isEqual from 'fast-deep-equal';
|
||||
import { ComponentBuilder } from '../Component';
|
||||
|
||||
/**
|
||||
* Represents a non-validated button component
|
||||
*/
|
||||
export class UnsafeButtonComponent extends Component<Partial<APIButtonComponent> & { type: ComponentType.Button }> {
|
||||
export class UnsafeButtonBuilder extends ComponentBuilder<
|
||||
Partial<APIButtonComponent> & { type: ComponentType.Button }
|
||||
> {
|
||||
public constructor(data?: Partial<APIButtonComponent>) {
|
||||
super({ type: ComponentType.Button, ...data });
|
||||
}
|
||||
|
||||
/**
|
||||
* The style of this button
|
||||
*/
|
||||
public get style() {
|
||||
return this.data.style;
|
||||
}
|
||||
|
||||
/**
|
||||
* The label of this button
|
||||
*/
|
||||
public get label() {
|
||||
return this.data.label;
|
||||
}
|
||||
|
||||
/**
|
||||
* The emoji used in this button
|
||||
*/
|
||||
public get emoji() {
|
||||
return this.data.emoji;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this button is disabled
|
||||
*/
|
||||
public get disabled() {
|
||||
return this.data.disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* The custom id of this button (only defined on non-link buttons)
|
||||
*/
|
||||
public get customId(): string | undefined {
|
||||
return (this.data as APIButtonComponentWithCustomId).custom_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The URL of this button (only defined on link buttons)
|
||||
*/
|
||||
public get url(): string | undefined {
|
||||
return (this.data as APIButtonComponentWithURL).url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the style of this button
|
||||
* @param style The style of the button
|
||||
@@ -119,11 +78,4 @@ export class UnsafeButtonComponent extends Component<Partial<APIButtonComponent>
|
||||
...this.data,
|
||||
} as APIButtonComponent;
|
||||
}
|
||||
|
||||
public equals(other: APIButtonComponent | UnsafeButtonComponent) {
|
||||
if (other instanceof UnsafeButtonComponent) {
|
||||
return isEqual(other.data, this.data);
|
||||
}
|
||||
return isEqual(other, this.data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user