Skip to content

Commit

Permalink
Patch Version 7.0.6 (#773)
Browse files Browse the repository at this point in the history
* add client to $discord __debugInfo

* max modal title & text input label

* deprecation of game store & non existing function

* other small fix with phpdoc

* add notes about slash command and option names

* dot

* Interaction::showModal() phpdoc throws LengthException

* TextInput constructor optional param
  • Loading branch information
SQKo authored Mar 30, 2022
1 parent 5801f85 commit 0fcd6ca
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/Discord/Builders/CommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function setType(int $type): self
/**
* Sets the name of the command.
*
* @param string $description Name of the command
* @param string $description Name of the command. Slash command names are lowercase.
*
* @throws \LengthException
*
Expand Down
8 changes: 4 additions & 4 deletions src/Discord/Builders/Components/TextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TextInput extends Component
* @param int $style The style of the text input.
* @param string|null $custom_id The custom ID of the text input. If not given, an UUID will be used
*/
public function __construct(string $label, int $style, ?string $custom_id)
public function __construct(string $label, int $style, ?string $custom_id = null)
{
$this->setLabel($label);
$this->setStyle($style);
Expand Down Expand Up @@ -150,16 +150,16 @@ public function setStyle(int $style): self
/**
* Sets the label of the text input.
*
* @param string $label Label of the text input. Maximum 80 characters.
* @param string $label Label of the text input. Maximum 45 characters.
*
* @throws \LengthException
*
* @return $this
*/
public function setLabel(string $label): self
{
if (poly_strlen($label) > 80) {
throw new \LengthException('Label must be maximum 80 characters.');
if (poly_strlen($label) > 45) {
throw new \LengthException('Label must be maximum 45 characters.');
}

$this->label = $label;
Expand Down
2 changes: 2 additions & 0 deletions src/Discord/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,8 @@ public function __debugInfo(): array

unset($config['loop'], $config['logger']);

$config[] = $this->client;

return $config;
}
}
1 change: 1 addition & 0 deletions src/Discord/Parts/Channel/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Channel extends Part
public const TYPE_GROUP = 3;
public const TYPE_CATEGORY = 4;
public const TYPE_NEWS = 5;
/** @deprecated 7.0.6 */
public const TYPE_GAME_STORE = 6;
public const TYPE_NEWS_THREAD = 10;
public const TYPE_PUBLIC_THREAD = 11;
Expand Down
2 changes: 2 additions & 0 deletions src/Discord/Parts/Channel/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Invite extends Part
/**
* Accepts the invite.
*
* @deprecated 7.0.6
*
* @return ExtendedPromiseInterface
*/
public function accept(): ExtendedPromiseInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Parts/Channel/StageInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class StageInstance extends Part
'channel_id',
'topic',
'privacy_level',
'discoverable_disabled',
'discoverable_disabled', // deprecated
'guild_scheduled_event_id',
];

Expand Down
3 changes: 1 addition & 2 deletions src/Discord/Parts/Guild/Guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
* @property int|null $max_presences Maximum amount of presences allowed in the guild.
* @property int|null $max_members Maximum amount of members allowed in the guild.
* @property string $vanity_url_code Vanity URL code for the guild.
* @property string $description Guild description if it is discoverable.
* @property string $description Guild description of a guild.
* @property string $banner Banner hash.
* @property int $premium_tier Server boost level.
* @property int|null $premium_subscription_count Number of boosts in the guild.
Expand Down Expand Up @@ -1020,7 +1020,6 @@ public function getWidget(): ExtendedPromiseInterface
*/
public function createInvite(...$args): ExtendedPromiseInterface
{
/** @var Member */
$channel = $this->channels->find(function (Channel $channel) {
return $channel->allowInvite() && $channel->getBotPermissions()->create_instant_invite;
});
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Parts/Interactions/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @property string $application_id The unique identifier of the parent Application that made the command, if made by one.
* @property string|null $guild_id The unique identifier of the guild that the command belongs to. Null if global.
* @property Guild|null $guild The guild that the command belongs to. Null if global.
* @property string $name 1-32 character name of the command.
* @property string $name 1-32 character name of the command. CHAT_INPUT command name is lowercase.
* @property string $description 1-100 character description for CHAT_INPUT commands, empty string for USER and MESSAGE commands.
* @property Collection|Option[]|null $options The parameters for the command, max 25. Only for Slash command (CHAT_INPUT).
* @property bool $default_permission Whether the command is enabled by default when the app is added to a guild.
Expand Down
7 changes: 5 additions & 2 deletions src/Discord/Parts/Interactions/Command/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
*
* @property int $type Type of the option.
* @property string $name Name of the option.
* @property string $name Name of the option. CHAT_INPUT option name is lowercase.
* @property string $description 1-100 character description.
* @property bool $required If the parameter is required or optional--default false.
* @property Collection|Choice[]|null $choices Choices for STRING, INTEGER, and NUMBER types for the user to pick from, max 25. Only for slash commands.
Expand Down Expand Up @@ -120,8 +120,11 @@ public function setType(int $type): self

/**
* Sets the name of the option.
* CHAT_INPUT command option names must match the following regex ^[\w-]{1,32}$ with the unicode flag set.
* If there is a lowercase variant of any letters used, you must use those.
* Characters with no lowercase variants and/or uncased letters are still allowed.
*
* @param string $name name of the option
* @param string $name name of the option. Slash command option names are lowercase.
*
* @throws \LengthException
*
Expand Down
10 changes: 8 additions & 2 deletions src/Discord/Parts/Interactions/Interaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Discord\WebSockets\Event;
use React\Promise\ExtendedPromiseInterface;

use function Discord\poly_strlen;
use function React\Promise\reject;

/**
Expand Down Expand Up @@ -327,7 +328,7 @@ public function deleteOriginalResponse(): ExtendedPromiseInterface
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#create-followup-message
*
* @param MessageBuilder $builder Message to send.
* @param bool $ephemeral Whether the created follow-up should be ephemeral.
* @param bool $ephemeral Whether the created follow-up should be ephemeral. Will be ignored if the respond is previously ephemeral.
*
* @throws \RuntimeException
*
Expand Down Expand Up @@ -524,12 +525,13 @@ public function autoCompleteResult(array $choices): ExtendedPromiseInterface
*
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction
*
* @param string $title The title of the popup modal
* @param string $title The title of the popup modal, max 45 characters
* @param string $custom_id A developer-defined identifier for the component, max 100 characters
* @param array|Component[] $components Between 1 and 5 (inclusive) components that make up the modal contained in Action Row
* @param callable|null $submit The function to call once modal is submitted.
*
* @throws \LogicException
* @throws \LengthException
*
* @return ExtendedPromiseInterface
*/
Expand All @@ -539,6 +541,10 @@ public function showModal(string $title, string $custom_id, array $components, ?
return reject(new \LogicException('You cannot pop up a modal from a ping or modal submit interaction.'));
}

if (poly_strlen($title) > 45) {
return reject(new \LengthException('Modal title must be less than or equal to 45 characters.'));
}

return $this->respond([
'type' => InteractionResponseType::MODAL,
'data' => [
Expand Down
3 changes: 1 addition & 2 deletions src/Discord/Parts/OAuth/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @property string|null $terms_of_service_url The url of the app's terms of service.
* @property string|null $privacy_policy_url The url of the app's privacy policy
* @property User|null $owner The owner of the OAuth application.
* @property string $summary If this application is a game sold on Discord, this field will be the summary field for the store page of its primary sku.
* @property string $verify_key The hex encoded key for verification in interactions and the GameSDK's GetTicket.
* @property object|null $team If the application belongs to a team, this will be a list of the members of that team.
* @property string|null $guild_id If this application is a game sold on Discord, this field will be the guild to which it has been linked.
Expand Down Expand Up @@ -61,7 +60,7 @@ class Application extends Part
'owner',
'primary_sku_id',
'slug',
'summary',
'summary', // deprecated, is now empty, used to be same as description
'team',
'verify_key',
'rpc_origins',
Expand Down
27 changes: 10 additions & 17 deletions src/Discord/Parts/Permissions/RolePermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,9 @@
/**
* @inheritdoc
*
* @property bool $connect
* @property bool $mute_members
* @property bool $deafen_members
* @property bool $move_members
* @property bool $request_to_speak
* @property bool $manage_events
*
* @property bool $add_reactions
* @property bool $priority_speaker
* @property bool $stream
* @property bool $connect
* @property bool $speak
* @property bool $mute_members
* @property bool $deafen_members
* @property bool $move_members
* @property bool $use_vad
* @property bool $manage_events
* @property bool $start_embedded_activities @todo $use_embedded_activities
*
* @property bool $add_reactions
* @property bool $send_messages
* @property bool $send_tts_messages
* @property bool $manage_messages
Expand All @@ -41,13 +25,22 @@
* @property bool $read_message_history
* @property bool $mention_everyone
* @property bool $use_external_emojis
* @property bool $connect
* @property bool $speak
* @property bool $mute_members
* @property bool $deafen_members
* @property bool $move_members
* @property bool $use_vad
* @property bool $manage_webhooks
* @property bool $use_application_commands
* @property bool $request_to_speak
* @property bool $manage_events
* @property bool $manage_threads
* @property bool $create_public_threads
* @property bool $create_private_threads
* @property bool $use_external_stickers
* @property bool $send_messages_in_threads
* @property bool $start_embedded_activities @todo $use_embedded_activities
*
* @property bool $kick_members
* @property bool $ban_members
Expand Down
3 changes: 2 additions & 1 deletion src/Discord/WebSockets/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ abstract class Event
use EventEmitterTrait;

// General
/** Not to be confused with 'ready' */
public const READY = 'READY';
public const RESUMED = 'RESUMED';
public const PRESENCE_UPDATE = 'PRESENCE_UPDATE';
Expand Down Expand Up @@ -76,7 +77,7 @@ abstract class Event
public const CHANNEL_DELETE = 'CHANNEL_DELETE';
public const CHANNEL_UPDATE = 'CHANNEL_UPDATE';
public const CHANNEL_PINS_UPDATE = 'CHANNEL_PINS_UPDATE';

// Threads
public const THREAD_CREATE = 'THREAD_CREATE';
public const THREAD_UPDATE = 'THREAD_UPDATE';
Expand Down

0 comments on commit 0fcd6ca

Please sign in to comment.