Skip to content

Commit

Permalink
Unrelated files from master
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming committed Sep 27, 2024
1 parent 269e045 commit e5b0a7c
Show file tree
Hide file tree
Showing 21 changed files with 558 additions and 30 deletions.
17 changes: 16 additions & 1 deletion src/Discord/Builders/CommandAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
* @property int $type The type of the command, defaults 1 if not set.
* @property string $name 1-32 character name of the command.
* @property ?string[]|null $name_localizations Localization dictionary for the name field. Values follow the same restrictions as name.
* @property string $description 1-100 character description for CHAT_INPUT commands, empty string for USER and MESSAGE commands.
* @property ?string $description 1-100 character description for CHAT_INPUT commands, empty string for USER and MESSAGE commands.
* @property ?string[]|null $description_localizations Localization dictionary for the description field. Values follow the same restrictions as description.
* @property \Discord\Helpers\Collection|Option[]|null $options The parameters for the command, max 25. Only for Slash command (CHAT_INPUT).
* @property ?string $default_member_permissions Set of permissions represented as a bit set.
* @property bool|null $dm_permission Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible.
* @property ?bool $default_permission Whether the command is enabled by default when the app is added to a guild. SOON DEPRECATED.
* @property ?int $guild_id The optional guild ID this command is for. If not set, the command is global.
* @property bool|null $nsfw Indicates whether the command is age-restricted, defaults to `false`.
*/
trait CommandAttributes
Expand Down Expand Up @@ -208,6 +209,20 @@ public function setDmPermission(bool $permission): self
return $this;
}

/**
* Sets the guild ID of the command.
*
* @param int $guildId Guild ID of the command.
*
* @return $this
*/
public function setGuildId(int $guildId): self
{
$this->guild_id = $guildId;

return $this;
}

/**
* Sets the age restriction of the command.
*
Expand Down
6 changes: 4 additions & 2 deletions src/Discord/Builders/CommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class CommandBuilder implements JsonSerializable
/**
* Description of the command. should be empty if the type is not CHAT_INPUT.
*
* @var string
* @var string|null
*/
protected string $description;
protected ?string $description = null;

/**
* The default permission of the command. If true the command is enabled when the app is added to the guild.
Expand Down Expand Up @@ -96,6 +96,8 @@ public function toArray(): array
'default_member_permissions',
'default_permission',
'dm_permission',
'guild_id',
'nsfw',
];

foreach ($optionals as $optional) {
Expand Down
147 changes: 146 additions & 1 deletion src/Discord/Builders/Components/SelectMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,49 @@
*/
abstract class SelectMenu extends Component
{
/**
* Type of select menu component (text: 3, user: 5, role: 6, mentionable: 7, channels: 8)
*
* @var integer
*/
protected $type;

/**
* Custom ID to identify the select menu.
*
* @var string
*/
protected $custom_id;

/**
* Specified choices in a select menu (only required and available for string selects (type 3); max 25
*
* @var array|null
*/
protected $options;

/**
* List of channel types to include in the channel select component (type 8)
*
* @var array|null
*/
protected $channel_types;

/**
* Placeholder string to display if nothing is selected. Maximum 150 characters.
*
* @var string|null
*/
protected $placeholder;

/**
* List of default values for auto-populated select menu components;
* number of default values must be in the range defined by min_values and max_values
*
* @var array|null
*/
protected $default_values;

/**
* Minimum number of options that must be selected.
* Default 1, minimum 0, maximum 25.
Expand Down Expand Up @@ -104,12 +133,34 @@ public static function new(?string $custom_id = null): self
return new static($custom_id);
}

/**
* Sets the type for the select menu.
* (text: 3, user: 5, role: 6, mentionable: 7, channels: 8)
*
* @param int $type
*
* @throws \InvalidArgumentException
*
* @return string
*/
public function setType(int $type): self
{
$allowed_types = [self::TYPE_STRING_SELECT, self::TYPE_USER_SELECT, self::TYPE_ROLE_SELECT, self::TYPE_MENTIONABLE_SELECT, self::TYPE_CHANNEL_SELECT];
if (! in_array($type, $allowed_types)) {
throw new \InvalidArgumentException('Invalid select menu type.');
}

$this->type = $type;

return $this;
}

/**
* Sets the custom ID for the select menu.
*
* @param string $custom_id
*
* @throws \LengthException
* @throws \LengthException If the custom ID is longer than 100 characters.
*
* @return $this
*/
Expand All @@ -124,6 +175,49 @@ public function setCustomId($custom_id): self
return $this;
}

/**
* Specified choices in a select menu (only required and available for string selects (type 3); max 25
*
* @param array $options
*
* @throws \InvalidArgumentException If the select menu type is not `TYPE_STRING_SELECT`.
*
* @return $this
*/
public function setOptions(array $options): self
{
if ($this->type != self::TYPE_STRING_SELECT) {
throw new \InvalidArgumentException('Options can only be set for string selects.');
}

$this->options = $options;

return $this;
}

/**
* Sets the channel types for the select menu.
*
* This method is only applicable if the select menu type is `TYPE_CHANNEL_SELECT`.
* If the select menu type is not `TYPE_CHANNEL_SELECT`, an `InvalidArgumentException` will be thrown.
*
* @param array $channel_types
*
* @throws \InvalidArgumentException If the select menu type is not `TYPE_CHANNEL_SELECT`.
*
* @return $this
*/
public function setChannelTypes(array $channel_types): self
{
if ($this->type != self::TYPE_CHANNEL_SELECT) {
throw new \InvalidArgumentException('Channel types can only be set for channel selects.');
}

$this->channel_types = $channel_types;

return $this;
}

/**
* Sets the placeholder string to display if nothing is selected.
*
Expand All @@ -144,6 +238,17 @@ public function setPlaceholder(?string $placeholder): self
return $this;
}

public function setDefaultValues(?array $default_values): self
{
$allowed_types = [self::TYPE_USER_SELECT, self::TYPE_ROLE_SELECT, self::TYPE_MENTIONABLE_SELECT, self::TYPE_CHANNEL_SELECT];
if (! in_array($this->type, $allowed_types)) {
throw new \InvalidArgumentException('Default values can only be set for user, role, mentionable, and channel selects.');
}
$this->default_values = $default_values;

return $this;
}

/**
* Sets the minimum number of options which must be chosen.
*
Expand Down Expand Up @@ -290,6 +395,16 @@ public function removeListener(): self
return $this->setListener(null, $this->discord);
}

/**
* Returns the type of the select menu.
*
* @return int
*/
public function getType(): int
{
return $this->type;
}

/**
* Returns the Custom ID of the select menu.
*
Expand All @@ -300,6 +415,26 @@ public function getCustomId(): string
return $this->custom_id;
}

/**
* Returns the options of the select menu.
*
* @return array|null
*/
public function getOptions(): ?array
{
return $this->options;
}

/**
* Returns the channel types of the select menu.
*
* @return array|null
*/
public function getChannelTypes(): ?array
{
return $this->channel_types;
}

/**
* Returns the placeholder string of the select menu.
*
Expand All @@ -310,6 +445,16 @@ public function getPlaceholder(): ?string
return $this->placeholder;
}

/**
* Returns the default values of the select menu.
*
* @return array|null
*/
public function getDefaultValues(): ?array
{
return $this->default_values;
}

/**
* Returns the minimum number of options that must be selected.
*
Expand Down
39 changes: 21 additions & 18 deletions src/Discord/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Discord\Parts\User\Member;
use Discord\Parts\User\User;
use Discord\Repository\AbstractRepository;
use Discord\Repository\EmojiRepository;
use Discord\Repository\GuildRepository;
use Discord\Repository\PrivateChannelRepository;
use Discord\Repository\UserRepository;
Expand All @@ -42,11 +43,12 @@
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger as Monolog;
use Monolog\Level;
use Psr\Log\LoggerInterface;
use Ratchet\Client\Connector;
use Ratchet\Client\WebSocket;
use Ratchet\RFC6455\Messaging\Message;
use React\EventLoop\Factory as LoopFactory;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use React\EventLoop\TimerInterface;
use React\Promise\ExtendedPromiseInterface;
Expand All @@ -61,20 +63,21 @@
*
* @version 10.0.0
*
* @property string $id The unique identifier of the client.
* @property string $username The username of the client.
* @property string $password The password of the client (if they have provided it).
* @property string $email The email of the client.
* @property bool $verified Whether the client has verified their email.
* @property string $avatar The avatar URL of the client.
* @property string $avatar_hash The avatar hash of the client.
* @property string $discriminator The unique discriminator of the client.
* @property bool $bot Whether the client is a bot.
* @property User $user The user instance of the client.
* @property Application $application The OAuth2 application of the bot.
* @property GuildRepository $guilds
* @property PrivateChannelRepository $private_channels
* @property UserRepository $users
* @property string $id The unique identifier of the client.
* @property string $username The username of the client.
* @property string $password The password of the client (if they have provided it).
* @property string $email The email of the client.
* @property bool $verified Whether the client has verified their email.
* @property string $avatar The avatar URL of the client.
* @property string $avatar_hash The avatar hash of the client.
* @property string $discriminator The unique discriminator of the client.
* @property bool $bot Whether the client is a bot.
* @property User $user The user instance of the client.
* @property Application $application The OAuth2 application of the bot.
* @property GuildRepository $guilds
* @property PrivateChannelRepository $private_channels
* @property UserRepository $users
* @property EmojiRepository $emojis
*/
class Discord
{
Expand Down Expand Up @@ -322,7 +325,7 @@ class Discord
/**
* The cache configuration.
*
* @var CacheConfig
* @var CacheConfig[]
*/
protected $cacheConfig;

Expand Down Expand Up @@ -1426,10 +1429,10 @@ protected function resolveOptions(array $options = []): array

$options = $resolver->resolve($options);

$options['loop'] ??= LoopFactory::create();
$options['loop'] ??= Loop::get();

if (null === $options['logger']) {
$streamHandler = new StreamHandler('php://stdout', Monolog::DEBUG);
$streamHandler = new StreamHandler('php://stdout', Level::Debug);
$lineFormatter = new LineFormatter(null, null, true, true);
$streamHandler->setFormatter($lineFormatter);
$logger = new Monolog('DiscordPHP', [$streamHandler]);
Expand Down
7 changes: 4 additions & 3 deletions src/Discord/Parts/Channel/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
* @property InviteRepository $invites Invites in the channel.
* @property StageInstanceRepository $stage_instances Stage instances in the channel.
*
* @method ExtendedPromiseInterface<Message> sendMessage(MessageBuilder $builder)
* @method ExtendedPromiseInterface<Message> sendMessage(MessageBuilder|string $builder)
*/
class Channel extends Part implements Stringable
{
Expand All @@ -114,6 +114,7 @@ class Channel extends Part implements Stringable
public const TYPE_GUILD_STAGE_VOICE = 13;
public const TYPE_GUILD_DIRECTORY = 14;
public const TYPE_GUILD_FORUM = 15;
public const TYPE_GUILD_MEDIA = 16;

/** @deprecated 10.0.0 Use `Channel::TYPE_GUILD_TEXT` */
public const TYPE_TEXT = self::TYPE_GUILD_TEXT;
Expand Down Expand Up @@ -912,14 +913,14 @@ protected function setPermissionOverwritesAttribute(?array $overwrites): void
*/
protected function getPermissionOverwritesAttribute(): ?array
{
$overwrites = null;
$overwrites = [];

/** @var Overwrite */
foreach ($this->overwrites as $overwrite) {
$overwrites[] = $overwrite->getRawAttributes();
}

return $overwrites ?? $this->attributes['permission_overwrites'] ?? null;
return ! empty($overwrites) ? $overwrites : ($this->attributes['permission_overwrites'] ?? null);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Discord/Parts/Guild/AuditLog/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class Entry extends Part
public const AUTO_MODERATION_BLOCK_MESSAGE = 143;
public const AUTO_MODERATION_FLAG_TO_CHANNEL = 144;
public const AUTO_MODERATION_USER_COMMUNICATION_DISABLED = 145;
public const CREATOR_MONETIZATION_REQUEST_CREATED = 150;
public const CREATOR_MONETIZATION_TERMS_ACCEPTED = 151;

// AUDIT LOG ENTRY TYPES

Expand Down
Loading

0 comments on commit e5b0a7c

Please sign in to comment.