From 251477eed9873f95fa5e4b7bfda5fb24bc72cef1 Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:08:46 +0700 Subject: [PATCH 1/7] remove nick mention formatting --- src/Discord/Parts/User/Member.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Discord/Parts/User/Member.php b/src/Discord/Parts/User/Member.php index 051174a15..acc35ee7c 100644 --- a/src/Discord/Parts/User/Member.php +++ b/src/Discord/Parts/User/Member.php @@ -679,10 +679,6 @@ public function getRepositoryAttributes(): array */ public function __toString(): string { - if ($this->nick) { - return "<@!{$this->id}>"; - } - return "<@{$this->id}>"; } } From accdc7542d91c30daea9d87e045c34d64842096c Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:29:05 +0700 Subject: [PATCH 2/7] add forum channel --- src/Discord/Parts/Channel/Channel.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index c25175c3b..36967b45f 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -57,7 +57,7 @@ * @property string|null $name The name of the channel. * @property string|null $topic The topic of the channel. * @property bool|null $nsfw Whether the channel is NSFW. - * @property string|null $last_message_id The unique identifier of the last message sent in the channel. + * @property string|null $last_message_id The unique identifier of the last message sent in the channel (or thread for forum channels) (may not point to an existing or valid message or thread). * @property int|null $bitrate The bitrate of the channel. Only for voice channels. * @property int|null $user_limit The user limit of the channel. * @property int|null $rate_limit_per_user Amount of seconds a user has to wait before sending a new message. @@ -72,6 +72,7 @@ * @property string|null $rtc_region Voice region id for the voice channel, automatic when set to null. * @property int|null $video_quality_mode The camera video quality mode of the voice channel, 1 when not present. * @property int|null $default_auto_archive_duration Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080. + * @property int|null $flags Channel flags combined as a bitfield. * @property string|null $permissions Computed permissions for the invoking user in the channel, including overwrites, only included when part of the resolved data received on a slash command interaction. * @property bool $is_private Whether the channel is a private channel. * @property MemberRepository $members Voice channel only - members in the channel. @@ -98,10 +99,13 @@ class Channel extends Part public const TYPE_PRIVATE_THREAD = 12; public const TYPE_STAGE_CHANNEL = 13; public const TYPE_DIRECTORY = 14; + public const TYPE_FORUM = 15; public const VIDEO_QUALITY_AUTO = 1; public const VIDEO_QUALITY_FULL = 2; + public const FLAG_PINNED = (1 << 1); + /** * @inheritdoc */ @@ -128,6 +132,7 @@ class Channel extends Part 'video_quality_mode', 'default_auto_archive_duration', 'permissions', + 'flags', 'is_private', ]; From 8864b87d76e71400157ae3d5bfb0071cc7320b85 Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:30:08 +0700 Subject: [PATCH 3/7] add Interaction::isReponded and guild_id if exists --- src/Discord/Parts/Interactions/Interaction.php | 10 +++++++++- .../Parts/Interactions/Request/InteractionData.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index 839576b30..306c8fcac 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -87,6 +87,14 @@ class Interaction extends Part */ protected $responded = false; + /** + * Returns true if this interaction has been internally responded. + */ + public function isResponded(): bool + { + return $this->responded; + } + /** * Returns the data associated with the interaction. * @@ -99,7 +107,7 @@ protected function getDataAttribute(): ?InteractionData } $adata = $this->attributes['data']; - if (isset($this->attributes['guild_id'])) { + if (! isset($adata->guild_id) && isset($this->attributes['guild_id'])) { $adata->guild_id = $this->guild_id; } diff --git a/src/Discord/Parts/Interactions/Request/InteractionData.php b/src/Discord/Parts/Interactions/Request/InteractionData.php index 5a3e12554..0b6dd063a 100644 --- a/src/Discord/Parts/Interactions/Request/InteractionData.php +++ b/src/Discord/Parts/Interactions/Request/InteractionData.php @@ -30,7 +30,7 @@ * @property string[]|null $values Values selected in a select menu. * @property string|null $target_id Id the of user or message targetted by a user or message command. * @property ComponentRepository $components The values submitted by the user in modal. - * @property string|null $guild_id ID of the guild passed from Interaction. + * @property string|null $guild_id ID of the guild passed from Interaction or ID of the guild the command belongs to. */ class InteractionData extends Part { From 6cbc77c8ca42f0899115628853dbd201c903b782 Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:33:40 +0700 Subject: [PATCH 4/7] command throws --- src/Discord/Builders/CommandAttributes.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Discord/Builders/CommandAttributes.php b/src/Discord/Builders/CommandAttributes.php index 4f02e1540..01cc8e567 100644 --- a/src/Discord/Builders/CommandAttributes.php +++ b/src/Discord/Builders/CommandAttributes.php @@ -63,8 +63,10 @@ public function setType(int $type): self public function setName(string $name): self { $nameLen = poly_strlen($name); - if ($nameLen < 1 || $nameLen > 100) { - throw new \LengthException('Command name can be only 1 to 32 characters long.'); + if ($nameLen < 1) { + throw new \LengthException('Command name can not be empty.'); + } elseif ($nameLen > 100) { + throw new \LengthException('Command name can be only up to 32 characters long.'); } $this->name = $name; @@ -86,8 +88,10 @@ public function setNameLocalization(string $locale, ?string $name): self { if (isset($name)) { $nameLen = poly_strlen($name); - if ($nameLen < 1 || $nameLen > 100) { - throw new \LengthException('Command name can be only 1 to 32 characters long.'); + if ($nameLen < 1) { + throw new \LengthException('Command name can not be empty.'); + } elseif ($nameLen > 100) { + throw new \LengthException('Command name can be only up to 32 characters long.'); } } @@ -108,8 +112,10 @@ public function setNameLocalization(string $locale, ?string $name): self public function setDescription(string $description): self { $descriptionLen = poly_strlen($description); - if ($descriptionLen < 1 || $descriptionLen > 100) { - throw new \LengthException('Command Description can be only 1 to 100 characters long.'); + if ($descriptionLen < 1) { + throw new \LengthException('Command description can not be empty.'); + } elseif ($descriptionLen > 100) { + throw new \LengthException('Command description can be only up to 100 characters long.'); } $this->description = $description; @@ -202,8 +208,6 @@ public function removeOption(Option $option): self /** * Clear all options from the command. * - * @throws \DomainException - * * @return $this */ public function clearOptions(): self From 6dbd207e046c8921884bd18c3215dc60e2633afa Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:56:13 +0700 Subject: [PATCH 5/7] forum startthread --- src/Discord/Parts/Channel/Channel.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index 36967b45f..cd1745c9c 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -768,9 +768,9 @@ protected function setPermissionOverwritesAttribute(array $overwrites): void * * @see https://discord.com/developers/docs/resources/channel#start-thread-without-message * - * @param string $name the name of the thread. - * @param bool $private whether the thread should be private. cannot start a private thread in a news channel. - * @param int $auto_archive_duration number of minutes of inactivity until the thread is auto-archived. one of 60, 1440, 4320, 10080. + * @param string $name The name of the thread. + * @param bool $private Whether the thread should be private. cannot start a private thread in a news channel or forum channel. + * @param int $auto_archive_duration Number of minutes of inactivity until the thread is auto-archived. one of 60, 1440, 4320, 10080. * @param string|null $reason Reason for Audit Log. * * @throws \RuntimeException @@ -792,6 +792,8 @@ public function startThread(string $name, bool $private = false, int $auto_archi $type = Channel::TYPE_NEWS_THREAD; } elseif ($this->type == Channel::TYPE_TEXT) { $type = $private ? Channel::TYPE_PRIVATE_THREAD : Channel::TYPE_PUBLIC_THREAD; + } elseif ($this->type == Channel::TYPE_FORUM) { + $type = Channel::TYPE_PUBLIC_THREAD; } else { return reject(new \RuntimeException('You cannot start a thread in this type of channel.')); } @@ -1066,7 +1068,7 @@ public function allowVoice() */ public function allowInvite() { - return in_array($this->type, [self::TYPE_TEXT, self::TYPE_VOICE, self::TYPE_NEWS, self::TYPE_STAGE_CHANNEL]); + return in_array($this->type, [self::TYPE_TEXT, self::TYPE_VOICE, self::TYPE_NEWS, self::TYPE_STAGE_CHANNEL, self::TYPE_FORUM]); } /** From a5bd258d9d91044cc630b80d799e86d56c25d7f4 Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Fri, 8 Apr 2022 21:03:41 +0700 Subject: [PATCH 6/7] message flags --- src/Discord/Builders/MessageBuilder.php | 20 +++++++++++++++++-- src/Discord/Parts/Channel/Message.php | 7 +++++-- .../Parts/Interactions/Interaction.php | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Discord/Builders/MessageBuilder.php b/src/Discord/Builders/MessageBuilder.php index ffa263c22..f060333c3 100644 --- a/src/Discord/Builders/MessageBuilder.php +++ b/src/Discord/Builders/MessageBuilder.php @@ -474,19 +474,35 @@ public function getStickers(): array /** * Sets the flags of the message. * - * @internal You cannot set flags except for when sending webhooks. Use the APIs given. + * @internal You cannot set flags except for when sending webhooks or interaction. Use the APIs given. * * @param int $flags * * @return $this */ - public function _setFlags(int $flags): self + public function setFlags(int $flags): self { $this->flags = $flags; return $this; } + /** + * Alias for old setFlags() + * + * @deprecated 7.1.0 Use setFlags() instead + * + * @internal You cannot set flags except for when sending webhooks or interaction. Use the APIs given. + * + * @param int $flags + * + * @return $this + */ + public function _setFlags(int $flags): self + { + return $this->setFlags($flags); + } + /** * Returns a boolean that determines whether the message needs to * be sent via multipart request, i.e. contains files. diff --git a/src/Discord/Parts/Channel/Message.php b/src/Discord/Parts/Channel/Message.php index 86f47d91c..c18155d86 100644 --- a/src/Discord/Parts/Channel/Message.php +++ b/src/Discord/Parts/Channel/Message.php @@ -118,6 +118,9 @@ class Message extends Part public const REACT_DELETE_ID = 2; public const REACT_DELETE_EMOJI = 3; + public const FLAG_SUPPRESS_EMBED = (1 << 2); + public const FLAG_EPHEMERAL = (1 << 6); + /** * @inheritdoc */ @@ -188,7 +191,7 @@ protected function getIsCrosspostAttribute(): bool */ protected function getSuppressEmbedsAttribute(): bool { - return (bool) ($this->flags & (1 << 2)); + return (bool) ($this->flags & self::FLAG_SUPPRESS_EMBED); } /** @@ -228,7 +231,7 @@ protected function getHasThreadAttribute(): bool */ protected function getEphemeralAttribute(): bool { - return (bool) ($this->flags & (1 << 6)); + return (bool) ($this->flags & self::FLAG_EPHEMERAL); } /** diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index 306c8fcac..81705021c 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -349,7 +349,7 @@ public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = f } if ($ephemeral) { - $builder->_setFlags(64); + $builder->setFlags(Message::FLAG_EPHEMERAL); } return (function () use ($builder): ExtendedPromiseInterface { @@ -384,7 +384,7 @@ public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = fa } if ($ephemeral) { - $builder->_setFlags(64); + $builder->setFlags(Message::FLAG_EPHEMERAL); } return $this->respond([ From 2f2377c0a4f79ca6128f89a0bdfd5ed79c01aea6 Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Fri, 8 Apr 2022 23:11:57 +0700 Subject: [PATCH 7/7] fix wrong length, revert setflags internal --- src/Discord/Builders/CommandAttributes.php | 4 ++-- src/Discord/Builders/MessageBuilder.php | 18 +----------------- src/Discord/Parts/Interactions/Interaction.php | 4 ++-- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/Discord/Builders/CommandAttributes.php b/src/Discord/Builders/CommandAttributes.php index 01cc8e567..1954b57dc 100644 --- a/src/Discord/Builders/CommandAttributes.php +++ b/src/Discord/Builders/CommandAttributes.php @@ -65,7 +65,7 @@ public function setName(string $name): self $nameLen = poly_strlen($name); if ($nameLen < 1) { throw new \LengthException('Command name can not be empty.'); - } elseif ($nameLen > 100) { + } elseif ($nameLen > 32) { throw new \LengthException('Command name can be only up to 32 characters long.'); } @@ -90,7 +90,7 @@ public function setNameLocalization(string $locale, ?string $name): self $nameLen = poly_strlen($name); if ($nameLen < 1) { throw new \LengthException('Command name can not be empty.'); - } elseif ($nameLen > 100) { + } elseif ($nameLen > 32) { throw new \LengthException('Command name can be only up to 32 characters long.'); } } diff --git a/src/Discord/Builders/MessageBuilder.php b/src/Discord/Builders/MessageBuilder.php index f060333c3..fafc36f58 100644 --- a/src/Discord/Builders/MessageBuilder.php +++ b/src/Discord/Builders/MessageBuilder.php @@ -480,29 +480,13 @@ public function getStickers(): array * * @return $this */ - public function setFlags(int $flags): self + public function _setFlags(int $flags): self { $this->flags = $flags; return $this; } - /** - * Alias for old setFlags() - * - * @deprecated 7.1.0 Use setFlags() instead - * - * @internal You cannot set flags except for when sending webhooks or interaction. Use the APIs given. - * - * @param int $flags - * - * @return $this - */ - public function _setFlags(int $flags): self - { - return $this->setFlags($flags); - } - /** * Returns a boolean that determines whether the message needs to * be sent via multipart request, i.e. contains files. diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index 81705021c..b726fae6f 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -349,7 +349,7 @@ public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = f } if ($ephemeral) { - $builder->setFlags(Message::FLAG_EPHEMERAL); + $builder->_setFlags(Message::FLAG_EPHEMERAL); } return (function () use ($builder): ExtendedPromiseInterface { @@ -384,7 +384,7 @@ public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = fa } if ($ephemeral) { - $builder->setFlags(Message::FLAG_EPHEMERAL); + $builder->_setFlags(Message::FLAG_EPHEMERAL); } return $this->respond([