From 0fcd6ca5321816a0c44803b41626d48fa5ab2156 Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Wed, 30 Mar 2022 22:07:05 +0700 Subject: [PATCH] Patch Version 7.0.6 (#773) * 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 --- src/Discord/Builders/CommandBuilder.php | 2 +- src/Discord/Builders/Components/TextInput.php | 8 +++--- src/Discord/Discord.php | 2 ++ src/Discord/Parts/Channel/Channel.php | 1 + src/Discord/Parts/Channel/Invite.php | 2 ++ src/Discord/Parts/Channel/StageInstance.php | 2 +- src/Discord/Parts/Guild/Guild.php | 3 +-- .../Parts/Interactions/Command/Command.php | 2 +- .../Parts/Interactions/Command/Option.php | 7 +++-- .../Parts/Interactions/Interaction.php | 10 +++++-- src/Discord/Parts/OAuth/Application.php | 3 +-- .../Parts/Permissions/RolePermission.php | 27 +++++++------------ src/Discord/WebSockets/Event.php | 3 ++- 13 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/Discord/Builders/CommandBuilder.php b/src/Discord/Builders/CommandBuilder.php index 24363137f..229e9bfc0 100644 --- a/src/Discord/Builders/CommandBuilder.php +++ b/src/Discord/Builders/CommandBuilder.php @@ -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 * diff --git a/src/Discord/Builders/Components/TextInput.php b/src/Discord/Builders/Components/TextInput.php index b195ee41f..9cd8235d1 100644 --- a/src/Discord/Builders/Components/TextInput.php +++ b/src/Discord/Builders/Components/TextInput.php @@ -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); @@ -150,7 +150,7 @@ 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 * @@ -158,8 +158,8 @@ public function setStyle(int $style): self */ 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; diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index a2b4e0f74..c4ae1f10c 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -1602,6 +1602,8 @@ public function __debugInfo(): array unset($config['loop'], $config['logger']); + $config[] = $this->client; + return $config; } } diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index c9d7a5d58..6a22c5214 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -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; diff --git a/src/Discord/Parts/Channel/Invite.php b/src/Discord/Parts/Channel/Invite.php index fefadf237..b44696200 100644 --- a/src/Discord/Parts/Channel/Invite.php +++ b/src/Discord/Parts/Channel/Invite.php @@ -80,6 +80,8 @@ class Invite extends Part /** * Accepts the invite. * + * @deprecated 7.0.6 + * * @return ExtendedPromiseInterface */ public function accept(): ExtendedPromiseInterface diff --git a/src/Discord/Parts/Channel/StageInstance.php b/src/Discord/Parts/Channel/StageInstance.php index a8f646498..5dee38a72 100644 --- a/src/Discord/Parts/Channel/StageInstance.php +++ b/src/Discord/Parts/Channel/StageInstance.php @@ -43,7 +43,7 @@ class StageInstance extends Part 'channel_id', 'topic', 'privacy_level', - 'discoverable_disabled', + 'discoverable_disabled', // deprecated 'guild_scheduled_event_id', ]; diff --git a/src/Discord/Parts/Guild/Guild.php b/src/Discord/Parts/Guild/Guild.php index f285bb4fe..0691c2c88 100644 --- a/src/Discord/Parts/Guild/Guild.php +++ b/src/Discord/Parts/Guild/Guild.php @@ -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. @@ -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; }); diff --git a/src/Discord/Parts/Interactions/Command/Command.php b/src/Discord/Parts/Interactions/Command/Command.php index dbf9cc830..0b32f1aac 100644 --- a/src/Discord/Parts/Interactions/Command/Command.php +++ b/src/Discord/Parts/Interactions/Command/Command.php @@ -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. diff --git a/src/Discord/Parts/Interactions/Command/Option.php b/src/Discord/Parts/Interactions/Command/Option.php index 7484ae8fe..a0c9fcc29 100644 --- a/src/Discord/Parts/Interactions/Command/Option.php +++ b/src/Discord/Parts/Interactions/Command/Option.php @@ -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. @@ -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 * diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index bddead7e5..839576b30 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -30,6 +30,7 @@ use Discord\WebSockets\Event; use React\Promise\ExtendedPromiseInterface; +use function Discord\poly_strlen; use function React\Promise\reject; /** @@ -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 * @@ -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 */ @@ -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' => [ diff --git a/src/Discord/Parts/OAuth/Application.php b/src/Discord/Parts/OAuth/Application.php index 244bd5913..766527f22 100644 --- a/src/Discord/Parts/OAuth/Application.php +++ b/src/Discord/Parts/OAuth/Application.php @@ -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. @@ -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', diff --git a/src/Discord/Parts/Permissions/RolePermission.php b/src/Discord/Parts/Permissions/RolePermission.php index a7374c6a7..522993082 100644 --- a/src/Discord/Parts/Permissions/RolePermission.php +++ b/src/Discord/Parts/Permissions/RolePermission.php @@ -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 @@ -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 diff --git a/src/Discord/WebSockets/Event.php b/src/Discord/WebSockets/Event.php index 0f4593bf1..a6690a0d1 100644 --- a/src/Discord/WebSockets/Event.php +++ b/src/Discord/WebSockets/Event.php @@ -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'; @@ -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';