From 44f71909b7c100576d7106b6fcb86e4559b2bae8 Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Sun, 13 Aug 2023 14:03:46 +0700 Subject: [PATCH 1/2] test: fix embed message test change with collection discriminator --- tests/Parts/Channel/Message/EmbedMessageTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Parts/Channel/Message/EmbedMessageTest.php b/tests/Parts/Channel/Message/EmbedMessageTest.php index 7e03bfb72..d11f0e9ea 100644 --- a/tests/Parts/Channel/Message/EmbedMessageTest.php +++ b/tests/Parts/Channel/Message/EmbedMessageTest.php @@ -63,12 +63,12 @@ public function testCanSendEmbed() $this->assertEquals('Footer Value', $embed->footer->text); $this->assertEquals(2, $embed->fields->count()); - $this->assertNotFalse(isset($embed->fields['Field 1'])); - $this->assertNotFalse(isset($embed->fields['Field 2'])); + $this->assertNotNull($embed->fields->get('name', 'Field 1')); + $this->assertNotNull($embed->fields->get('name', 'Field 2')); $this->assertNotEquals( - (string) $embed->fields['Field 1'], - (string) $embed->fields['Field 2'] + (string) $embed->fields->get('name', 'Field 1'), + (string) $embed->fields->get('name', 'Field 2') ); }) ->done($resolve, $resolve); From 0462d49fd6b2794d55dcbcdfb834bfdbb311c4ac Mon Sep 17 00:00:00 2001 From: SQKo <87897282+SQKo@users.noreply.github.com> Date: Sun, 13 Aug 2023 14:11:23 +0700 Subject: [PATCH 2/2] ran php cs-fixer --- src/Discord/CommandClient/Command.php | 6 +++--- src/Discord/Discord.php | 2 +- src/Discord/DiscordCommandClient.php | 12 ++++++------ src/Discord/Parts/Channel/Channel.php | 4 ++-- src/Discord/Parts/Embed/Embed.php | 14 ++++++-------- src/Discord/Parts/Guild/AutoModeration/Action.php | 2 +- src/Discord/Parts/Interactions/Interaction.php | 12 +++++------- src/Discord/Parts/Permissions/Permission.php | 2 +- src/Discord/Parts/Thread/Thread.php | 5 ++--- src/Discord/Parts/User/Member.php | 8 ++++---- src/Discord/WebSockets/Event.php | 2 +- src/Discord/WebSockets/Events/GuildCreate.php | 6 ++++-- src/Discord/WebSockets/Intents.php | 2 +- src/Discord/functions.php | 2 +- tests/FunctionsTest.php | 2 +- 15 files changed, 39 insertions(+), 42 deletions(-) diff --git a/src/Discord/CommandClient/Command.php b/src/Discord/CommandClient/Command.php index 489c180fa..1e9cd6c62 100644 --- a/src/Discord/CommandClient/Command.php +++ b/src/Discord/CommandClient/Command.php @@ -158,9 +158,9 @@ public function getCommand(string $command, bool $aliases = true): ?Command /** * Registers a new command. * - * @param string $command The command name. - * @param callable|string $callable The function called when the command is executed. - * @param array $options An array of options. + * @param string $command The command name. + * @param callable|string $callable The function called when the command is executed. + * @param array $options An array of options. * * @return Command The command instance. * @throws \Exception diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index 8366a2465..6f23ed901 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -1136,7 +1136,7 @@ protected function ready() /* deprecated */ if ($this->listeners['ready']) { - if (count($this->listeners['ready'] ?? []) > 1 || count($this->onceListeners["ready"] ?? []) > 1) { + if (count($this->listeners['ready'] ?? []) > 1 || count($this->onceListeners['ready'] ?? []) > 1) { $this->logger->info('The \'ready\' event is deprecated and will be removed in a future version of DiscordPHP. Please use \'init\' instead.'); } diff --git a/src/Discord/DiscordCommandClient.php b/src/Discord/DiscordCommandClient.php index f02aa0bf3..59e17b656 100644 --- a/src/Discord/DiscordCommandClient.php +++ b/src/Discord/DiscordCommandClient.php @@ -231,9 +231,9 @@ protected function checkForPrefix(string $content): ?string /** * Registers a new command. * - * @param string $command The command name. - * @param callable|string $callable The function called when the command is executed. - * @param array $options An array of options. + * @param string $command The command name. + * @param callable|string $callable The function called when the command is executed. + * @param array $options An array of options. * * @return Command The command instance. * @throws \Exception @@ -325,9 +325,9 @@ public function getCommand(string $command, bool $aliases = true): ?Command /** * Builds a command and returns it. * - * @param string $command The command name. - * @param callable|string $callable The function called when the command is executed. - * @param array $options An array of options. + * @param string $command The command name. + * @param callable|string $callable The function called when the command is executed. + * @param array $options An array of options. * * @return Command[]|array[] The command instance and options. */ diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index 5444d53e4..991b76b48 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -1194,7 +1194,7 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed $messagePart = $this->messages->create($response, true); } - return $messagePart; + return $messagePart; }); } @@ -1365,7 +1365,7 @@ public function isTextBased() self::TYPE_PUBLIC_THREAD, self::TYPE_PRIVATE_THREAD, self::TYPE_GUILD_ANNOUNCEMENT, - self::TYPE_GUILD_STAGE_VOICE + self::TYPE_GUILD_STAGE_VOICE, ]); } diff --git a/src/Discord/Parts/Embed/Embed.php b/src/Discord/Parts/Embed/Embed.php index e1341db3d..f1ce61be3 100644 --- a/src/Discord/Parts/Embed/Embed.php +++ b/src/Discord/Parts/Embed/Embed.php @@ -390,9 +390,9 @@ public function setAuthor(string $name, $iconurl = null, ?string $url = null): s /** * Set the footer of this embed. * - * @param string $text Maximum length is 2048 characters. - * @param string|Attachment|null $iconurl The URL to the icon, only http(s) and attachments URLs are allowed. - * + * @param string $text Maximum length is 2048 characters. + * @param string|Attachment|null $iconurl The URL to the icon, only http(s) and attachments URLs are allowed. + * * @throws \LengthException Embed text too long. * @throws \InvalidArgumentException Invalid scheme provided. * @@ -420,7 +420,6 @@ public function setFooter(string $text, $iconurl = null): self 'icon_url' => $iconurl, ]; - return $this; } @@ -430,7 +429,7 @@ public function setFooter(string $text, $iconurl = null): self * @param string|Attachment|null $url The URL to the image, only http(s) and attachments URLs are allowed. * * @throws \InvalidArgumentException Invalid scheme provided. - * + * * @return $this */ public function setImage($url): self @@ -452,7 +451,7 @@ public function setImage($url): self * @param string|Attachment|null $url The URL to the thumbnail, only http(s) and attachments URLs are allowed. * * @throws \InvalidArgumentException Invalid scheme provided. - * + * * @return $this */ public function setThumbnail($url): self @@ -503,11 +502,10 @@ public function setURL(string $url): self * * @param ?string $url * - * @return void * * @throws \DomainException */ - function ensureValidUrl(?string $url = null, array $allowed = ['http', 'https', 'attachment']) + protected function ensureValidUrl(?string $url = null, array $allowed = ['http', 'https', 'attachment']) { if (null !== $url && ! in_array(parse_url($url, PHP_URL_SCHEME), $allowed)) { throw new \DomainException('Url scheme only supports '.implode(', ', $allowed)); diff --git a/src/Discord/Parts/Guild/AutoModeration/Action.php b/src/Discord/Parts/Guild/AutoModeration/Action.php index 6139b0132..3fad0923c 100644 --- a/src/Discord/Parts/Guild/AutoModeration/Action.php +++ b/src/Discord/Parts/Guild/AutoModeration/Action.php @@ -38,7 +38,7 @@ class Action extends Part public const TYPE_TIMEOUT = 3; /** - * Get the Metadata Attributes + * Get the Metadata Attributes. * * @return ?ActionMetadata */ diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index 3e756e189..518ef917c 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -140,14 +140,12 @@ protected function getChannelAttribute(): ?Part if ( ! in_array($this->attributes['channel']->type ?? null, [Channel::TYPE_PUBLIC_THREAD, CHANNEL::TYPE_PRIVATE_THREAD, CHANNEL::TYPE_ANNOUNCEMENT_THREAD]) && $channel = $channels->get('id', $channelId) - ) - { + ) { return $channel; - } else { - foreach ($channels as $parent) { - if ($thread = $parent->threads->get('id', $channelId)) { - return $thread; - } + } + foreach ($channels as $parent) { + if ($thread = $parent->threads->get('id', $channelId)) { + return $thread; } } } diff --git a/src/Discord/Parts/Permissions/Permission.php b/src/Discord/Parts/Permissions/Permission.php index 3085fd8fb..7d80a7bdd 100644 --- a/src/Discord/Parts/Permissions/Permission.php +++ b/src/Discord/Parts/Permissions/Permission.php @@ -49,7 +49,7 @@ abstract class Permission extends Part /** * Array of permissions that only apply to text channels. * i.e. indicated T in documentation. - * + * * The constant values here are the bit position, not the bitwise value * * @see ChannelPermission diff --git a/src/Discord/Parts/Thread/Thread.php b/src/Discord/Parts/Thread/Thread.php index 92d7c08d8..0768f44bd 100644 --- a/src/Discord/Parts/Thread/Thread.php +++ b/src/Discord/Parts/Thread/Thread.php @@ -36,7 +36,6 @@ use function Discord\getSnowflakeTimestamp; use function React\Promise\all; use function React\Promise\reject; -use function React\Promise\resolve; /** * Represents a Discord thread. @@ -722,7 +721,7 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed return $this->http->post(Endpoint::bind(Endpoint::CHANNEL_MESSAGES, $this->id), $message); })()->then(function ($response) { - return $this->messages->get('id', $response->id) ?: $this->messages->create($response, true); + return $this->messages->get('id', $response->id) ?: $this->messages->create($response, true); }); } @@ -845,7 +844,7 @@ public function getCreatableAttributes(): array if ($this->type == Channel::TYPE_PRIVATE_THREAD) { $attr += $this->makeOptionalAttributes([ - 'invitable' => $this->invitable + 'invitable' => $this->invitable, ]); } diff --git a/src/Discord/Parts/User/Member.php b/src/Discord/Parts/User/Member.php index 6e5ac9dbe..460129e51 100644 --- a/src/Discord/Parts/User/Member.php +++ b/src/Discord/Parts/User/Member.php @@ -547,8 +547,8 @@ public function timeoutMember(?Carbon $communication_disabled_until, ?string $re /** * Sets verification bypasses flag on a member. * - * @param bool $bypasses_verification Whether member is exempt from guild verification requirements. - * @param string|null $reason Reason for Audit Log. + * @param bool $bypasses_verification Whether member is exempt from guild verification requirements. + * @param string|null $reason Reason for Audit Log. * * @throws NoPermissionsException Missing `moderate_members` permission. * @@ -576,7 +576,7 @@ public function setBypassesVerification(bool $bypasses_verification, ?string $re $flags &= ~self::FLAGS_BYPASSES_VERIFICATION; } - return $this->http->patch(Endpoint::bind(Endpoint::GUILD_MEMBER, $this->guild_id, $this->id), ['flags' => $flags ], $headers) + return $this->http->patch(Endpoint::bind(Endpoint::GUILD_MEMBER, $this->guild_id, $this->id), ['flags' => $flags], $headers) ->then(function ($response) { $this->attributes['flags'] = $response->flags; @@ -593,7 +593,7 @@ protected function getDisplaynameAttribute(): string { $user = $this->user; - return ($this->nick ?? $user->global_name ?? $user->username) . ($user->discriminator ? '#' . $user->discriminator : ''); + return ($this->nick ?? $user->global_name ?? $user->username).($user->discriminator ? '#'.$user->discriminator : ''); } /** diff --git a/src/Discord/WebSockets/Event.php b/src/Discord/WebSockets/Event.php index 838e6ea05..4c2967b5a 100644 --- a/src/Discord/WebSockets/Event.php +++ b/src/Discord/WebSockets/Event.php @@ -78,7 +78,7 @@ abstract class Event public const AUTO_MODERATION_RULE_DELETE = 'AUTO_MODERATION_RULE_DELETE'; public const AUTO_MODERATION_ACTION_EXECUTION = 'AUTO_MODERATION_ACTION_EXECUTION'; - public const GUILD_AUDIT_LOG_ENTRY_CREATE ='GUILD_AUDIT_LOG_ENTRY_CREATE'; + public const GUILD_AUDIT_LOG_ENTRY_CREATE = 'GUILD_AUDIT_LOG_ENTRY_CREATE'; // Channel public const CHANNEL_CREATE = 'CHANNEL_CREATE'; diff --git a/src/Discord/WebSockets/Events/GuildCreate.php b/src/Discord/WebSockets/Events/GuildCreate.php index a6e0779d2..715039870 100644 --- a/src/Discord/WebSockets/Events/GuildCreate.php +++ b/src/Discord/WebSockets/Events/GuildCreate.php @@ -106,8 +106,10 @@ public function handle($data) }); if ( - ($this->discord->options['retrieveBans'] === true - || (is_array($this->discord->options['retrieveBans']) + ( + $this->discord->options['retrieveBans'] === true + || ( + is_array($this->discord->options['retrieveBans']) && in_array($data->id, $this->discord->options['retrieveBans']) ) ) diff --git a/src/Discord/WebSockets/Intents.php b/src/Discord/WebSockets/Intents.php index c1f1cc6b7..9b766e0d7 100644 --- a/src/Discord/WebSockets/Intents.php +++ b/src/Discord/WebSockets/Intents.php @@ -52,7 +52,7 @@ class Intents * Guild moderation events. * - GUILD_AUDIT_LOG_ENTRY_CREATE * - GUILD_BAN_ADD - * - GUILD_BAN_REMOVE + * - GUILD_BAN_REMOVE. */ public const GUILD_MODERATION = (1 << 2); diff --git a/src/Discord/functions.php b/src/Discord/functions.php index 3e0298f30..826fb10ca 100644 --- a/src/Discord/functions.php +++ b/src/Discord/functions.php @@ -356,7 +356,7 @@ function nowait(PromiseInterface $promiseInterface) } /** - * File namespaces that were changed in new versions are aliased + * File namespaces that were changed in new versions are aliased. */ class_alias(\Discord\Repository\Channel\StageInstanceRepository::class, '\Discord\Repository\Guild\StageInstanceRepository'); // @since 10.0.0 class_alias(\Discord\Parts\Guild\CommandPermissions::class, '\Discord\Parts\Interactions\Command\Overwrite'); // @since 10.0.0 diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 2fe75131e..e5734fe5d 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -176,7 +176,7 @@ public function testNormalizePartId($part, $expected): void $expected, (normalizePartId())( new OptionsResolver(), - $part + $part ) ); }