Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Discord/Builders/Components/ActionRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
*/
class ActionRow extends Layout
{
/** Usage of ActionRow in Modal is deprecated. Use `Component::Label` as the top-level container. */
/** Usage of ActionRow in Modal is deprecated. Use `ComponentObject::Label` as the top-level container. */
public const USAGE = ['Message', 'Modal'];

/**
* Component type.
*
* @var int
*/
protected $type = Component::TYPE_ACTION_ROW;
protected $type = ComponentObject::TYPE_ACTION_ROW;

/**
* Components contained by the action row.
Expand Down
4 changes: 2 additions & 2 deletions src/Discord/Builders/Components/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Button extends Interactive
*
* @var int
*/
protected $type = Component::TYPE_BUTTON;
protected $type = ComponentObject::TYPE_BUTTON;

/**
* Style of button.
Expand Down Expand Up @@ -519,7 +519,7 @@ protected function createListener(callable $callback, bool $oneOff = false, int|
$timer = null;

$listener = function (Interaction $interaction) use ($callback, $oneOff, &$timer) {
if ($interaction->data->component_type !== Component::TYPE_BUTTON || $interaction->data->custom_id !== $this->custom_id) {
if ($interaction->data->component_type !== ComponentObject::TYPE_BUTTON || $interaction->data->custom_id !== $this->custom_id) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/ChannelSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ChannelSelect extends SelectMenu
*
* @var int
*/
protected $type = Component::TYPE_CHANNEL_SELECT;
protected $type = ComponentObject::TYPE_CHANNEL_SELECT;

/**
* List of channel types to include.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ abstract class Component extends Builder implements JsonSerializable
/** Undocumented. */
public const TYPE_CHECKPOINT_CARD = 20;

/** @deprecated 7.4.0 Use `Component::TYPE_STRING_SELECT` */
/** @deprecated 7.4.0 Use `ComponentObject::TYPE_STRING_SELECT` */
public const TYPE_SELECT_MENU = 3;

/**
Expand Down
11 changes: 11 additions & 0 deletions src/Discord/Builders/Components/ComponentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Discord\Builders\Components;

use Discord\Parts\Channel\Message\Component as ComponentPart;

/**
* Components allow you to style and structure your messages, modals, and interactions.
* They are interactive elements that can create rich user experiences in your Discord applications.
Expand All @@ -28,6 +30,15 @@ abstract class ComponentObject extends Component
{
public const USAGE = [];

/**
* Available components and their respective classes.
*
* Alias of Component::TYPES.
*
* @var array<int, string>
*/
public const TYPES = ComponentPart::TYPES;

/**
* The type of the component.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Container extends Layout implements Contracts\ComponentV2
*
* @var int
*/
protected $type = Component::TYPE_CONTAINER;
protected $type = ComponentObject::TYPE_CONTAINER;

/**
* Array of components.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class File extends Content implements Contracts\ComponentV2
*
* @var int
*/
protected $type = Component::TYPE_FILE;
protected $type = ComponentObject::TYPE_FILE;

/**
* The file to be displayed.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FileUpload extends Interactive
*
* @var int
*/
protected $type = Component::TYPE_FILE_UPLOAD;
protected $type = ComponentObject::TYPE_FILE_UPLOAD;

/**
* Minimum number of files that can be uploaded.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Label extends Layout
*
* @var int
*/
protected $type = Component::TYPE_LABEL;
protected $type = ComponentObject::TYPE_LABEL;

/**
* The text for the label.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/MediaGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MediaGallery extends Content implements Contracts\ComponentV2
*
* @var int
*/
protected $type = Component::TYPE_MEDIA_GALLERY;
protected $type = ComponentObject::TYPE_MEDIA_GALLERY;

/**
* Array of media gallery items.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/MentionableSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MentionableSelect extends SelectMenu
*
* @var int
*/
protected $type = Component::TYPE_MENTIONABLE_SELECT;
protected $type = ComponentObject::TYPE_MENTIONABLE_SELECT;

/**
* Set if this component is required to be filled, default false. (Modal only).
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/RoleSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RoleSelect extends SelectMenu
*
* @var int
*/
protected $type = Component::TYPE_ROLE_SELECT;
protected $type = ComponentObject::TYPE_ROLE_SELECT;

/**
* Set if this component is required to be filled, default false. (Modal only).
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Section extends Layout implements Contracts\ComponentV2
*
* @var int
*/
protected $type = Component::TYPE_SECTION;
protected $type = ComponentObject::TYPE_SECTION;

/**
* Array of text display components.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/SelectMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class SelectMenu extends Interactive
*
* @var int
*/
protected $type = Component::TYPE_SELECT_MENU; // Default type
protected $type = ComponentObject::TYPE_STRING_SELECT; // Default type

/**
* Custom ID to identify the select menu.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/Separator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Separator extends Layout implements Contracts\ComponentV2
*
* @var int
*/
protected $type = Component::TYPE_SEPARATOR;
protected $type = ComponentObject::TYPE_SEPARATOR;

/**
* Whether the separator is a divider.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/StringSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class StringSelect extends SelectMenu
*
* @var int
*/
protected $type = Component::TYPE_STRING_SELECT;
protected $type = ComponentObject::TYPE_STRING_SELECT;

/**
* Array of options that the select menu has.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/TextDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TextDisplay extends Content implements Contracts\ComponentV2
*
* @var int
*/
protected $type = Component::TYPE_TEXT_DISPLAY;
protected $type = ComponentObject::TYPE_TEXT_DISPLAY;

/**
* Content of the text display.
Expand Down
4 changes: 2 additions & 2 deletions src/Discord/Builders/Components/TextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TextInput extends Interactive
*
* @var int
*/
protected $type = Component::TYPE_TEXT_INPUT;
protected $type = ComponentObject::TYPE_TEXT_INPUT;

/**
* Style of text input.
Expand All @@ -57,7 +57,7 @@ class TextInput extends Interactive
/**
* Label for the text input.
*
* @deprecated Use a top-level `Component::Label`
* @deprecated Use a top-level `ComponentObject::Label`
*
* @var string|null
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/Thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Thumbnail extends Content implements Contracts\ComponentV2
*
* @var int
*/
protected $type = Component::TYPE_THUMBNAIL;
protected $type = ComponentObject::TYPE_THUMBNAIL;

/**
* Media item for the thumbnail.
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/Components/UserSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UserSelect extends SelectMenu
*
* @var int
*/
protected $type = Component::TYPE_USER_SELECT;
protected $type = ComponentObject::TYPE_USER_SELECT;

/**
* Set if this component is required to be filled, default false. (Modal only).
Expand Down
7 changes: 3 additions & 4 deletions src/Discord/Builders/MessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Discord\Builders;

use Discord\Builders\Components\ActionRow;
use Discord\Builders\Components\Component;
use Discord\Builders\Components\ComponentObject;
use Discord\Builders\Components\Contracts\ComponentV2;
use Discord\Builders\Components\Interactive;
Expand All @@ -24,7 +23,7 @@
use Discord\Parts\Channel\Attachment;
use Discord\Parts\Channel\Message;
use Discord\Parts\Channel\Message\AllowedMentions;
use Discord\Parts\Channel\Poll\Poll;
use Discord\Parts\Channel\Poll\PollCreateRequest as Poll;
use Discord\Parts\Embed\Embed;
use Discord\Parts\Guild\Sticker;
use JsonSerializable;
Expand Down Expand Up @@ -536,7 +535,7 @@ public function countTotalComponents(): int
*
* @return $this
*/
public function removeComponent(Component $component): self
public function removeComponent($component): self
{
if (! isset($this->components)) {
return $this;
Expand Down Expand Up @@ -787,7 +786,7 @@ public function clearAttachments(): self
*
* @return $this
*/
public function setPoll(Poll|null $poll): self
public function setPoll($poll = null): self
{
$this->poll = $poll;

Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Builders/ModalBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function setComponents(...$components): self
*
* Only ActionRow, TextDisplay, and Label components are allowed.
*
* Using ActionRow in modals is now deprecated. Use `Component::Label` as the top level component.
* Using ActionRow in modals is now deprecated. Use `ComponentObject::Label` as the top level component.
*
* @param ComponentObject $component
*
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Parts/Channel/Message/ActionRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* An Action Row is a top-level layout component used in messages.
*
* Using ActionRows in modals is now deprecated - use Component::Label as the top level component!
* Using ActionRows in modals is now deprecated - use ComponentObject::Label as the top level component!
*
* Action Rows can contain:
*
Expand Down
42 changes: 21 additions & 21 deletions src/Discord/Parts/Channel/Message/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Discord\Parts\Channel\Message;

use Discord\Builders\Components\Component as ComponentBuilder;
use Discord\Builders\Components\ComponentObject;
use Discord\Helpers\ExCollectionInterface;
use Discord\Parts\Part;

Expand All @@ -39,24 +39,24 @@ class Component extends Part
* @var array<int, string>
*/
public const TYPES = [
0 => Component::class, // Fallback for unknown types
ComponentBuilder::TYPE_ACTION_ROW => ActionRow::class,
ComponentBuilder::TYPE_BUTTON => Button::class,
ComponentBuilder::TYPE_STRING_SELECT => StringSelect::class,
ComponentBuilder::TYPE_TEXT_INPUT => TextInput::class,
ComponentBuilder::TYPE_USER_SELECT => UserSelect::class,
ComponentBuilder::TYPE_ROLE_SELECT => RoleSelect::class,
ComponentBuilder::TYPE_MENTIONABLE_SELECT => MentionableSelect::class,
ComponentBuilder::TYPE_CHANNEL_SELECT => ChannelSelect::class,
ComponentBuilder::TYPE_SECTION => Section::class,
ComponentBuilder::TYPE_TEXT_DISPLAY => TextDisplay::class,
ComponentBuilder::TYPE_THUMBNAIL => Thumbnail::class,
ComponentBuilder::TYPE_MEDIA_GALLERY => MediaGallery::class,
ComponentBuilder::TYPE_FILE => File::class,
ComponentBuilder::TYPE_SEPARATOR => Separator::class,
ComponentBuilder::TYPE_CONTAINER => Container::class,
ComponentBuilder::TYPE_LABEL => Label::class,
ComponentBuilder::TYPE_FILE_UPLOAD => FileUpload::class,
0 => ComponentObject::class, // Fallback for unknown types
ComponentObject::TYPE_ACTION_ROW => ActionRow::class,
ComponentObject::TYPE_BUTTON => Button::class,
ComponentObject::TYPE_STRING_SELECT => StringSelect::class,
ComponentObject::TYPE_TEXT_INPUT => TextInput::class,
ComponentObject::TYPE_USER_SELECT => UserSelect::class,
ComponentObject::TYPE_ROLE_SELECT => RoleSelect::class,
ComponentObject::TYPE_MENTIONABLE_SELECT => MentionableSelect::class,
ComponentObject::TYPE_CHANNEL_SELECT => ChannelSelect::class,
ComponentObject::TYPE_SECTION => Section::class,
ComponentObject::TYPE_TEXT_DISPLAY => TextDisplay::class,
ComponentObject::TYPE_THUMBNAIL => Thumbnail::class,
ComponentObject::TYPE_MEDIA_GALLERY => MediaGallery::class,
ComponentObject::TYPE_FILE => File::class,
ComponentObject::TYPE_SEPARATOR => Separator::class,
ComponentObject::TYPE_CONTAINER => Container::class,
ComponentObject::TYPE_LABEL => Label::class,
ComponentObject::TYPE_FILE_UPLOAD => FileUpload::class,
];

/**
Expand All @@ -74,14 +74,14 @@ class Component extends Part
*/
protected function getComponentsAttribute(): ExCollectionInterface
{
return $this->attributeTypedCollectionHelper(Component::class, 'components');
return $this->attributeTypedCollectionHelper(ComponentObject::class, 'components');
}

/**
* Gets the component.
*/
public function getComponentAttribute(): ?Component
{
return $this->attributePartHelper('component', Component::TYPES[$this->attributes['component']->type ?? 0]);
return $this->attributePartHelper('component', self::TYPES[$this->attributes['component']->type ?? 0]);
}
}