From 0781c3587c8f05a3513f0345d4ebea76682984f0 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Sun, 16 Jul 2023 23:20:00 +0200 Subject: [PATCH 01/19] Promise v3 changes - changed ExtendedPromiseInterface to PromiseInterface - replaced Discord\Helpers\Deferred with React\Promise\Deferred - changed ->done(true function, false function) with ->then(true function)->catch(false function) - changed ->always() to ->finally() - added use React\Promise\Deferred where I think it was missing - updated $deferred->resolve() to $deferred->resolve(true) - updated $deferred->reject() to $deferred->reject(throwable) --- src/Discord/Discord.php | 49 +++++----- src/Discord/Helpers/Buffer.php | 15 ++-- src/Discord/Helpers/Deferred.php | 28 ------ .../Helpers/ExtendedPromisorInterface.php | 30 ------- src/Discord/Parts/Channel/Channel.php | 82 ++++++++--------- src/Discord/Parts/Channel/Message.php | 52 +++++------ src/Discord/Parts/Channel/Reaction.php | 12 +-- src/Discord/Parts/Channel/Webhook.php | 10 +-- src/Discord/Parts/Guild/Guild.php | 90 +++++++++---------- src/Discord/Parts/Guild/GuildTemplate.php | 6 +- src/Discord/Parts/Guild/ScheduledEvent.php | 6 +- src/Discord/Parts/Guild/Widget.php | 4 +- .../Parts/Interactions/Interaction.php | 62 ++++++------- src/Discord/Parts/Part.php | 6 +- src/Discord/Parts/Thread/Member.php | 6 +- src/Discord/Parts/Thread/Thread.php | 74 +++++++-------- src/Discord/Parts/User/Client.php | 8 +- src/Discord/Parts/User/Member.php | 40 ++++----- src/Discord/Parts/User/User.php | 16 ++-- .../Parts/WebSockets/MessageReaction.php | 8 +- src/Discord/Repository/AbstractRepository.php | 34 +++---- .../Repository/Channel/ReactionRepository.php | 6 +- .../Repository/Channel/ThreadRepository.php | 12 +-- .../Repository/Guild/BanRepository.php | 10 +-- .../Guild/GuildTemplateRepository.php | 6 +- .../Repository/Guild/MemberRepository.php | 10 +-- .../Guild/ScheduledEventRepository.php | 6 +- src/Discord/Repository/GuildRepository.php | 6 +- src/Discord/Voice/OggPage.php | 6 +- src/Discord/Voice/OggStream.php | 14 +-- src/Discord/Voice/VoiceClient.php | 39 ++++---- src/Discord/WebSockets/Events/GuildCreate.php | 8 +- src/Discord/functions.php | 4 +- 33 files changed, 351 insertions(+), 414 deletions(-) delete mode 100644 src/Discord/Helpers/Deferred.php delete mode 100644 src/Discord/Helpers/ExtendedPromisorInterface.php diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index e38f6e599..2fafd2cbb 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -42,7 +42,6 @@ use React\EventLoop\Factory as LoopFactory; use React\EventLoop\LoopInterface; use React\EventLoop\TimerInterface; -use Discord\Helpers\Deferred; use Discord\Helpers\RegisteredCommand; use Discord\Http\Drivers\React; use Discord\Http\Endpoint; @@ -50,7 +49,8 @@ use Monolog\Formatter\LineFormatter; use Psr\Log\LoggerInterface; use React\Cache\ArrayCache; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\Deferred; +use React\Promise\PromiseInterface; use React\Promise\PromiseInterface; use React\Socket\Connector as SocketConnector; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -470,10 +470,10 @@ protected function handleReady(object $data) $unavailable = []; foreach ($content->guilds as $guild) { - /** @var ExtendedPromiseInterface */ + /** @var PromiseInterface */ $promise = coroutine([$event, 'handle'], $guild); - $promise->done(function ($d) use (&$unavailable) { + $promise->then(function ($d) use (&$unavailable) { if (! empty($d->unavailable)) { $unavailable[$d->id] = $d->unavailable; } @@ -499,7 +499,7 @@ protected function handleReady(object $data) unset($unavailable[$guild->id]); } if (count($unavailable) < 1) { - $guildLoad->resolve(); + $guildLoad->resolve(true); } }; $this->on(Event::GUILD_CREATE, $onGuildCreate); @@ -510,18 +510,18 @@ protected function handleReady(object $data) unset($unavailable[$guild->id]); } if (count($unavailable) < 1) { - $guildLoad->resolve(); + $guildLoad->resolve(true); } }; $this->on(Event::GUILD_DELETE, $onGuildDelete); - $guildLoad->promise()->always(function () use ($onGuildCreate, $onGuildDelete) { + $guildLoad->promise()->finally(function () use ($onGuildCreate, $onGuildDelete) { $this->removeListener(Event::GUILD_CREATE, $onGuildCreate); $this->removeListener(Event::GUILD_DELETE, $onGuildDelete); $this->logger->info('all guilds are now available', ['count' => $this->guilds->count()]); $this->setupChunking(); - })->done(); + }); } /** @@ -773,7 +773,7 @@ protected function handleDispatch(object $data): void $handler = new $hData['class']($this); $deferred = new Deferred(); - $deferred->promise()->done(function ($d) use ($data, $hData) { + $deferred->promise()->then(function ($d) use ($data, $hData) { if (is_array($d) && count($d) == 2) { list($new, $old) = $d; } else { @@ -790,7 +790,7 @@ protected function handleDispatch(object $data): void if ($data->t == Event::MESSAGE_CREATE && mentioned($this->client->user, $new)) { $this->emit('mention', [$new, $this, $old]); } - }, function ($e) use ($data) { + })->catch(function ($e) use ($data) { if ($e instanceof \Error) { throw $e; } elseif ($e instanceof \Exception) { @@ -807,14 +807,14 @@ protected function handleDispatch(object $data): void if (! $this->emittedInit && (! in_array($data->t, $parse))) { $this->unparsedPackets[] = function () use (&$handler, &$deferred, &$data) { - /** @var ExtendedPromiseInterface */ + /** @var PromiseInterface */ $promise = coroutine([$handler, 'handle'], $data->d); - $promise->done([$deferred, 'resolve'], [$deferred, 'reject']); + $promise->then([$deferred, 'resolve'])->catch([$deferred, 'reject']); }; } else { - /** @var ExtendedPromiseInterface */ + /** @var PromiseInterface */ $promise = coroutine([$handler, 'handle'], $data->d); - $promise->done([$deferred, 'resolve'], [$deferred, 'reject']); + $promise->then([$deferred, 'resolve'])->catch([$deferred, 'reject']); } } @@ -1077,7 +1077,7 @@ protected function setupHeartbeat(int $interval): void */ protected function connectWs(): void { - $this->setGateway()->done(function ($gateway) { + $this->setGateway()->then(function ($gateway) { if (isset($gateway['session']) && $session = $gateway['session']) { if ($session['remaining'] < 2) { $this->logger->error('exceeded number of reconnects allowed, waiting before attempting reconnect', $session); @@ -1091,12 +1091,9 @@ protected function connectWs(): void $this->logger->info('starting connection to websocket', ['gateway' => $this->gateway]); - /** @var ExtendedPromiseInterface */ + /** @var PromiseInterface */ $promise = ($this->wsFactory)($this->gateway); - $promise->done( - [$this, 'handleWsConnection'], - [$this, 'handleWsConnectionFailed'] - ); + $promise->then([$this, 'handleWsConnection'])->catch([$this, 'handleWsConnectionFailed']); }); } @@ -1219,7 +1216,7 @@ public function getVoiceClient(string $guild_id): ?VoiceClient * * @return PromiseInterface */ - public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, ?LoggerInterface $logger = null, bool $check = true): ExtendedPromiseInterface + public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, ?LoggerInterface $logger = null, bool $check = true): PromiseInterface { $deferred = new Deferred(); @@ -1313,9 +1310,9 @@ public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, * * @param string|null $gateway Gateway URL to set. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - protected function setGateway(?string $gateway = null): ExtendedPromiseInterface + protected function setGateway(?string $gateway = null): PromiseInterface { $deferred = new Deferred(); $defaultSession = [ @@ -1343,12 +1340,12 @@ protected function setGateway(?string $gateway = null): ExtendedPromiseInterface }; if (null === $gateway) { - $this->http->get(Endpoint::GATEWAY_BOT)->done(function ($response) use ($buildParams) { + $this->http->get(Endpoint::GATEWAY_BOT)->then(function ($response) use ($buildParams) { if ($response->shards > 1) { $this->logger->info('Please contact the DiscordPHP devs at https://discord.gg/dphp or https://github.com/discord-php/DiscordPHP/issues if you are interrested in assisting us with sharding support development.'); } $buildParams($this->resume_gateway_url ?? $response->url, $response->session_start_limit); - }, function ($e) use ($buildParams) { + })->catch(function ($e) use ($buildParams) { // Can't access the API server so we will use the default gateway. $this->logger->warning('could not retrieve gateway, using default'); $buildParams('wss://gateway.discord.gg'); @@ -1359,7 +1356,7 @@ protected function setGateway(?string $gateway = null): ExtendedPromiseInterface $deferred->promise()->then(function ($gateway) { $this->logger->info('gateway retrieved and set', $gateway); - }, function ($e) { + })->catch(function ($e) { $this->logger->error('error obtaining gateway', ['e' => $e->getMessage()]); }); diff --git a/src/Discord/Helpers/Buffer.php b/src/Discord/Helpers/Buffer.php index e4a28e8f6..71fff963e 100644 --- a/src/Discord/Helpers/Buffer.php +++ b/src/Discord/Helpers/Buffer.php @@ -14,7 +14,8 @@ use Discord\Exceptions\BufferTimedOutException; use Evenement\EventEmitter; use React\EventLoop\LoopInterface; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\Deferred; +use React\Promise\PromiseInterface; use React\Stream\WritableStreamInterface; /** @@ -106,11 +107,11 @@ private function readRaw(int $length) * @param null|string $format Format to read the bytes in. See `pack()`. * @param int $timeout Time in milliseconds before the read times out. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function read(int $length, ?string $format = null, ?int $timeout = -1): ExtendedPromiseInterface + public function read(int $length, ?string $format = null, ?int $timeout = -1): PromiseInterface { $deferred = new Deferred(); @@ -152,11 +153,11 @@ public function read(int $length, ?string $format = null, ?int $timeout = -1): E * * @param int $timeout Time in milliseconds before the read times out. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function readInt32(int $timeout = -1): ExtendedPromiseInterface + public function readInt32(int $timeout = -1): PromiseInterface { return $this->read(4, 'l', $timeout); } @@ -166,11 +167,11 @@ public function readInt32(int $timeout = -1): ExtendedPromiseInterface * * @param int $timeout Time in milliseconds before the read times out. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function readInt16(int $timeout = -1): ExtendedPromiseInterface + public function readInt16(int $timeout = -1): PromiseInterface { return $this->read(2, 'v', $timeout); } diff --git a/src/Discord/Helpers/Deferred.php b/src/Discord/Helpers/Deferred.php deleted file mode 100644 index 41b84115a..000000000 --- a/src/Discord/Helpers/Deferred.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * This file is subject to the MIT license that is bundled - * with this source code in the LICENSE.md file. - */ - -namespace Discord\Helpers; - -use React\Promise\Deferred as ReactDeferred; -use React\Promise\ExtendedPromiseInterface; - -/** - * Wrapper for extended promisor interface. Work-around until react/promise v3.0. - * - * @since 5.0.12 - */ -class Deferred extends ReactDeferred implements ExtendedPromisorInterface -{ - public function promise(): ExtendedPromiseInterface - { - return parent::promise(); - } -} diff --git a/src/Discord/Helpers/ExtendedPromisorInterface.php b/src/Discord/Helpers/ExtendedPromisorInterface.php deleted file mode 100644 index 8bca1c97a..000000000 --- a/src/Discord/Helpers/ExtendedPromisorInterface.php +++ /dev/null @@ -1,30 +0,0 @@ - - * - * This file is subject to the MIT license that is bundled - * with this source code in the LICENSE.md file. - */ - -namespace Discord\Helpers; - -use React\Promise\ExtendedPromiseInterface; - -/** - * Expands on the react/promise PromisorInterface by returning an extended - * promise. - * - * @since 5.0.12 - */ -interface ExtendedPromisorInterface -{ - /** - * Returns the promise of the deferred. - * - * @return ExtendedPromiseInterface - */ - public function promise(): ExtendedPromiseInterface; -} diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index a332ac85a..77460291e 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -27,7 +27,6 @@ use Discord\Repository\Channel\VoiceMemberRepository as MemberRepository; use Discord\Repository\Channel\WebhookRepository; use Discord\WebSockets\Event; -use Discord\Helpers\Deferred; use Discord\Helpers\Multipart; use Discord\Http\Endpoint; use Discord\Http\Exceptions\NoPermissionsException; @@ -38,7 +37,8 @@ use Discord\Repository\Channel\InviteRepository; use Discord\Repository\Channel\StageInstanceRepository; use Discord\Repository\Channel\ThreadRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\Deferred; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Traversable; @@ -97,7 +97,7 @@ * @property InviteRepository $invites Invites in the channel. * @property StageInstanceRepository $stage_instances Stage instances in the channel. * - * @method ExtendedPromiseInterface sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class Channel extends Part { @@ -293,9 +293,9 @@ protected function getLastPinTimestampAttribute(): ?Carbon * * @link https://discord.com/developers/docs/resources/channel#get-pinned-messages * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> */ - public function getPinnedMessages(): ExtendedPromiseInterface + public function getPinnedMessages(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_PINS, $this->id)) ->then(function ($responses) { @@ -321,9 +321,9 @@ public function getPinnedMessages(): ExtendedPromiseInterface * * @throws InvalidOverwriteException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function setPermissions(Part $part, array $allow = [], array $deny = [], ?string $reason = null): ExtendedPromiseInterface + public function setPermissions(Part $part, array $allow = [], array $deny = [], ?string $reason = null): PromiseInterface { if ($part instanceof Member) { $type = Overwrite::TYPE_MEMBER; @@ -362,9 +362,9 @@ public function setPermissions(Part $part, array $allow = [], array $deny = [], * @throws NoPermissionsException Missing manage_roles permission. * @throws InvalidOverwriteException Overwrite type is not member or role. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = null): ExtendedPromiseInterface + public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = null): PromiseInterface { if ($this->guild_id && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_roles) { @@ -408,13 +408,13 @@ public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = * @param int|null $position The new channel position, not relative to category. * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \RuntimeException * @throws \InvalidArgumentException * @throws NoPermissionsException Missing manage_channels permission in either channel. */ - public function setCategory($category, ?int $position = null, ?string $reason = null): ExtendedPromiseInterface + public function setCategory($category, ?int $position = null, ?string $reason = null): PromiseInterface { if (! in_array($this->type, [self::TYPE_GUILD_TEXT, self::TYPE_GUILD_VOICE, self::TYPE_GUILD_ANNOUNCEMENT, self::TYPE_GUILD_FORUM])) { return reject(new \RuntimeException('You can only move Text, Voice, Announcement or Forum channel type.')); @@ -472,9 +472,9 @@ public function setCategory($category, ?int $position = null, ?string $reason = * @throws \RuntimeException * @throws NoPermissionsException Missing move_members permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function moveMember($member, ?string $reason = null): ExtendedPromiseInterface + public function moveMember($member, ?string $reason = null): PromiseInterface { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot move a member in a text channel.')); @@ -507,9 +507,9 @@ public function moveMember($member, ?string $reason = null): ExtendedPromiseInte * @throws \RuntimeException * @throws NoPermissionsException Missing mute_members permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function muteMember($member, ?string $reason = null): ExtendedPromiseInterface + public function muteMember($member, ?string $reason = null): PromiseInterface { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot mute a member in a text channel.')); @@ -542,9 +542,9 @@ public function muteMember($member, ?string $reason = null): ExtendedPromiseInte * @throws \RuntimeException * @throws NoPermissionsException Missing mute_members permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function unmuteMember($member, ?string $reason = null): ExtendedPromiseInterface + public function unmuteMember($member, ?string $reason = null): PromiseInterface { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot unmute a member in a text channel.')); @@ -585,9 +585,9 @@ public function unmuteMember($member, ?string $reason = null): ExtendedPromiseIn * * @throws NoPermissionsException Missing create_instant_invite permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function createInvite($options = [], ?string $reason = null): ExtendedPromiseInterface + public function createInvite($options = [], ?string $reason = null): PromiseInterface { if (! $this->canInvite()) { return reject(new \RuntimeException('You cannot create invite in this type of channel.')); @@ -651,9 +651,9 @@ public function createInvite($options = [], ?string $reason = null): ExtendedPro * @throws \InvalidArgumentException * @throws NoPermissionsException Missing manage_messages permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function deleteMessages($messages, ?string $reason = null): ExtendedPromiseInterface + public function deleteMessages($messages, ?string $reason = null): PromiseInterface { if (! is_array($messages) && ! ($messages instanceof Traversable)) { return reject(new \InvalidArgumentException('$messages must be an array or implement Traversable.')); @@ -706,9 +706,9 @@ public function deleteMessages($messages, ?string $reason = null): ExtendedPromi * * @throws NoPermissionsException Missing manage_messages permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function limitDelete(int $value, ?string $reason = null): ExtendedPromiseInterface + public function limitDelete(int $value, ?string $reason = null): PromiseInterface { if ($botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -732,9 +732,9 @@ public function limitDelete(int $value, ?string $reason = null): ExtendedPromise * Or also missing `connect` permission for text in voice. * @throws \RangeException * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> */ - public function getMessageHistory(array $options): ExtendedPromiseInterface + public function getMessageHistory(array $options): PromiseInterface { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->read_message_history) { @@ -796,9 +796,9 @@ public function getMessageHistory(array $options): ExtendedPromiseInterface * @throws NoPermissionsException Missing manage_messages permission. * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function pinMessage(Message $message, ?string $reason = null): ExtendedPromiseInterface + public function pinMessage(Message $message, ?string $reason = null): PromiseInterface { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -837,9 +837,9 @@ public function pinMessage(Message $message, ?string $reason = null): ExtendedPr * @throws NoPermissionsException Missing manage_messages permission. * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function unpinMessage(Message $message, ?string $reason = null): ExtendedPromiseInterface + public function unpinMessage(Message $message, ?string $reason = null): PromiseInterface { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -967,11 +967,11 @@ protected function getDefaultReactionEmojiAttribute(): ?Reaction * create_public_threads when creating a public thread. * send_messages when creating a forum post. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @since 10.0.0 Arguments for `$name`, `$private` and `$auto_archive_duration` are now inside `$options` */ - public function startThread(array|string $options, string|null|bool $reason = null, int $_auto_archive_duration = 1440, ?string $_reason = null): ExtendedPromiseInterface + public function startThread(array|string $options, string|null|bool $reason = null, int $_auto_archive_duration = 1440, ?string $_reason = null): PromiseInterface { // Old v7 signature if (is_string($options)) { @@ -1124,9 +1124,9 @@ public function startThread(array|string $options, string|null|bool $reason = nu * @throws \RuntimeException * @throws NoPermissionsException Missing various permissions depending on the message body. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): ExtendedPromiseInterface + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface { // Backwards compatible support for old `sendMessage` function signature. if (! ($message instanceof MessageBuilder)) { @@ -1190,9 +1190,9 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @param Embed $embed Embed to send. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function sendEmbed(Embed $embed): ExtendedPromiseInterface + public function sendEmbed(Embed $embed): PromiseInterface { return $this->sendMessage(MessageBuilder::new() ->addEmbed($embed)); @@ -1210,9 +1210,9 @@ public function sendEmbed(Embed $embed): ExtendedPromiseInterface * @param string|null $content Message content to send with the file. * @param bool $tts Whether to send the message with TTS. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function sendFile(string $filepath, ?string $filename = null, ?string $content = null, bool $tts = false): ExtendedPromiseInterface + public function sendFile(string $filepath, ?string $filename = null, ?string $content = null, bool $tts = false): PromiseInterface { $builder = MessageBuilder::new() ->setTts($tts) @@ -1232,9 +1232,9 @@ public function sendFile(string $filepath, ?string $filename = null, ?string $co * * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function broadcastTyping(): ExtendedPromiseInterface + public function broadcastTyping(): PromiseInterface { if (! $this->isTextBased()) { return reject(new \RuntimeException('You cannot broadcast typing to a voice channel.')); @@ -1251,9 +1251,9 @@ public function broadcastTyping(): ExtendedPromiseInterface * @param int $options['time'] Time in milliseconds until the collector finishes or false. * @param int $options['limit'] The amount of messages allowed or false. * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> */ - public function createMessageCollector(callable $filter, array $options = []): ExtendedPromiseInterface + public function createMessageCollector(callable $filter, array $options = []): PromiseInterface { $deferred = new Deferred(); $messages = new Collection([], null, null); diff --git a/src/Discord/Parts/Channel/Message.php b/src/Discord/Parts/Channel/Message.php index b0af43f7e..f3f92e665 100644 --- a/src/Discord/Parts/Channel/Message.php +++ b/src/Discord/Parts/Channel/Message.php @@ -22,7 +22,6 @@ use Discord\Parts\User\User; use Discord\Parts\WebSockets\MessageReaction; use Discord\WebSockets\Event; -use Discord\Helpers\Deferred; use Discord\Http\Endpoint; use Discord\Http\Exceptions\NoPermissionsException; use Discord\Parts\Guild\Guild; @@ -32,7 +31,8 @@ use Discord\Parts\WebSockets\MessageInteraction; use Discord\Repository\Channel\ReactionRepository; use React\EventLoop\TimerInterface; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\Deferred; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use function React\Promise\reject; @@ -739,11 +739,11 @@ public function getLinkAttribute(): ?string * @throws \RuntimeException Channel type is not guild text or news. * @throws NoPermissionsException Missing create_public_threads permission to create or manage_threads permission to set rate_limit_per_user. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @since 10.0.0 Arguments for `$name` and `$auto_archive_duration` are now inside `$options` */ - public function startThread(array|string $options, string|null|int $reason = null, ?string $_reason = null): ExtendedPromiseInterface + public function startThread(array|string $options, string|null|int $reason = null, ?string $_reason = null): PromiseInterface { // Old v7 signature if (is_string($options)) { @@ -819,9 +819,9 @@ public function startThread(array|string $options, string|null|int $reason = nul * * @param string|MessageBuilder $message The reply message. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function reply($message): ExtendedPromiseInterface + public function reply($message): PromiseInterface { $channel = $this->channel; @@ -844,9 +844,9 @@ public function reply($message): ExtendedPromiseInterface * send_messages if this message author is the bot. * manage_messages if this message author is other user. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function crosspost(): ExtendedPromiseInterface + public function crosspost(): PromiseInterface { if ($this->crossposted) { return reject(new \RuntimeException('This message has already been crossposted.')); @@ -882,14 +882,14 @@ public function crosspost(): ExtendedPromiseInterface * @param int $delay Delay after text will be sent in milliseconds. * @param TimerInterface &$timer Delay timer passed by reference. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function delayedReply($message, int $delay, &$timer = null): ExtendedPromiseInterface + public function delayedReply($message, int $delay, &$timer = null): PromiseInterface { $deferred = new Deferred(); $timer = $this->discord->getLoop()->addTimer($delay / 1000, function () use ($message, $deferred) { - $this->reply($message)->done([$deferred, 'resolve'], [$deferred, 'reject']); + $this->reply($message)->then([$deferred, 'resolve'])->catch([$deferred, 'reject']); }); return $deferred->promise(); @@ -905,12 +905,12 @@ public function delayedReply($message, int $delay, &$timer = null): ExtendedProm * * @return ExtendedPromseInterface */ - public function delayedDelete(int $delay, &$timer = null): ExtendedPromiseInterface + public function delayedDelete(int $delay, &$timer = null): PromiseInterface { $deferred = new Deferred(); $timer = $this->discord->getLoop()->addTimer($delay / 1000, function () use ($deferred) { - $this->delete()->done([$deferred, 'resolve'], [$deferred, 'reject']); + $this->delete()->then([$deferred, 'resolve'])->catch([$deferred, 'reject']); }); return $deferred->promise(); @@ -925,9 +925,9 @@ public function delayedDelete(int $delay, &$timer = null): ExtendedPromiseInterf * * @throws NoPermissionsException Missing read_message_history permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function react($emoticon): ExtendedPromiseInterface + public function react($emoticon): PromiseInterface { if ($emoticon instanceof Emoji) { $emoticon = $emoticon->toReactionString(); @@ -956,9 +956,9 @@ public function react($emoticon): ExtendedPromiseInterface * @throws \UnexpectedValueException Invalid reaction `$type`. * @throws NoPermissionsException Missing manage_messages permission when deleting others reaction. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function deleteReaction(int $type, $emoticon = null, ?string $id = null): ExtendedPromiseInterface + public function deleteReaction(int $type, $emoticon = null, ?string $id = null): PromiseInterface { if ($emoticon instanceof Emoji) { $emoticon = $emoticon->toReactionString(); @@ -1000,9 +1000,9 @@ public function deleteReaction(int $type, $emoticon = null, ?string $id = null): * * @param MessageBuilder $message Contains the new contents of the message. Note that fields not specified in the builder will not be overwritten. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function edit(MessageBuilder $message): ExtendedPromiseInterface + public function edit(MessageBuilder $message): PromiseInterface { return $this->_edit($message)->then(function ($response) { $this->fill((array) $response); @@ -1011,7 +1011,7 @@ public function edit(MessageBuilder $message): ExtendedPromiseInterface }); } - private function _edit(MessageBuilder $message): ExtendedPromiseInterface + private function _edit(MessageBuilder $message): PromiseInterface { if ($message->requiresMultipart()) { $multipart = $message->toMultipart(); @@ -1027,12 +1027,12 @@ private function _edit(MessageBuilder $message): ExtendedPromiseInterface * * @link https://discord.com/developers/docs/resources/channel#delete-message * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \RuntimeException This type of message cannot be deleted. * @throws NoPermissionsException Missing manage_messages permission when deleting others message. */ - public function delete(): ExtendedPromiseInterface + public function delete(): PromiseInterface { if (! $this->isDeletable()) { return reject(new \RuntimeException("Cannot delete this type of message: {$this->type}", 50021)); @@ -1055,9 +1055,9 @@ public function delete(): ExtendedPromiseInterface * @param int $options['time'] Time in milliseconds until the collector finishes or false. * @param int $options['limit'] The amount of reactions allowed or false. * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> */ - public function createReactionCollector(callable $filter, array $options = []): ExtendedPromiseInterface + public function createReactionCollector(callable $filter, array $options = []): PromiseInterface { $deferred = new Deferred(); $reactions = new Collection([], null, null); @@ -1106,9 +1106,9 @@ public function createReactionCollector(callable $filter, array $options = []): * * @param Embed $embed * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function addEmbed(Embed $embed): ExtendedPromiseInterface + public function addEmbed(Embed $embed): PromiseInterface { return $this->edit(MessageBuilder::new() ->addEmbed($embed)); diff --git a/src/Discord/Parts/Channel/Reaction.php b/src/Discord/Parts/Channel/Reaction.php index 868912c4b..b12f3b23d 100644 --- a/src/Discord/Parts/Channel/Reaction.php +++ b/src/Discord/Parts/Channel/Reaction.php @@ -17,7 +17,7 @@ use Discord\Parts\Guild\Guild; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use function Discord\normalizePartId; @@ -70,7 +70,7 @@ public function isPartial(): bool /** * {@inheritDoc} */ - public function fetch(): ExtendedPromiseInterface + public function fetch(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_MESSAGE, $this->channel_id, $this->message_id)) ->then(function ($message) { @@ -101,9 +101,9 @@ protected function getIdAttribute(): string * * @link https://discord.com/developers/docs/resources/channel#get-reactions * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getUsers(array $options = []): ExtendedPromiseInterface + public function getUsers(array $options = []): PromiseInterface { $query = Endpoint::bind(Endpoint::MESSAGE_REACTION_EMOJI, $this->channel_id, $this->message_id, urlencode($this->emoji->id === null ? $this->emoji->name : "{$this->emoji->name}:{$this->emoji->id}")); @@ -144,9 +144,9 @@ public function getUsers(array $options = []): ExtendedPromiseInterface * * @see Message::getUsers() * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getAllUsers(): ExtendedPromiseInterface + public function getAllUsers(): PromiseInterface { $response = Collection::for(User::class); $getUsers = function ($after = null) use (&$getUsers, $response) { diff --git a/src/Discord/Parts/Channel/Webhook.php b/src/Discord/Parts/Channel/Webhook.php index 9eca344bd..2c585a623 100644 --- a/src/Discord/Parts/Channel/Webhook.php +++ b/src/Discord/Parts/Channel/Webhook.php @@ -18,7 +18,7 @@ use Discord\Parts\Part; use Discord\Parts\User\User; use Discord\Repository\Channel\WebhookMessageRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -85,9 +85,9 @@ class Webhook extends Part * @param MessageBuilder|array $data * @param array $queryparams Query string params to add to the request. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function execute($data, array $queryparams = []): ExtendedPromiseInterface + public function execute($data, array $queryparams = []): PromiseInterface { $endpoint = Endpoint::bind(Endpoint::WEBHOOK_EXECUTE, $this->id, $this->token); @@ -129,9 +129,9 @@ public function execute($data, array $queryparams = []): ExtendedPromiseInterfac * @param MessageBuilder $builder The new message. * @param array $queryparams Query string params to add to the request. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function updateMessage(string $message_id, MessageBuilder $builder, array $queryparams = []): ExtendedPromiseInterface + public function updateMessage(string $message_id, MessageBuilder $builder, array $queryparams = []): PromiseInterface { $endpoint = Endpoint::bind(Endpoint::WEBHOOK_MESSAGE, $this->id, $this->token, $message_id); diff --git a/src/Discord/Parts/Guild/Guild.php b/src/Discord/Parts/Guild/Guild.php index e0e88ef97..b076b0092 100644 --- a/src/Discord/Parts/Guild/Guild.php +++ b/src/Discord/Parts/Guild/Guild.php @@ -39,7 +39,7 @@ use Discord\Repository\Guild\ScheduledEventRepository; use Discord\Repository\Guild\GuildTemplateRepository; use Discord\Repository\Guild\IntegrationRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use ReflectionClass; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -399,9 +399,9 @@ protected function setStickersAttribute(?array $stickers): void * * @throws NoPermissionsException Missing manage_guild permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getInvites(): ExtendedPromiseInterface + public function getInvites(): PromiseInterface { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_guild) { @@ -429,9 +429,9 @@ public function getInvites(): ExtendedPromiseInterface * * @throws NoPermissionsException Missing ban_members permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function unban($user): ExtendedPromiseInterface + public function unban($user): PromiseInterface { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->ban_members) { @@ -720,9 +720,9 @@ protected function getFeatureWelcomeScreenEnabledAttribute(): bool * * @link https://discord.com/developers/docs/resources/voice#list-voice-regions * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getVoiceRegions(): ExtendedPromiseInterface + public function getVoiceRegions(): PromiseInterface { if (null !== $this->regions) { return resolve($this->regions); @@ -747,9 +747,9 @@ public function getVoiceRegions(): ExtendedPromiseInterface * * @throws NoPermissionsException Missing manage_roles permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function createRole(array $data = [], ?string $reason = null): ExtendedPromiseInterface + public function createRole(array $data = [], ?string $reason = null): PromiseInterface { $botperms = $this->getBotPermissions(); @@ -775,9 +775,9 @@ public function createRole(array $data = [], ?string $reason = null): ExtendedPr * @throws NoPermissionsException Missing manage_guild_expressions permission. * @throws FileNotFoundException File does not exist. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function createEmoji(array $options, ?string $filepath = null, ?string $reason = null): ExtendedPromiseInterface + public function createEmoji(array $options, ?string $filepath = null, ?string $reason = null): PromiseInterface { $resolver = new OptionsResolver(); $resolver @@ -851,9 +851,9 @@ public function createEmoji(array $options, ?string $filepath = null, ?string $r * @throws \DomainException File format is not PNG, APNG, or Lottie JSON. * @throws \RuntimeException Guild is not verified or partnered to upload Lottie stickers. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function createSticker(array $options, string $filepath, ?string $reason = null): ExtendedPromiseInterface + public function createSticker(array $options, string $filepath, ?string $reason = null): PromiseInterface { $resolver = new OptionsResolver(); $resolver @@ -951,9 +951,9 @@ public function createSticker(array $options, string $filepath, ?string $reason /** * Leaves the guild. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function leave(): ExtendedPromiseInterface + public function leave(): PromiseInterface { return $this->discord->guilds->leave($this->id); } @@ -966,9 +966,9 @@ public function leave(): ExtendedPromiseInterface * * @throws \RuntimeException Ownership not transferred correctly. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function transferOwnership($member, ?string $reason = null): ExtendedPromiseInterface + public function transferOwnership($member, ?string $reason = null): PromiseInterface { if ($member instanceof Member) { $member = $member->id; @@ -993,11 +993,11 @@ public function transferOwnership($member, ?string $reason = null): ExtendedProm * * @deprecated 10.0.0 Use `Channel::$rtc_region`. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @see Guild::REGION_DEFAULT The default region. */ - public function validateRegion(): ExtendedPromiseInterface + public function validateRegion(): PromiseInterface { return $this->getVoiceRegions()->then(function () { $regions = $this->regions->map(function ($region) { @@ -1026,9 +1026,9 @@ public function validateRegion(): ExtendedPromiseInterface * * @throws NoPermissionsException Missing view_audit_log permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getAuditLog(array $options = []): ExtendedPromiseInterface + public function getAuditLog(array $options = []): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1092,9 +1092,9 @@ public function getBotPermissions(): ?RolePermission * * @throws NoPermissionsException Missing manage_roles permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function updateRolePositions(array $roles): ExtendedPromiseInterface + public function updateRolePositions(array $roles): PromiseInterface { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_roles) { @@ -1135,9 +1135,9 @@ public function updateRolePositions(array $roles): ExtendedPromiseInterface * @param string|null $options['query'] Query string to match username(s) and nickname(s) against * @param int|null $options['limit'] How many entries are returned (default 1, minimum 1, maximum 1000) * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function searchMembers(array $options): ExtendedPromiseInterface + public function searchMembers(array $options): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1182,9 +1182,9 @@ public function searchMembers(array $options): ExtendedPromiseInterface * * @throws NoPermissionsException Missing kick_members permission. * - * @return ExtendedPromiseInterface The number of members that would be removed. + * @return PromiseInterface The number of members that would be removed. */ - public function getPruneCount(array $options = []): ExtendedPromiseInterface + public function getPruneCount(array $options = []): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1238,9 +1238,9 @@ public function getPruneCount(array $options = []): ExtendedPromiseInterface * * @throws NoPermissionsException Missing kick_members permission. * - * @return ExtendedPromiseInterface The number of members that were removed in the prune operation. + * @return PromiseInterface The number of members that were removed in the prune operation. */ - public function beginPrune(array $options = [], ?string $reason = null): ExtendedPromiseInterface + public function beginPrune(array $options = [], ?string $reason = null): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1289,9 +1289,9 @@ public function beginPrune(array $options = [], ?string $reason = null): Extende * * @throws NoPermissionsException Missing manage_guild permission when the welcome screen is not enabled. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getWelcomeScreen(bool $fresh = false): ExtendedPromiseInterface + public function getWelcomeScreen(bool $fresh = false): PromiseInterface { if (! $this->feature_welcome_screen_enabled) { $botperms = $this->getBotPermissions(); @@ -1337,9 +1337,9 @@ protected function getWelcomeScreenAttribute(): ?WelcomeScreen * * @throws NoPermissionsException Missing manage_guild permission. * - * @return ExtendedPromiseInterface The updated Welcome Screen. + * @return PromiseInterface The updated Welcome Screen. */ - public function updateWelcomeScreen(array $options): ExtendedPromiseInterface + public function updateWelcomeScreen(array $options): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1381,9 +1381,9 @@ public function updateWelcomeScreen(array $options): ExtendedPromiseInterface * * @throws NoPermissionsException Missing manage_guild permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getWidgetSettings(): ExtendedPromiseInterface + public function getWidgetSettings(): PromiseInterface { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_guild) { @@ -1411,9 +1411,9 @@ public function getWidgetSettings(): ExtendedPromiseInterface * * @throws NoPermissionsException Missing manage_guild permission. * - * @return ExtendedPromiseInterface The updated guild widget object. + * @return PromiseInterface The updated guild widget object. */ - public function updateWidgetSettings(array $options, ?string $reason = null): ExtendedPromiseInterface + public function updateWidgetSettings(array $options, ?string $reason = null): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1448,9 +1448,9 @@ public function updateWidgetSettings(array $options, ?string $reason = null): Ex * * @link https://discord.com/developers/docs/resources/guild#get-guild-widget * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getWidget(): ExtendedPromiseInterface + public function getWidget(): PromiseInterface { return $this->factory->part(Widget::class, ['id' => $this->id])->fetch(); } @@ -1463,9 +1463,9 @@ public function getWidget(): ExtendedPromiseInterface * @throws \RuntimeException No possible channels to create Invite on. * @throws NoPermissionsException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function createInvite(...$args): ExtendedPromiseInterface + public function createInvite(...$args): PromiseInterface { $channel = $this->channels->find(function (Channel $channel) { if ($channel->canInvite()) { @@ -1494,9 +1494,9 @@ public function createInvite(...$args): ExtendedPromiseInterface * @param int $level The new MFA level `Guild::MFA_NONE` or `Guild::MFA_ELEVATED`. * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface This guild. + * @return PromiseInterface This guild. */ - public function updateMFALevel(int $level, ?string $reason = null): ExtendedPromiseInterface + public function updateMFALevel(int $level, ?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -1525,9 +1525,9 @@ public function updateMFALevel(int $level, ?string $reason = null): ExtendedProm * administrator for COMMUNITY or DISCOVERABLE. * manage_guild for INVITES_DISABLED or RAID_ALERTS_ENABLED. * - * @return ExtendedPromiseInterface This guild. + * @return PromiseInterface This guild. */ - public function setFeatures(array $features, ?string $reason = null): ExtendedPromiseInterface + public function setFeatures(array $features, ?string $reason = null): PromiseInterface { if ($botperms = $this->getBotPermissions()) { if ((isset($features['COMMUNITY']) || isset($features['DISCOVERABLE'])) && ! $botperms->administrator) { diff --git a/src/Discord/Parts/Guild/GuildTemplate.php b/src/Discord/Parts/Guild/GuildTemplate.php index 76d2f99f0..75c2993a4 100644 --- a/src/Discord/Parts/Guild/GuildTemplate.php +++ b/src/Discord/Parts/Guild/GuildTemplate.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -130,9 +130,9 @@ protected function getUpdatedAtAttribute(): Carbon * @param string $options['name'] The name of the guild (2-100 characters). * @param string|null $options['icon'] The base64 128x128 image for the guild icon. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function createGuild($options = []): ExtendedPromiseInterface + public function createGuild($options = []): PromiseInterface { $resolver = new OptionsResolver(); $resolver diff --git a/src/Discord/Parts/Guild/ScheduledEvent.php b/src/Discord/Parts/Guild/ScheduledEvent.php index 0e73fb1d7..429330633 100644 --- a/src/Discord/Parts/Guild/ScheduledEvent.php +++ b/src/Discord/Parts/Guild/ScheduledEvent.php @@ -17,7 +17,7 @@ use Discord\Parts\Channel\Channel; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use function React\Promise\reject; @@ -95,9 +95,9 @@ class ScheduledEvent extends Part * * @throws \RangeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getUsers(array $options): ExtendedPromiseInterface + public function getUsers(array $options): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefaults(['limit' => 100, 'with_member' => false]); diff --git a/src/Discord/Parts/Guild/Widget.php b/src/Discord/Parts/Guild/Widget.php index 4e7782c36..adcff1596 100644 --- a/src/Discord/Parts/Guild/Widget.php +++ b/src/Discord/Parts/Guild/Widget.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Http\Http; use Discord\Parts\Part; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * A Widget of a Guild. @@ -86,7 +86,7 @@ class Widget extends Part /** * {@inheritDoc} */ - public function fetch(): ExtendedPromiseInterface + public function fetch(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::GUILD_WIDGET, $this->id)) ->then(function ($response) { diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index 590b19a8d..208f6c979 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -29,7 +29,7 @@ use Discord\Parts\User\Member; use Discord\Parts\User\User; use Discord\WebSockets\Event; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use function Discord\poly_strlen; use function React\Promise\reject; @@ -225,9 +225,9 @@ protected function getAppPermissionsAttribute(): ?ChannelPermission * * @throws \LogicException Interaction is not Message Component or Modal Submit. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function acknowledge(): ExtendedPromiseInterface + public function acknowledge(): PromiseInterface { if ($this->type == InteractionType::APPLICATION_COMMAND) { return $this->acknowledgeWithResponse(); @@ -252,9 +252,9 @@ public function acknowledge(): ExtendedPromiseInterface * * @throws \LogicException Interaction is not Application Command, Message Component, or Modal Submit. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function acknowledgeWithResponse(bool $ephemeral = false): ExtendedPromiseInterface + public function acknowledgeWithResponse(bool $ephemeral = false): PromiseInterface { if (! in_array($this->type, [InteractionType::APPLICATION_COMMAND, InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only acknowledge application command, message component, or modal submit interactions.')); @@ -276,9 +276,9 @@ public function acknowledgeWithResponse(bool $ephemeral = false): ExtendedPromis * * @throws \LogicException Interaction is not Message Component. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function updateMessage(MessageBuilder $builder): ExtendedPromiseInterface + public function updateMessage(MessageBuilder $builder): PromiseInterface { if (! in_array($this->type, [InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only update messages that occur due to a message component interaction.')); @@ -297,9 +297,9 @@ public function updateMessage(MessageBuilder $builder): ExtendedPromiseInterface * * @throws \RuntimeException Interaction is not created yet. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getOriginalResponse(): ExtendedPromiseInterface + public function getOriginalResponse(): PromiseInterface { if (! $this->created) { return reject(new \RuntimeException('Interaction has not been created yet.')); @@ -322,15 +322,15 @@ public function getOriginalResponse(): ExtendedPromiseInterface * * @throws \RuntimeException Interaction is not responded yet. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function updateOriginalResponse(MessageBuilder $builder): ExtendedPromiseInterface + public function updateOriginalResponse(MessageBuilder $builder): PromiseInterface { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); } - return (function () use ($builder): ExtendedPromiseInterface { + return (function () use ($builder): PromiseInterface { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -350,9 +350,9 @@ public function updateOriginalResponse(MessageBuilder $builder): ExtendedPromise * * @throws \RuntimeException Interaction is not responded yet. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function deleteOriginalResponse(): ExtendedPromiseInterface + public function deleteOriginalResponse(): PromiseInterface { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); @@ -371,9 +371,9 @@ public function deleteOriginalResponse(): ExtendedPromiseInterface * * @throws \RuntimeException Interaction is not responded yet. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = false): ExtendedPromiseInterface + public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = false): PromiseInterface { if (! $this->responded && $this->type != InteractionType::MESSAGE_COMPONENT) { return reject(new \RuntimeException('Cannot create a follow-up message as the interaction has not been responded to.')); @@ -383,7 +383,7 @@ public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = f $builder->_setFlags(Message::FLAG_EPHEMERAL); } - return (function () use ($builder): ExtendedPromiseInterface { + return (function () use ($builder): PromiseInterface { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -406,9 +406,9 @@ public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = f * * @throws \LogicException Interaction is not Application Command, Message Component, or Modal Submit. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = false): ExtendedPromiseInterface + public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = false): PromiseInterface { if (! in_array($this->type, [InteractionType::APPLICATION_COMMAND, InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only acknowledge application command, message component, or modal submit interactions.')); @@ -437,9 +437,9 @@ public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = fa * * @throws \RuntimeException Interaction is already responded. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - protected function respond(array $payload, ?Multipart $multipart = null): ExtendedPromiseInterface + protected function respond(array $payload, ?Multipart $multipart = null): PromiseInterface { if ($this->responded) { return reject(new \RuntimeException('Interaction has already been responded to.')); @@ -472,7 +472,7 @@ protected function respond(array $payload, ?Multipart $multipart = null): Extend * * @throws \RuntimeException Interaction is not responded yet. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ public function updateFollowUpMessage(string $message_id, MessageBuilder $builder) { @@ -480,7 +480,7 @@ public function updateFollowUpMessage(string $message_id, MessageBuilder $builde return reject(new \RuntimeException('Cannot create a follow-up message as the interaction has not been responded to.')); } - return (function () use ($message_id, $builder): ExtendedPromiseInterface { + return (function () use ($message_id, $builder): PromiseInterface { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -502,9 +502,9 @@ public function updateFollowUpMessage(string $message_id, MessageBuilder $builde * * @throws \RuntimeException Interaction is not created yet. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getFollowUpMessage(string $message_id): ExtendedPromiseInterface + public function getFollowUpMessage(string $message_id): PromiseInterface { if (! $this->created) { return reject(new \RuntimeException('Interaction has not been created yet.')); @@ -527,9 +527,9 @@ public function getFollowUpMessage(string $message_id): ExtendedPromiseInterface * * @throws \RuntimeException Interaction is not responded yet. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function deleteFollowUpMessage(string $message_id): ExtendedPromiseInterface + public function deleteFollowUpMessage(string $message_id): PromiseInterface { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); @@ -547,9 +547,9 @@ public function deleteFollowUpMessage(string $message_id): ExtendedPromiseInterf * * @throws \LogicException Interaction is not Autocomplete. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function autoCompleteResult(array $choices): ExtendedPromiseInterface + public function autoCompleteResult(array $choices): PromiseInterface { if ($this->type != InteractionType::APPLICATION_COMMAND_AUTOCOMPLETE) { return reject(new \LogicException('You can only respond command option results with auto complete interactions.')); @@ -574,9 +574,9 @@ public function autoCompleteResult(array $choices): ExtendedPromiseInterface * @throws \LogicException Interaction is Ping or Modal Submit. * @throws \LengthException Modal title is longer than 45 characters. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function showModal(string $title, string $custom_id, array $components, ?callable $submit = null): ExtendedPromiseInterface + public function showModal(string $title, string $custom_id, array $components, ?callable $submit = null): PromiseInterface { if (in_array($this->type, [InteractionType::PING, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You cannot pop up a modal from a ping or modal submit interaction.')); diff --git a/src/Discord/Parts/Part.php b/src/Discord/Parts/Part.php index 2777eae2c..c13909d16 100644 --- a/src/Discord/Parts/Part.php +++ b/src/Discord/Parts/Part.php @@ -17,7 +17,7 @@ use Discord\Factory\Factory; use Discord\Http\Http; use JsonSerializable; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * This class is the base of all objects that are returned. All "Parts" extend @@ -149,9 +149,9 @@ public function isPartial(): bool * * @throws \RuntimeException The part is not fetchable. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function fetch(): ExtendedPromiseInterface + public function fetch(): PromiseInterface { throw new \RuntimeException('This part is not fetchable.'); } diff --git a/src/Discord/Parts/Thread/Member.php b/src/Discord/Parts/Thread/Member.php index 45639bf3b..a429a5553 100644 --- a/src/Discord/Parts/Thread/Member.php +++ b/src/Discord/Parts/Thread/Member.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * Represents a member that belongs to a thread. Not the same as a user nor a @@ -70,9 +70,9 @@ protected function getJoinTimestampAttribute(): Carbon * * @link https://discord.com/developers/docs/resources/channel#remove-thread-member * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function remove(): ExtendedPromiseInterface + public function remove(): PromiseInterface { return $this->http->delete(Endpoint::bind(Endpoint::THREAD_MEMBER, $this->id, $this->user_id)); } diff --git a/src/Discord/Parts/Thread/Thread.php b/src/Discord/Parts/Thread/Thread.php index c09fdc830..6079e2c93 100644 --- a/src/Discord/Parts/Thread/Thread.php +++ b/src/Discord/Parts/Thread/Thread.php @@ -14,7 +14,6 @@ use Carbon\Carbon; use Discord\Builders\MessageBuilder; use Discord\Helpers\Collection; -use Discord\Helpers\Deferred; use Discord\Http\Endpoint; use Discord\Http\Exceptions\NoPermissionsException; use Discord\Parts\Channel\Channel; @@ -29,7 +28,8 @@ use Discord\Repository\Channel\MessageRepository; use Discord\Repository\Thread\MemberRepository; use Discord\WebSockets\Event; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\Deferred; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Traversable; @@ -74,7 +74,7 @@ * @property MessageRepository $messages Repository of messages sent in the thread. * @property MemberRepository $members Repository of members in the thread. * - * @method ExtendedPromiseInterface sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class Thread extends Part { @@ -304,9 +304,9 @@ protected function getCreateTimestampAttribute(): ?Carbon * * @link https://discord.com/developers/docs/resources/channel#join-thread * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function join(): ExtendedPromiseInterface + public function join(): PromiseInterface { return $this->http->put(Endpoint::bind(Endpoint::THREAD_MEMBER_ME, $this->id)); } @@ -318,9 +318,9 @@ public function join(): ExtendedPromiseInterface * * @param User|Member|string $user User to add. Can be one of the user objects or a user ID. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function addMember($user): ExtendedPromiseInterface + public function addMember($user): PromiseInterface { if ($user instanceof User || $user instanceof Member) { $user = $user->id; @@ -334,9 +334,9 @@ public function addMember($user): ExtendedPromiseInterface * * @link https://discord.com/developers/docs/resources/channel#leave-thread * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function leave(): ExtendedPromiseInterface + public function leave(): PromiseInterface { return $this->http->delete(Endpoint::bind(Endpoint::THREAD_MEMBER_ME, $this->id)); } @@ -348,9 +348,9 @@ public function leave(): ExtendedPromiseInterface * * @param User|Member|ThreadMember|string $user User to remove. Can be one of the user objects or a user ID. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function removeMember($user): ExtendedPromiseInterface + public function removeMember($user): PromiseInterface { if ($user instanceof User || $user instanceof Member) { $user = $user->id; @@ -367,9 +367,9 @@ public function removeMember($user): ExtendedPromiseInterface * @param string $name New thread name. * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function rename(string $name, ?string $reason = null): ExtendedPromiseInterface + public function rename(string $name, ?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -389,9 +389,9 @@ public function rename(string $name, ?string $reason = null): ExtendedPromiseInt * * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function archive(?string $reason = null): ExtendedPromiseInterface + public function archive(?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -411,9 +411,9 @@ public function archive(?string $reason = null): ExtendedPromiseInterface * * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function unarchive(?string $reason = null): ExtendedPromiseInterface + public function unarchive(?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -434,9 +434,9 @@ public function unarchive(?string $reason = null): ExtendedPromiseInterface * @param int $duration Duration in minutes. * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function setAutoArchiveDuration(int $duration, ?string $reason = null): ExtendedPromiseInterface + public function setAutoArchiveDuration(int $duration, ?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -456,11 +456,11 @@ public function setAutoArchiveDuration(int $duration, ?string $reason = null): E * * @link https://discord.com/developers/docs/resources/channel#get-pinned-messages * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> * * @todo Make it in a trait along with Channel */ - public function getPinnedMessages(): ExtendedPromiseInterface + public function getPinnedMessages(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_PINS, $this->id)) ->then(function ($responses) { @@ -482,11 +482,11 @@ public function getPinnedMessages(): ExtendedPromiseInterface * @param array|Traversable $messages An array of messages to delete. * @param string|null $reason Reason for Audit Log (only for bulk messages). * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function deleteMessages($messages, ?string $reason = null): ExtendedPromiseInterface + public function deleteMessages($messages, ?string $reason = null): PromiseInterface { if (! is_array($messages) && ! ($messages instanceof Traversable)) { return reject(new \InvalidArgumentException('$messages must be an array or implement Traversable.')); @@ -536,11 +536,11 @@ public function deleteMessages($messages, ?string $reason = null): ExtendedPromi * * @param array $options * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> * * @todo Make it in a trait along with Channel */ - public function getMessageHistory(array $options): ExtendedPromiseInterface + public function getMessageHistory(array $options): PromiseInterface { $resolver = new OptionsResolver(); $resolver @@ -600,11 +600,11 @@ public function getMessageHistory(array $options): ExtendedPromiseInterface * * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function pinMessage(Message $message, ?string $reason = null): ExtendedPromiseInterface + public function pinMessage(Message $message, ?string $reason = null): PromiseInterface { if ($message->pinned) { return reject(new \RuntimeException('This message is already pinned.')); @@ -636,11 +636,11 @@ public function pinMessage(Message $message, ?string $reason = null): ExtendedPr * * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function unpinMessage(Message $message, ?string $reason = null): ExtendedPromiseInterface + public function unpinMessage(Message $message, ?string $reason = null): PromiseInterface { if (! $message->pinned) { return reject(new \RuntimeException('This message is not pinned.')); @@ -677,11 +677,11 @@ public function unpinMessage(Message $message, ?string $reason = null): Extended * @param array|null $allowed_mentions Allowed mentions object for the message. * @param Message|null $replyTo Sends the message as a reply to the given message instance. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): ExtendedPromiseInterface + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface { // Backwards compatible support for old `sendMessage` function signature. if (! ($message instanceof MessageBuilder)) { @@ -727,11 +727,11 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @param Embed $embed Embed to send. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function sendEmbed(Embed $embed): ExtendedPromiseInterface + public function sendEmbed(Embed $embed): PromiseInterface { return $this->sendMessage(MessageBuilder::new() ->addEmbed($embed)); @@ -746,9 +746,9 @@ public function sendEmbed(Embed $embed): ExtendedPromiseInterface * * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function broadcastTyping(): ExtendedPromiseInterface + public function broadcastTyping(): PromiseInterface { return $this->http->post(Endpoint::bind(Endpoint::CHANNEL_TYPING, $this->id)); } @@ -761,11 +761,11 @@ public function broadcastTyping(): ExtendedPromiseInterface * @param int $options ['time'] Time in milliseconds until the collector finishes or false. * @param int $options ['limit'] The amount of messages allowed or false. * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> * * @todo Make it in a trait along with Channel */ - public function createMessageCollector(callable $filter, array $options = []): ExtendedPromiseInterface + public function createMessageCollector(callable $filter, array $options = []): PromiseInterface { $deferred = new Deferred(); $messages = new Collection([], null, null); diff --git a/src/Discord/Parts/User/Client.php b/src/Discord/Parts/User/Client.php index 7bbf28ddb..71b0dd45d 100644 --- a/src/Discord/Parts/User/Client.php +++ b/src/Discord/Parts/User/Client.php @@ -18,7 +18,7 @@ use Discord\Repository\GuildRepository; use Discord\Repository\PrivateChannelRepository; use Discord\Repository\UserRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * The client is the main interface for the client. Most calls on the main class are forwarded here. @@ -83,7 +83,7 @@ public function afterConstruct(): void { $this->application = $this->factory->part(Application::class, [], true); - $this->http->get(Endpoint::APPLICATION_CURRENT)->done(function ($response) { + $this->http->get(Endpoint::APPLICATION_CURRENT)->then(function ($response) { $this->application->fill((array) $response); $this->created = true; }); @@ -142,9 +142,9 @@ protected function getAvatarHashAttribute(): ?string /** * Saves the client instance. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function save(): ExtendedPromiseInterface + public function save(): PromiseInterface { return $this->http->patch(Endpoint::USER_CURRENT, $this->getUpdatableAttributes()); } diff --git a/src/Discord/Parts/User/Member.php b/src/Discord/Parts/User/Member.php index f071fbb12..c12d64769 100644 --- a/src/Discord/Parts/User/Member.php +++ b/src/Discord/Parts/User/Member.php @@ -28,7 +28,7 @@ use Discord\Parts\Permissions\RolePermission; use Discord\Parts\Thread\Thread; use Discord\Parts\WebSockets\PresenceUpdate; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use function React\Promise\reject; @@ -63,7 +63,7 @@ * @property Collection|Activity[] $activities User's current activities. * @property object $client_status Current client status. * - * @method ExtendedPromiseInterface sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class Member extends Part { @@ -129,9 +129,9 @@ public function updateFromPresence(PresenceUpdate $presence): PresenceUpdate * * @throws \RuntimeException Member has no `$guild` * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): ExtendedPromiseInterface + public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): PromiseInterface { if (! $guild = $this->guild) { return reject(new \RuntimeException('Member has no Guild Part')); @@ -148,9 +148,9 @@ public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): * * @throws NoPermissionsException Missing manage_nicknames permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function setNickname(?string $nick = null, ?string $reason = null): ExtendedPromiseInterface + public function setNickname(?string $nick = null, ?string $reason = null): PromiseInterface { $payload = [ 'nick' => $nick ?? '', @@ -188,9 +188,9 @@ public function setNickname(?string $nick = null, ?string $reason = null): Exten * @param Channel|?string $channel The channel to move the member to. * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function moveMember($channel, ?string $reason = null): ExtendedPromiseInterface + public function moveMember($channel, ?string $reason = null): PromiseInterface { if ($channel instanceof Channel) { $channel = $channel->id; @@ -218,9 +218,9 @@ public function moveMember($channel, ?string $reason = null): ExtendedPromiseInt * @throws \RuntimeException * @throws NoPermissionsException Missing manage_roles permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function addRole($role, ?string $reason = null): ExtendedPromiseInterface + public function addRole($role, ?string $reason = null): PromiseInterface { if ($role instanceof Role) { $role = $role->id; @@ -262,9 +262,9 @@ public function addRole($role, ?string $reason = null): ExtendedPromiseInterface * * @throws NoPermissionsException Missing manage_roles permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function removeRole($role, ?string $reason = null): ExtendedPromiseInterface + public function removeRole($role, ?string $reason = null): PromiseInterface { if ($role instanceof Role) { $role = $role->id; @@ -301,9 +301,9 @@ public function removeRole($role, ?string $reason = null): ExtendedPromiseInterf * * @throws NoPermissionsException Missing manage_roles permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function setRoles(array $roles, ?string $reason = null): ExtendedPromiseInterface + public function setRoles(array $roles, ?string $reason = null): PromiseInterface { foreach ($roles as $i => $role) { if ($role instanceof Role) { @@ -348,9 +348,9 @@ public function setRoles(array $roles, ?string $reason = null): ExtendedPromiseI * * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): ExtendedPromiseInterface + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface { if ($user = $this->user) { return $user->sendMessage($message, $tts, $embed, $allowed_mentions, $replyTo); @@ -483,9 +483,9 @@ public function getPermissions($channel = null): ?RolePermission * * @throws NoPermissionsException Missing moderate_members permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function timeoutMember(?Carbon $communication_disabled_until, ?string $reason = null): ExtendedPromiseInterface + public function timeoutMember(?Carbon $communication_disabled_until, ?string $reason = null): PromiseInterface { if ($guild = $this->guild) { if ($botperms = $guild->getBotPermissions()) { @@ -516,9 +516,9 @@ public function timeoutMember(?Carbon $communication_disabled_until, ?string $re * * @throws NoPermissionsException Missing `moderate_members` permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function setBypassesVerification(bool $bypasses_verification, ?string $reason = null): ExtendedPromiseInterface + public function setBypassesVerification(bool $bypasses_verification, ?string $reason = null): PromiseInterface { if ($guild = $this->guild) { if ($botperms = $guild->getBotPermissions()) { diff --git a/src/Discord/Parts/User/User.php b/src/Discord/Parts/User/User.php index a5f920fa0..ca8f69294 100644 --- a/src/Discord/Parts/User/User.php +++ b/src/Discord/Parts/User/User.php @@ -16,7 +16,7 @@ use Discord\Parts\Channel\Channel; use Discord\Parts\Part; use Discord\Parts\Channel\Message; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -47,7 +47,7 @@ * @property int|null $premium_type Type of nitro subscription. * @property int|null $public_flags Public flags on the user. * - * @method ExtendedPromiseInterface sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class User extends Part { @@ -100,9 +100,9 @@ class User extends Part * * @link https://discord.com/developers/docs/resources/user#create-dm * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getPrivateChannel(): ExtendedPromiseInterface + public function getPrivateChannel(): PromiseInterface { if ($channel = $this->discord->private_channels->get('recipient_id', $this->id)) { return resolve($channel); @@ -130,9 +130,9 @@ public function getPrivateChannel(): ExtendedPromiseInterface * @param array|null $allowed_mentions Allowed mentions object for the message. * @param Message|null $replyTo Sends the message as a reply to the given message instance. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): ExtendedPromiseInterface + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface { return $this->getPrivateChannel()->then(function (Channel $channel) use ($message, $tts, $embed, $allowed_mentions, $replyTo) { return $channel->sendMessage($message, $tts, $embed, $allowed_mentions, $replyTo); @@ -146,9 +146,9 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function broadcastTyping(): ExtendedPromiseInterface + public function broadcastTyping(): PromiseInterface { return $this->getPrivateChannel()->then(function (Channel $channel) { return $channel->broadcastTyping(); diff --git a/src/Discord/Parts/WebSockets/MessageReaction.php b/src/Discord/Parts/WebSockets/MessageReaction.php index a7253ce46..294a084a6 100644 --- a/src/Discord/Parts/WebSockets/MessageReaction.php +++ b/src/Discord/Parts/WebSockets/MessageReaction.php @@ -19,7 +19,7 @@ use Discord\Parts\Part; use Discord\Parts\User\Member; use Discord\Parts\User\User; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use function React\Promise\reject; use function React\Promise\resolve; @@ -71,7 +71,7 @@ public function isPartial(): bool /** * {@inheritDoc} */ - public function fetch(): ExtendedPromiseInterface + public function fetch(): PromiseInterface { $promise = resolve(); @@ -229,14 +229,14 @@ protected function getEmojiAttribute(): Emoji * * @throws \RuntimeException Reaction has no user id. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @see Message::deleteReaction() * * @link https://discord.com/developers/docs/resources/channel#delete-own-reaction * @link https://discord.com/developers/docs/resources/channel#delete-user-reaction */ - public function delete(?int $type = null): ExtendedPromiseInterface + public function delete(?int $type = null): PromiseInterface { if ($type === null) { if ($this->user_id == $this->discord->id) { diff --git a/src/Discord/Repository/AbstractRepository.php b/src/Discord/Repository/AbstractRepository.php index 8792bd3ee..61e89b4d4 100755 --- a/src/Discord/Repository/AbstractRepository.php +++ b/src/Discord/Repository/AbstractRepository.php @@ -18,7 +18,7 @@ use Discord\Http\Endpoint; use Discord\Http\Http; use Discord\Parts\Part; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use Traversable; use WeakReference; @@ -100,11 +100,11 @@ public function __construct(Discord $discord, array $vars = []) * * @param array $queryparams Query string params to add to the request (no validation) * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \Exception */ - public function freshen(array $queryparams = []): ExtendedPromiseInterface + public function freshen(array $queryparams = []): PromiseInterface { if (! isset($this->endpoints['all'])) { return reject(new \Exception('You cannot freshen this repository.')); @@ -134,9 +134,9 @@ public function freshen(array $queryparams = []): ExtendedPromiseInterface /** * @param object $response * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - protected function cacheFreshen($response): ExtendedPromiseInterface + protected function cacheFreshen($response): PromiseInterface { foreach ($response as $value) { $value = array_merge($this->vars, (array) $value); @@ -174,11 +174,11 @@ public function create(array $attributes = [], bool $created = false): Part * @param Part $part The part to save. * @param string|null $reason Reason for Audit Log (if supported). * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \Exception */ - public function save(Part $part, ?string $reason = null): ExtendedPromiseInterface + public function save(Part $part, ?string $reason = null): PromiseInterface { if ($part->created) { if (! isset($this->endpoints['update'])) { @@ -219,11 +219,11 @@ public function save(Part $part, ?string $reason = null): ExtendedPromiseInterfa * @param Part|string $part The part to delete. * @param string|null $reason Reason for Audit Log (if supported). * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \Exception */ - public function delete($part, ?string $reason = null): ExtendedPromiseInterface + public function delete($part, ?string $reason = null): PromiseInterface { if (! isset($part)) { return reject(new \Exception('You cannot delete a non-existant part.')); @@ -265,11 +265,11 @@ public function delete($part, ?string $reason = null): ExtendedPromiseInterface * @param Part $part The part to get fresh values. * @param array $queryparams Query string params to add to the request (no validation) * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @throws \Exception */ - public function fresh(Part $part, array $queryparams = []): ExtendedPromiseInterface + public function fresh(Part $part, array $queryparams = []): PromiseInterface { if (! $part->created) { return reject(new \Exception('You cannot get a non-existant part.')); @@ -301,9 +301,9 @@ public function fresh(Part $part, array $queryparams = []): ExtendedPromiseInter * * @throws \Exception * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function fetch(string $id, bool $fresh = false): ExtendedPromiseInterface + public function fetch(string $id, bool $fresh = false): PromiseInterface { if (! $fresh) { if (isset($this->items[$id])) { @@ -391,9 +391,9 @@ public function get(string $discrim, $key) * * @param string|int $offset * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function cacheGet($offset): ExtendedPromiseInterface + public function cacheGet($offset): PromiseInterface { return resolve($this->offsetGet($offset) ?? $this->cache->get($offset)); } @@ -444,9 +444,9 @@ public function pull($key, $default = null) * @param string|int $key * @param ?Part $default * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function cachePull($key, $default = null): ExtendedPromiseInterface + public function cachePull($key, $default = null): PromiseInterface { return $this->cacheGet($key)->then(fn ($item) => ($item === null) ? $default : $this->cache->delete($key)->then(fn ($success) => $item)); } diff --git a/src/Discord/Repository/Channel/ReactionRepository.php b/src/Discord/Repository/Channel/ReactionRepository.php index cdff59a46..6a7f73247 100644 --- a/src/Discord/Repository/Channel/ReactionRepository.php +++ b/src/Discord/Repository/Channel/ReactionRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Channel\Reaction; use Discord\Repository\AbstractRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * Contains reactions on a message. @@ -51,11 +51,11 @@ class ReactionRepository extends AbstractRepository * * @param Reaction|string $part The Reaction part or unicode emoji to delete. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * * @since 10.0.0 */ - public function delete($part, ?string $reason = null): ExtendedPromiseInterface + public function delete($part, ?string $reason = null): PromiseInterface { // Deal with unicode emoji if (is_string($part) && ! is_numeric($part)) { diff --git a/src/Discord/Repository/Channel/ThreadRepository.php b/src/Discord/Repository/Channel/ThreadRepository.php index cbd9c9572..8018ccd16 100644 --- a/src/Discord/Repository/Channel/ThreadRepository.php +++ b/src/Discord/Repository/Channel/ThreadRepository.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Thread\Thread; use Discord\Repository\AbstractRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -53,7 +53,7 @@ class ThreadRepository extends AbstractRepository /** * {@inheritDoc} */ - protected function cacheFreshen($response): ExtendedPromiseInterface + protected function cacheFreshen($response): PromiseInterface { foreach ($response->threads as $value) { $value = array_merge($this->vars, (array) $value); @@ -87,9 +87,9 @@ protected function cacheFreshen($response): ExtendedPromiseInterface * * @link https://discord.com/developers/docs/resources/channel#list-active-threads * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> */ - public function active(): ExtendedPromiseInterface + public function active(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::GUILD_THREADS_ACTIVE, $this->vars['guild_id'])) ->then(function ($response) { @@ -111,9 +111,9 @@ public function active(): ExtendedPromiseInterface * * @throws \InvalidArgumentException * - * @return ExtendedPromiseInterface> + * @return PromiseInterface> */ - public function archived(bool $private = false, bool $joined = false, ?int $limit = null, $before = null): ExtendedPromiseInterface + public function archived(bool $private = false, bool $joined = false, ?int $limit = null, $before = null): PromiseInterface { if ($joined) { if (! $private) { diff --git a/src/Discord/Repository/Guild/BanRepository.php b/src/Discord/Repository/Guild/BanRepository.php index 135d9825e..0c975d6c5 100644 --- a/src/Discord/Repository/Guild/BanRepository.php +++ b/src/Discord/Repository/Guild/BanRepository.php @@ -16,7 +16,7 @@ use Discord\Parts\User\Member; use Discord\Parts\User\User; use Discord\Repository\AbstractRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -63,9 +63,9 @@ class BanRepository extends AbstractRepository * @param array $options Array of Ban options 'delete_message_seconds' or 'delete_message_days' (deprecated). * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function ban($user, array $options = [], ?string $reason = null): ExtendedPromiseInterface + public function ban($user, array $options = [], ?string $reason = null): PromiseInterface { $content = []; $headers = []; @@ -122,9 +122,9 @@ public function ban($user, array $options = [], ?string $reason = null): Extende * @param User|Ban|string $ban User or Ban Part, or User ID * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function unban($ban, ?string $reason = null): ExtendedPromiseInterface + public function unban($ban, ?string $reason = null): PromiseInterface { if ($ban instanceof User || $ban instanceof Member) { $ban = $ban->id; diff --git a/src/Discord/Repository/Guild/GuildTemplateRepository.php b/src/Discord/Repository/Guild/GuildTemplateRepository.php index af50544dc..865f5bc0d 100644 --- a/src/Discord/Repository/Guild/GuildTemplateRepository.php +++ b/src/Discord/Repository/Guild/GuildTemplateRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\GuildTemplate; use Discord\Repository\AbstractRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * Contains guild templates of a guild. @@ -58,9 +58,9 @@ class GuildTemplateRepository extends AbstractRepository * * @param string $template_code The guild template code. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function sync(string $template_code): ExtendedPromiseInterface + public function sync(string $template_code): PromiseInterface { return $this->http->put(Endpoint::bind(Endpoint::GUILD_TEMPLATE, $this->vars['guild_id'], $template_code))->then(function ($guild_template) use ($template_code) { return $this->cache->get($template_code)->then(function ($guildTemplate) use ($guild_template, $template_code) { diff --git a/src/Discord/Repository/Guild/MemberRepository.php b/src/Discord/Repository/Guild/MemberRepository.php index 6afcb3754..91ab0ada7 100755 --- a/src/Discord/Repository/Guild/MemberRepository.php +++ b/src/Discord/Repository/Guild/MemberRepository.php @@ -11,11 +11,11 @@ namespace Discord\Repository\Guild; -use Discord\Helpers\Deferred; use Discord\Http\Endpoint; use Discord\Parts\User\Member; use Discord\Repository\AbstractRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\Deferred; +use React\Promise\PromiseInterface; /** * Contains members of a guild. @@ -56,9 +56,9 @@ class MemberRepository extends AbstractRepository * @param Member $member The member to kick. * @param string|null $reason Reason for Audit Log. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function kick(Member $member, ?string $reason = null): ExtendedPromiseInterface + public function kick(Member $member, ?string $reason = null): PromiseInterface { return $this->delete($member, $reason); } @@ -68,7 +68,7 @@ public function kick(Member $member, ?string $reason = null): ExtendedPromiseInt * * @param array $queryparams Query string params to add to the request, leave null to paginate all members (Warning: Be careful to use this on very large guild) */ - public function freshen(array $queryparams = null): ExtendedPromiseInterface + public function freshen(array $queryparams = null): PromiseInterface { if (isset($queryparams)) { return parent::freshen($queryparams); diff --git a/src/Discord/Repository/Guild/ScheduledEventRepository.php b/src/Discord/Repository/Guild/ScheduledEventRepository.php index 543fd4e84..46e49f694 100644 --- a/src/Discord/Repository/Guild/ScheduledEventRepository.php +++ b/src/Discord/Repository/Guild/ScheduledEventRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\ScheduledEvent; use Discord\Repository\AbstractRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -55,9 +55,9 @@ class ScheduledEventRepository extends AbstractRepository * * @param bool $with_user_count Whether to include number of users subscribed to each event * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function fetch(string $id, bool $fresh = false, bool $with_user_count = false): ExtendedPromiseInterface + public function fetch(string $id, bool $fresh = false, bool $with_user_count = false): PromiseInterface { if (! $with_user_count) { return parent::fetch($id, $fresh); diff --git a/src/Discord/Repository/GuildRepository.php b/src/Discord/Repository/GuildRepository.php index 9a97d22eb..aaf165576 100755 --- a/src/Discord/Repository/GuildRepository.php +++ b/src/Discord/Repository/GuildRepository.php @@ -13,7 +13,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\Guild; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * Contains guilds that the client is in. @@ -54,9 +54,9 @@ class GuildRepository extends AbstractRepository * * @param Guild|string $guild * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function leave($guild): ExtendedPromiseInterface + public function leave($guild): PromiseInterface { if ($guild instanceof Guild) { $guild = $guild->id; diff --git a/src/Discord/Voice/OggPage.php b/src/Discord/Voice/OggPage.php index 7b11208a9..d9e616b35 100644 --- a/src/Discord/Voice/OggPage.php +++ b/src/Discord/Voice/OggPage.php @@ -13,7 +13,7 @@ use Discord\Helpers\Buffer; use Generator; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * Represents a page in an Ogg container. @@ -65,11 +65,11 @@ private function __construct( * @param Buffer $buffer Buffer to read the Ogg page from. * @param ?int $timeout Time in milliseconds before a buffer read times out. * - * @return ExtendedPromiseInterface Promise containing the Ogg page. + * @return PromiseInterface Promise containing the Ogg page. * * @throws \UnexpectedValueException If the buffer is out of sync and an invalid header is read. */ - public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): ExtendedPromiseInterface + public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): PromiseInterface { $header = null; $pageSegments = []; diff --git a/src/Discord/Voice/OggStream.php b/src/Discord/Voice/OggStream.php index 59f640a1d..166925a89 100644 --- a/src/Discord/Voice/OggStream.php +++ b/src/Discord/Voice/OggStream.php @@ -13,7 +13,7 @@ use Discord\Exceptions\BufferTimedOutException; use Discord\Helpers\Buffer; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use React\Promise\Promise; use function React\Promise\resolve; @@ -65,9 +65,9 @@ private function __construct( * @param Buffer $buffer Buffer to read Ogg Opus packets from. * @param ?int $timeout Time in milliseconds before a buffer read times out. * - * @return ExtendedPromiseInterface A promise containing the Ogg stream. + * @return PromiseInterface A promise containing the Ogg stream. */ - public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): ExtendedPromiseInterface + public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): PromiseInterface { /** @var OpusHead */ $header = null; @@ -86,9 +86,9 @@ public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): ExtendedP /** * Attempt to get a packet from the Ogg stream. * - * @return ExtendedPromiseInterface Promise containing an Opus packet. If null, indicates EOF. + * @return PromiseInterface Promise containing an Opus packet. If null, indicates EOF. */ - public function getPacket(): ExtendedPromiseInterface + public function getPacket(): PromiseInterface { if ($this->packets === null) { return resolve(null); @@ -113,9 +113,9 @@ public function getPacket(): ExtendedPromiseInterface * Attempt to read an Ogg page from the buffer and parse it into Opus * packets. * - * @return ExtendedPromiseInterface Promise containing an array of Opus packets. + * @return PromiseInterface Promise containing an array of Opus packets. */ - private function parsePackets(): ExtendedPromiseInterface + private function parsePackets(): PromiseInterface { return new Promise(function ($resolve, $reject) { OggPage::fromBuffer($this->buffer, timeout: 0)->then(function ($page) use ($resolve) { diff --git a/src/Discord/Voice/VoiceClient.php b/src/Discord/Voice/VoiceClient.php index 73e3cf269..a71018278 100644 --- a/src/Discord/Voice/VoiceClient.php +++ b/src/Discord/Voice/VoiceClient.php @@ -26,10 +26,10 @@ use React\Datagram\Socket; use React\Dns\Resolver\Factory as DNSFactory; use React\EventLoop\LoopInterface; -use Discord\Helpers\Deferred; use Psr\Log\LoggerInterface; use React\ChildProcess\Process; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\Deferred; +use React\Promise\PromiseInterface; use React\Stream\ReadableResourceStream as Stream; use React\EventLoop\TimerInterface; use React\Stream\ReadableResourceStream; @@ -400,13 +400,10 @@ public function start() public function initSockets(): void { $wsfac = new WsFactory($this->loop); - /** @var ExtendedPromiseInterface */ + /** @var PromiseInterface */ $promise = $wsfac("wss://{$this->endpoint}?v={$this->version}"); - $promise->done( - [$this, 'handleWebSocketConnection'], - [$this, 'handleWebSocketError'] - ); + $promise->then([$this, 'handleWebSocketConnection'])->catch([$this, 'handleWebSocketError']); } /** @@ -441,10 +438,10 @@ public function handleWebSocketConnection(WebSocket $ws): void $buffer[1] = "\x01"; $buffer[3] = "\x46"; $buffer->writeUInt32BE($this->ssrc, 4); - /** @var ExtendedPromiseInterface */ + /** @var PromiseInterface */ $promise = $udpfac->createClient("{$data->d->ip}:{$this->udpPort}"); - $promise->done(function (Socket $client) use (&$ws, &$firstPack, &$ip, &$port, $buffer) { + $promise->then(function (Socket $client) use (&$ws, &$firstPack, &$ip, &$port, $buffer) { $this->logger->debug('connected to voice UDP'); $this->client = $client; @@ -502,7 +499,7 @@ public function handleWebSocketConnection(WebSocket $ws): void }; $client->on('message', $decodeUDP); - }, function ($e) { + })->catch(function ($e) { $this->logger->error('error while connecting to udp', ['e' => $e->getMessage()]); $this->emit('error', [$e]); }); @@ -689,9 +686,9 @@ public function handleVoiceServerChange(array $data = []): void * @throws FileNotFoundException * @throws \RuntimeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function playFile(string $file, int $channels = 2): ExtendedPromiseInterface + public function playFile(string $file, int $channels = 2): PromiseInterface { $deferred = new Deferred(); @@ -729,9 +726,9 @@ public function playFile(string $file, int $channels = 2): ExtendedPromiseInterf * @throws \RuntimeException * @throws \InvalidArgumentException Thrown when the stream passed to playRawStream is not a valid resource. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function playRawStream($stream, int $channels = 2, int $audioRate = 48000): ExtendedPromiseInterface + public function playRawStream($stream, int $channels = 2, int $audioRate = 48000): PromiseInterface { $deferred = new Deferred(); @@ -776,9 +773,9 @@ public function playRawStream($stream, int $channels = 2, int $audioRate = 48000 * @throws \RuntimeException * @throws \InvalidArgumentException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function playOggStream($stream): ExtendedPromiseInterface + public function playOggStream($stream): PromiseInterface { $deferred = new Deferred(); @@ -843,7 +840,7 @@ public function playOggStream($stream): ExtendedPromiseInterface // EOF for Ogg stream. if (null === $packet) { $this->reset(); - $deferred->resolve(); + $deferred->resolve(true); return; } @@ -868,7 +865,7 @@ public function playOggStream($stream): ExtendedPromiseInterface $this->readOpusTimer = $this->loop->addTimer($delay, $readOpus); }, function ($e) use ($deferred) { $this->reset(); - $deferred->resolve(); + $deferred->resolve(true); }); }; @@ -888,13 +885,13 @@ public function playOggStream($stream): ExtendedPromiseInterface * * @param resource|Process|Stream $stream The DCA stream to be sent. * - * @return ExtendedPromiseInterface + * @return PromiseInterface * @throws \Exception * * @deprecated 10.0.0 DCA is now deprecated in DiscordPHP, switch to using * `playOggStream` with raw Ogg Opus. */ - public function playDCAStream($stream): ExtendedPromiseInterface + public function playDCAStream($stream): PromiseInterface { $deferred = new Deferred(); @@ -970,7 +967,7 @@ public function playDCAStream($stream): ExtendedPromiseInterface $this->readOpusTimer = $this->loop->addTimer(($this->frameSize - 1) / 1000, $readOpus); }, function () use ($deferred) { $this->reset(); - $deferred->resolve(); + $deferred->resolve(true); }); }; diff --git a/src/Discord/WebSockets/Events/GuildCreate.php b/src/Discord/WebSockets/Events/GuildCreate.php index e5c574602..c4773b783 100644 --- a/src/Discord/WebSockets/Events/GuildCreate.php +++ b/src/Discord/WebSockets/Events/GuildCreate.php @@ -11,12 +11,12 @@ namespace Discord\WebSockets\Events; -use Discord\Helpers\Deferred; use Discord\Parts\Channel\Channel; use Discord\Parts\Guild\Guild; use Discord\Parts\User\Member; use Discord\WebSockets\Event; use Discord\Http\Endpoint; +use React\Promise\Deferred; use function React\Promise\all; @@ -119,9 +119,9 @@ public function handle($data) if (isset($lastUserId)) { $bind->addQuery('after', $lastUserId); } - $this->http->get($bind)->done(function ($bans) use (&$banPagination, $guildPart, $loadBans) { + $this->http->get($bind)->then(function ($bans) use (&$banPagination, $guildPart, $loadBans) { if (empty($bans)) { - $loadBans->resolve(); + $loadBans->resolve(true); return; } @@ -133,7 +133,7 @@ public function handle($data) } $banPagination($lastUserId); - }, [$loadBans, 'resolve']); + })->catch([$loadBans, 'resolve']); }; $banPagination(); yield $loadBans->promise(); diff --git a/src/Discord/functions.php b/src/Discord/functions.php index 3e0298f30..2a2a7a9dd 100644 --- a/src/Discord/functions.php +++ b/src/Discord/functions.php @@ -12,7 +12,6 @@ namespace Discord; use ArrayIterator; -use Discord\Helpers\Deferred; use Discord\Parts\Channel\Channel; use Discord\Parts\Channel\Message; use Discord\Parts\Guild\Role; @@ -21,6 +20,7 @@ use Discord\Parts\User\User; use React\EventLoop\Loop; use React\EventLoop\LoopInterface; +use React\Promise\Deferred; use React\Promise\Promise; use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\Options; @@ -313,7 +313,7 @@ function deferFind($array, callable $callback, $loop = null): Promise if (! $iterator->valid()) { $loop->cancelTimer($timer); - $deferred->reject(); + $deferred->reject((new \Exception('Invalid iterator.')); return; } From af627b7cbeab7e49d46c06dac553e674ae8a06b9 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Sun, 16 Jul 2023 23:31:20 +0200 Subject: [PATCH 02/19] Remove react/promise version restriction --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index ac79ab589..b00c80894 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,6 @@ "trafficcophp/bytebuffer": "^0.3", "monolog/monolog": "^2.1.1 || ^3.0", "react/event-loop": "^1.2", - "react/promise": "^2.2", "ext-json": "*", "ext-zlib": "*", "discord-php/http": "^10.1.7", From 625df80e49a67ee4b6bbedea170c5473835840e5 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Mon, 17 Jul 2023 06:05:47 +0200 Subject: [PATCH 03/19] Update functions.php --- src/Discord/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord/functions.php b/src/Discord/functions.php index 2a2a7a9dd..440fa8ab8 100644 --- a/src/Discord/functions.php +++ b/src/Discord/functions.php @@ -313,7 +313,7 @@ function deferFind($array, callable $callback, $loop = null): Promise if (! $iterator->valid()) { $loop->cancelTimer($timer); - $deferred->reject((new \Exception('Invalid iterator.')); + $deferred->reject((new \Exception('Loop done.')); return; } From 9cc6193d63a6c701508366f931bf602a59482641 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Mon, 17 Jul 2023 06:15:16 +0200 Subject: [PATCH 04/19] change then->cath to just then --- src/Discord/Discord.php | 12 ++++++------ src/Discord/Parts/Channel/Message.php | 4 ++-- src/Discord/Voice/VoiceClient.php | 4 ++-- src/Discord/WebSockets/Events/GuildCreate.php | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index 2fafd2cbb..50b6203e2 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -790,7 +790,7 @@ protected function handleDispatch(object $data): void if ($data->t == Event::MESSAGE_CREATE && mentioned($this->client->user, $new)) { $this->emit('mention', [$new, $this, $old]); } - })->catch(function ($e) use ($data) { + }, function ($e) use ($data) { if ($e instanceof \Error) { throw $e; } elseif ($e instanceof \Exception) { @@ -809,12 +809,12 @@ protected function handleDispatch(object $data): void $this->unparsedPackets[] = function () use (&$handler, &$deferred, &$data) { /** @var PromiseInterface */ $promise = coroutine([$handler, 'handle'], $data->d); - $promise->then([$deferred, 'resolve'])->catch([$deferred, 'reject']); + $promise->then([$deferred, 'resolve'], [$deferred, 'reject']); }; } else { /** @var PromiseInterface */ $promise = coroutine([$handler, 'handle'], $data->d); - $promise->then([$deferred, 'resolve'])->catch([$deferred, 'reject']); + $promise->then([$deferred, 'resolve'], [$deferred, 'reject']); } } @@ -1093,7 +1093,7 @@ protected function connectWs(): void /** @var PromiseInterface */ $promise = ($this->wsFactory)($this->gateway); - $promise->then([$this, 'handleWsConnection'])->catch([$this, 'handleWsConnectionFailed']); + $promise->then([$this, 'handleWsConnection'], [$this, 'handleWsConnectionFailed']); }); } @@ -1345,7 +1345,7 @@ protected function setGateway(?string $gateway = null): PromiseInterface $this->logger->info('Please contact the DiscordPHP devs at https://discord.gg/dphp or https://github.com/discord-php/DiscordPHP/issues if you are interrested in assisting us with sharding support development.'); } $buildParams($this->resume_gateway_url ?? $response->url, $response->session_start_limit); - })->catch(function ($e) use ($buildParams) { + }, function ($e) use ($buildParams) { // Can't access the API server so we will use the default gateway. $this->logger->warning('could not retrieve gateway, using default'); $buildParams('wss://gateway.discord.gg'); @@ -1356,7 +1356,7 @@ protected function setGateway(?string $gateway = null): PromiseInterface $deferred->promise()->then(function ($gateway) { $this->logger->info('gateway retrieved and set', $gateway); - })->catch(function ($e) { + }, function ($e) { $this->logger->error('error obtaining gateway', ['e' => $e->getMessage()]); }); diff --git a/src/Discord/Parts/Channel/Message.php b/src/Discord/Parts/Channel/Message.php index f3f92e665..ee5831ba1 100644 --- a/src/Discord/Parts/Channel/Message.php +++ b/src/Discord/Parts/Channel/Message.php @@ -889,7 +889,7 @@ public function delayedReply($message, int $delay, &$timer = null): PromiseInter $deferred = new Deferred(); $timer = $this->discord->getLoop()->addTimer($delay / 1000, function () use ($message, $deferred) { - $this->reply($message)->then([$deferred, 'resolve'])->catch([$deferred, 'reject']); + $this->reply($message)->then([$deferred, 'resolve'], [$deferred, 'reject']); }); return $deferred->promise(); @@ -910,7 +910,7 @@ public function delayedDelete(int $delay, &$timer = null): PromiseInterface $deferred = new Deferred(); $timer = $this->discord->getLoop()->addTimer($delay / 1000, function () use ($deferred) { - $this->delete()->then([$deferred, 'resolve'])->catch([$deferred, 'reject']); + $this->delete()->then([$deferred, 'resolve'], [$deferred, 'reject']); }); return $deferred->promise(); diff --git a/src/Discord/Voice/VoiceClient.php b/src/Discord/Voice/VoiceClient.php index a71018278..b3d9764b3 100644 --- a/src/Discord/Voice/VoiceClient.php +++ b/src/Discord/Voice/VoiceClient.php @@ -403,7 +403,7 @@ public function initSockets(): void /** @var PromiseInterface */ $promise = $wsfac("wss://{$this->endpoint}?v={$this->version}"); - $promise->then([$this, 'handleWebSocketConnection'])->catch([$this, 'handleWebSocketError']); + $promise->then([$this, 'handleWebSocketConnection'], [$this, 'handleWebSocketError']); } /** @@ -499,7 +499,7 @@ public function handleWebSocketConnection(WebSocket $ws): void }; $client->on('message', $decodeUDP); - })->catch(function ($e) { + }, function ($e) { $this->logger->error('error while connecting to udp', ['e' => $e->getMessage()]); $this->emit('error', [$e]); }); diff --git a/src/Discord/WebSockets/Events/GuildCreate.php b/src/Discord/WebSockets/Events/GuildCreate.php index c4773b783..e89128577 100644 --- a/src/Discord/WebSockets/Events/GuildCreate.php +++ b/src/Discord/WebSockets/Events/GuildCreate.php @@ -133,7 +133,7 @@ public function handle($data) } $banPagination($lastUserId); - })->catch([$loadBans, 'resolve']); + }, [$loadBans, 'resolve']); }; $banPagination(); yield $loadBans->promise(); From f40f91a07507f7c0265f567647d22c6f1b7fa40c Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Mon, 17 Jul 2023 16:56:04 +0200 Subject: [PATCH 05/19] remove duplicate use --- src/Discord/Discord.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index 50b6203e2..159834c42 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -51,7 +51,6 @@ use React\Cache\ArrayCache; use React\Promise\Deferred; use React\Promise\PromiseInterface; -use React\Promise\PromiseInterface; use React\Socket\Connector as SocketConnector; use Symfony\Component\OptionsResolver\OptionsResolver; From 0733f147ca2b70089c700faf5f59b0a7e116b6f6 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Mon, 17 Jul 2023 18:10:20 +0200 Subject: [PATCH 06/19] small fix --- src/Discord/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord/functions.php b/src/Discord/functions.php index 440fa8ab8..c060d2c31 100644 --- a/src/Discord/functions.php +++ b/src/Discord/functions.php @@ -313,7 +313,7 @@ function deferFind($array, callable $callback, $loop = null): Promise if (! $iterator->valid()) { $loop->cancelTimer($timer); - $deferred->reject((new \Exception('Loop done.')); + $deferred->reject(new \Exception('Loop done.'); return; } From 03d842e97f2bd37b385d1254f629e9a484348147 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Mon, 31 Jul 2023 19:26:11 +0200 Subject: [PATCH 07/19] Change PromiseInterface to Promise --- src/Discord/Builders/Components/Button.php | 4 +- .../Builders/Components/SelectMenu.php | 4 +- src/Discord/Discord.php | 18 ++-- src/Discord/Helpers/Buffer.php | 14 +-- src/Discord/Helpers/CacheWrapper.php | 30 +++---- src/Discord/Parts/Channel/Channel.php | 80 ++++++++--------- src/Discord/Parts/Channel/Message.php | 46 +++++----- src/Discord/Parts/Channel/Reaction.php | 12 +-- src/Discord/Parts/Channel/Webhook.php | 10 +-- src/Discord/Parts/Guild/Guild.php | 90 +++++++++---------- src/Discord/Parts/Guild/GuildTemplate.php | 6 +- src/Discord/Parts/Guild/ScheduledEvent.php | 6 +- src/Discord/Parts/Guild/Widget.php | 4 +- .../Parts/Interactions/Interaction.php | 62 ++++++------- src/Discord/Parts/Part.php | 6 +- src/Discord/Parts/Thread/Member.php | 6 +- src/Discord/Parts/Thread/Thread.php | 72 +++++++-------- src/Discord/Parts/User/Client.php | 6 +- src/Discord/Parts/User/Member.php | 40 ++++----- src/Discord/Parts/User/User.php | 16 ++-- .../Parts/WebSockets/MessageReaction.php | 8 +- src/Discord/Repository/AbstractRepository.php | 34 +++---- .../Repository/Channel/ReactionRepository.php | 6 +- .../Repository/Channel/ThreadRepository.php | 12 +-- .../Repository/Guild/BanRepository.php | 10 +-- .../Guild/GuildTemplateRepository.php | 6 +- .../Repository/Guild/MemberRepository.php | 8 +- .../Guild/ScheduledEventRepository.php | 6 +- src/Discord/Repository/GuildRepository.php | 6 +- src/Discord/Voice/OggPage.php | 6 +- src/Discord/Voice/OggStream.php | 14 +-- src/Discord/Voice/VoiceClient.php | 22 ++--- src/Discord/functions.php | 6 +- 33 files changed, 338 insertions(+), 338 deletions(-) diff --git a/src/Discord/Builders/Components/Button.php b/src/Discord/Builders/Components/Button.php index 480921bc7..9127005f5 100644 --- a/src/Discord/Builders/Components/Button.php +++ b/src/Discord/Builders/Components/Button.php @@ -15,7 +15,7 @@ use Discord\Parts\Guild\Emoji; use Discord\Parts\Interactions\Interaction; use Discord\WebSockets\Event; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use function Discord\poly_strlen; @@ -343,7 +343,7 @@ public function setListener(?callable $callback, Discord $discord, bool $oneOff } }; - if ($response instanceof PromiseInterface) { + if ($response instanceof Promise) { $response->then($ack); } else { $ack(); diff --git a/src/Discord/Builders/Components/SelectMenu.php b/src/Discord/Builders/Components/SelectMenu.php index cb557904e..70da37866 100644 --- a/src/Discord/Builders/Components/SelectMenu.php +++ b/src/Discord/Builders/Components/SelectMenu.php @@ -15,7 +15,7 @@ use Discord\Helpers\Collection; use Discord\Parts\Interactions\Interaction; use Discord\WebSockets\Event; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use function Discord\poly_strlen; @@ -263,7 +263,7 @@ public function setListener(?callable $callback, Discord $discord, bool $oneOff } }; - if ($response instanceof PromiseInterface) { + if ($response instanceof Promise) { $response->then($ack); } else { $ack(); diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index 159834c42..6546bf819 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -50,7 +50,7 @@ use Psr\Log\LoggerInterface; use React\Cache\ArrayCache; use React\Promise\Deferred; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use React\Socket\Connector as SocketConnector; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -469,7 +469,7 @@ protected function handleReady(object $data) $unavailable = []; foreach ($content->guilds as $guild) { - /** @var PromiseInterface */ + /** @var Promise */ $promise = coroutine([$event, 'handle'], $guild); $promise->then(function ($d) use (&$unavailable) { @@ -806,12 +806,12 @@ protected function handleDispatch(object $data): void if (! $this->emittedInit && (! in_array($data->t, $parse))) { $this->unparsedPackets[] = function () use (&$handler, &$deferred, &$data) { - /** @var PromiseInterface */ + /** @var Promise */ $promise = coroutine([$handler, 'handle'], $data->d); $promise->then([$deferred, 'resolve'], [$deferred, 'reject']); }; } else { - /** @var PromiseInterface */ + /** @var Promise */ $promise = coroutine([$handler, 'handle'], $data->d); $promise->then([$deferred, 'resolve'], [$deferred, 'reject']); } @@ -1090,7 +1090,7 @@ protected function connectWs(): void $this->logger->info('starting connection to websocket', ['gateway' => $this->gateway]); - /** @var PromiseInterface */ + /** @var Promise */ $promise = ($this->wsFactory)($this->gateway); $promise->then([$this, 'handleWsConnection'], [$this, 'handleWsConnectionFailed']); }); @@ -1213,9 +1213,9 @@ public function getVoiceClient(string $guild_id): ?VoiceClient * * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise */ - public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, ?LoggerInterface $logger = null, bool $check = true): PromiseInterface + public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, ?LoggerInterface $logger = null, bool $check = true): Promise { $deferred = new Deferred(); @@ -1309,9 +1309,9 @@ public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, * * @param string|null $gateway Gateway URL to set. * - * @return PromiseInterface + * @return Promise */ - protected function setGateway(?string $gateway = null): PromiseInterface + protected function setGateway(?string $gateway = null): Promise { $deferred = new Deferred(); $defaultSession = [ diff --git a/src/Discord/Helpers/Buffer.php b/src/Discord/Helpers/Buffer.php index 71fff963e..adf3ce533 100644 --- a/src/Discord/Helpers/Buffer.php +++ b/src/Discord/Helpers/Buffer.php @@ -15,7 +15,7 @@ use Evenement\EventEmitter; use React\EventLoop\LoopInterface; use React\Promise\Deferred; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use React\Stream\WritableStreamInterface; /** @@ -107,11 +107,11 @@ private function readRaw(int $length) * @param null|string $format Format to read the bytes in. See `pack()`. * @param int $timeout Time in milliseconds before the read times out. * - * @return PromiseInterface + * @return Promise * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function read(int $length, ?string $format = null, ?int $timeout = -1): PromiseInterface + public function read(int $length, ?string $format = null, ?int $timeout = -1): Promise { $deferred = new Deferred(); @@ -153,11 +153,11 @@ public function read(int $length, ?string $format = null, ?int $timeout = -1): P * * @param int $timeout Time in milliseconds before the read times out. * - * @return PromiseInterface + * @return Promise * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function readInt32(int $timeout = -1): PromiseInterface + public function readInt32(int $timeout = -1): Promise { return $this->read(4, 'l', $timeout); } @@ -167,11 +167,11 @@ public function readInt32(int $timeout = -1): PromiseInterface * * @param int $timeout Time in milliseconds before the read times out. * - * @return PromiseInterface + * @return Promise * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function readInt16(int $timeout = -1): PromiseInterface + public function readInt16(int $timeout = -1): Promise { return $this->read(2, 'v', $timeout); } diff --git a/src/Discord/Helpers/CacheWrapper.php b/src/Discord/Helpers/CacheWrapper.php index 3789f9197..5f25b75f1 100644 --- a/src/Discord/Helpers/CacheWrapper.php +++ b/src/Discord/Helpers/CacheWrapper.php @@ -14,7 +14,7 @@ use Discord\Discord; use Discord\Parts\Part; use React\Cache\ArrayCache; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Throwable; use WeakReference; @@ -108,7 +108,7 @@ public function __destruct() * @param string $key * @param mixed $default * - * @return PromiseInterface + * @return Promise */ public function get($key, $default = null) { @@ -128,7 +128,7 @@ public function get($key, $default = null) return reject($throwable); } - if ($result instanceof PromiseInterface) { + if ($result instanceof Promise) { return $result->then($handleValue); } @@ -141,7 +141,7 @@ public function get($key, $default = null) * @param string $key * @param Part $value * - * @return PromiseInterface + * @return Promise */ public function set($key, $value, $ttl = null) { @@ -162,7 +162,7 @@ public function set($key, $value, $ttl = null) return reject($throwable); } - if ($result instanceof PromiseInterface) { + if ($result instanceof Promise) { return $result->then($handleValue); } @@ -174,7 +174,7 @@ public function set($key, $value, $ttl = null) * * @param string $key * - * @return PromiseInterface|bool + * @return Promise|bool */ public function delete($key) { @@ -192,7 +192,7 @@ public function delete($key) return reject($throwable); } - if ($result instanceof PromiseInterface) { + if ($result instanceof Promise) { return $result->then($handleValue); } @@ -207,7 +207,7 @@ public function delete($key) * @param array $keys * @param ?Part $default * - * @return PromiseInterface + * @return Promise */ public function getMultiple(array $keys, $default = null) { @@ -230,7 +230,7 @@ public function getMultiple(array $keys, $default = null) return reject($throwable); } - if ($result instanceof PromiseInterface) { + if ($result instanceof Promise) { return $result->then($handleValue); } @@ -254,7 +254,7 @@ public function getMultiple(array $keys, $default = null) * @param Part[] $values * @param ?int $ttl * - * @return PromiseInterface + * @return Promise */ public function setMultiple(array $values, $ttl = null) { @@ -274,7 +274,7 @@ public function setMultiple(array $values, $ttl = null) * * @param array $keys * - * @return PromiseInterface + * @return Promise */ public function deleteMultiple(array $keys) { @@ -297,7 +297,7 @@ public function deleteMultiple(array $keys) return reject($throwable); } - if ($result instanceof PromiseInterface) { + if ($result instanceof Promise) { return $result->then($handleValue); } @@ -318,7 +318,7 @@ public function deleteMultiple(array $keys) * * For react/cache 0.5 polyfill. * - * @return PromiseInterface + * @return Promise */ public function clear() { @@ -332,7 +332,7 @@ public function clear() * * @param string $key * - * @return PromiseInterface + * @return Promise */ public function has($key) { @@ -354,7 +354,7 @@ public function has($key) return reject($throwable); } - if ($result instanceof PromiseInterface) { + if ($result instanceof Promise) { return $result->then($handleValue); } diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index 77460291e..fcc3d2a6f 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -38,7 +38,7 @@ use Discord\Repository\Channel\StageInstanceRepository; use Discord\Repository\Channel\ThreadRepository; use React\Promise\Deferred; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\OptionsResolver; use Traversable; @@ -97,7 +97,7 @@ * @property InviteRepository $invites Invites in the channel. * @property StageInstanceRepository $stage_instances Stage instances in the channel. * - * @method PromiseInterface sendMessage(MessageBuilder $builder) + * @method Promise sendMessage(MessageBuilder $builder) */ class Channel extends Part { @@ -293,9 +293,9 @@ protected function getLastPinTimestampAttribute(): ?Carbon * * @link https://discord.com/developers/docs/resources/channel#get-pinned-messages * - * @return PromiseInterface> + * @return Promise> */ - public function getPinnedMessages(): PromiseInterface + public function getPinnedMessages(): Promise { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_PINS, $this->id)) ->then(function ($responses) { @@ -321,9 +321,9 @@ public function getPinnedMessages(): PromiseInterface * * @throws InvalidOverwriteException * - * @return PromiseInterface + * @return Promise */ - public function setPermissions(Part $part, array $allow = [], array $deny = [], ?string $reason = null): PromiseInterface + public function setPermissions(Part $part, array $allow = [], array $deny = [], ?string $reason = null): Promise { if ($part instanceof Member) { $type = Overwrite::TYPE_MEMBER; @@ -362,9 +362,9 @@ public function setPermissions(Part $part, array $allow = [], array $deny = [], * @throws NoPermissionsException Missing manage_roles permission. * @throws InvalidOverwriteException Overwrite type is not member or role. * - * @return PromiseInterface + * @return Promise */ - public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = null): PromiseInterface + public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = null): Promise { if ($this->guild_id && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_roles) { @@ -408,13 +408,13 @@ public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = * @param int|null $position The new channel position, not relative to category. * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise * * @throws \RuntimeException * @throws \InvalidArgumentException * @throws NoPermissionsException Missing manage_channels permission in either channel. */ - public function setCategory($category, ?int $position = null, ?string $reason = null): PromiseInterface + public function setCategory($category, ?int $position = null, ?string $reason = null): Promise { if (! in_array($this->type, [self::TYPE_GUILD_TEXT, self::TYPE_GUILD_VOICE, self::TYPE_GUILD_ANNOUNCEMENT, self::TYPE_GUILD_FORUM])) { return reject(new \RuntimeException('You can only move Text, Voice, Announcement or Forum channel type.')); @@ -472,9 +472,9 @@ public function setCategory($category, ?int $position = null, ?string $reason = * @throws \RuntimeException * @throws NoPermissionsException Missing move_members permission. * - * @return PromiseInterface + * @return Promise */ - public function moveMember($member, ?string $reason = null): PromiseInterface + public function moveMember($member, ?string $reason = null): Promise { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot move a member in a text channel.')); @@ -507,9 +507,9 @@ public function moveMember($member, ?string $reason = null): PromiseInterface * @throws \RuntimeException * @throws NoPermissionsException Missing mute_members permission. * - * @return PromiseInterface + * @return Promise */ - public function muteMember($member, ?string $reason = null): PromiseInterface + public function muteMember($member, ?string $reason = null): Promise { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot mute a member in a text channel.')); @@ -542,9 +542,9 @@ public function muteMember($member, ?string $reason = null): PromiseInterface * @throws \RuntimeException * @throws NoPermissionsException Missing mute_members permission. * - * @return PromiseInterface + * @return Promise */ - public function unmuteMember($member, ?string $reason = null): PromiseInterface + public function unmuteMember($member, ?string $reason = null): Promise { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot unmute a member in a text channel.')); @@ -585,9 +585,9 @@ public function unmuteMember($member, ?string $reason = null): PromiseInterface * * @throws NoPermissionsException Missing create_instant_invite permission. * - * @return PromiseInterface + * @return Promise */ - public function createInvite($options = [], ?string $reason = null): PromiseInterface + public function createInvite($options = [], ?string $reason = null): Promise { if (! $this->canInvite()) { return reject(new \RuntimeException('You cannot create invite in this type of channel.')); @@ -651,9 +651,9 @@ public function createInvite($options = [], ?string $reason = null): PromiseInte * @throws \InvalidArgumentException * @throws NoPermissionsException Missing manage_messages permission. * - * @return PromiseInterface + * @return Promise */ - public function deleteMessages($messages, ?string $reason = null): PromiseInterface + public function deleteMessages($messages, ?string $reason = null): Promise { if (! is_array($messages) && ! ($messages instanceof Traversable)) { return reject(new \InvalidArgumentException('$messages must be an array or implement Traversable.')); @@ -706,9 +706,9 @@ public function deleteMessages($messages, ?string $reason = null): PromiseInterf * * @throws NoPermissionsException Missing manage_messages permission. * - * @return PromiseInterface + * @return Promise */ - public function limitDelete(int $value, ?string $reason = null): PromiseInterface + public function limitDelete(int $value, ?string $reason = null): Promise { if ($botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -732,9 +732,9 @@ public function limitDelete(int $value, ?string $reason = null): PromiseInterfac * Or also missing `connect` permission for text in voice. * @throws \RangeException * - * @return PromiseInterface> + * @return Promise> */ - public function getMessageHistory(array $options): PromiseInterface + public function getMessageHistory(array $options): Promise { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->read_message_history) { @@ -796,9 +796,9 @@ public function getMessageHistory(array $options): PromiseInterface * @throws NoPermissionsException Missing manage_messages permission. * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise */ - public function pinMessage(Message $message, ?string $reason = null): PromiseInterface + public function pinMessage(Message $message, ?string $reason = null): Promise { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -837,9 +837,9 @@ public function pinMessage(Message $message, ?string $reason = null): PromiseInt * @throws NoPermissionsException Missing manage_messages permission. * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise */ - public function unpinMessage(Message $message, ?string $reason = null): PromiseInterface + public function unpinMessage(Message $message, ?string $reason = null): Promise { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -967,11 +967,11 @@ protected function getDefaultReactionEmojiAttribute(): ?Reaction * create_public_threads when creating a public thread. * send_messages when creating a forum post. * - * @return PromiseInterface + * @return Promise * * @since 10.0.0 Arguments for `$name`, `$private` and `$auto_archive_duration` are now inside `$options` */ - public function startThread(array|string $options, string|null|bool $reason = null, int $_auto_archive_duration = 1440, ?string $_reason = null): PromiseInterface + public function startThread(array|string $options, string|null|bool $reason = null, int $_auto_archive_duration = 1440, ?string $_reason = null): Promise { // Old v7 signature if (is_string($options)) { @@ -1124,9 +1124,9 @@ public function startThread(array|string $options, string|null|bool $reason = nu * @throws \RuntimeException * @throws NoPermissionsException Missing various permissions depending on the message body. * - * @return PromiseInterface + * @return Promise */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): Promise { // Backwards compatible support for old `sendMessage` function signature. if (! ($message instanceof MessageBuilder)) { @@ -1190,9 +1190,9 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @param Embed $embed Embed to send. * - * @return PromiseInterface + * @return Promise */ - public function sendEmbed(Embed $embed): PromiseInterface + public function sendEmbed(Embed $embed): Promise { return $this->sendMessage(MessageBuilder::new() ->addEmbed($embed)); @@ -1210,9 +1210,9 @@ public function sendEmbed(Embed $embed): PromiseInterface * @param string|null $content Message content to send with the file. * @param bool $tts Whether to send the message with TTS. * - * @return PromiseInterface + * @return Promise */ - public function sendFile(string $filepath, ?string $filename = null, ?string $content = null, bool $tts = false): PromiseInterface + public function sendFile(string $filepath, ?string $filename = null, ?string $content = null, bool $tts = false): Promise { $builder = MessageBuilder::new() ->setTts($tts) @@ -1232,9 +1232,9 @@ public function sendFile(string $filepath, ?string $filename = null, ?string $co * * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise */ - public function broadcastTyping(): PromiseInterface + public function broadcastTyping(): Promise { if (! $this->isTextBased()) { return reject(new \RuntimeException('You cannot broadcast typing to a voice channel.')); @@ -1251,9 +1251,9 @@ public function broadcastTyping(): PromiseInterface * @param int $options['time'] Time in milliseconds until the collector finishes or false. * @param int $options['limit'] The amount of messages allowed or false. * - * @return PromiseInterface> + * @return Promise> */ - public function createMessageCollector(callable $filter, array $options = []): PromiseInterface + public function createMessageCollector(callable $filter, array $options = []): Promise { $deferred = new Deferred(); $messages = new Collection([], null, null); diff --git a/src/Discord/Parts/Channel/Message.php b/src/Discord/Parts/Channel/Message.php index ee5831ba1..4a00607e6 100644 --- a/src/Discord/Parts/Channel/Message.php +++ b/src/Discord/Parts/Channel/Message.php @@ -32,7 +32,7 @@ use Discord\Repository\Channel\ReactionRepository; use React\EventLoop\TimerInterface; use React\Promise\Deferred; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\OptionsResolver; use function React\Promise\reject; @@ -739,11 +739,11 @@ public function getLinkAttribute(): ?string * @throws \RuntimeException Channel type is not guild text or news. * @throws NoPermissionsException Missing create_public_threads permission to create or manage_threads permission to set rate_limit_per_user. * - * @return PromiseInterface + * @return Promise * * @since 10.0.0 Arguments for `$name` and `$auto_archive_duration` are now inside `$options` */ - public function startThread(array|string $options, string|null|int $reason = null, ?string $_reason = null): PromiseInterface + public function startThread(array|string $options, string|null|int $reason = null, ?string $_reason = null): Promise { // Old v7 signature if (is_string($options)) { @@ -819,9 +819,9 @@ public function startThread(array|string $options, string|null|int $reason = nul * * @param string|MessageBuilder $message The reply message. * - * @return PromiseInterface + * @return Promise */ - public function reply($message): PromiseInterface + public function reply($message): Promise { $channel = $this->channel; @@ -844,9 +844,9 @@ public function reply($message): PromiseInterface * send_messages if this message author is the bot. * manage_messages if this message author is other user. * - * @return PromiseInterface + * @return Promise */ - public function crosspost(): PromiseInterface + public function crosspost(): Promise { if ($this->crossposted) { return reject(new \RuntimeException('This message has already been crossposted.')); @@ -882,9 +882,9 @@ public function crosspost(): PromiseInterface * @param int $delay Delay after text will be sent in milliseconds. * @param TimerInterface &$timer Delay timer passed by reference. * - * @return PromiseInterface + * @return Promise */ - public function delayedReply($message, int $delay, &$timer = null): PromiseInterface + public function delayedReply($message, int $delay, &$timer = null): Promise { $deferred = new Deferred(); @@ -905,7 +905,7 @@ public function delayedReply($message, int $delay, &$timer = null): PromiseInter * * @return ExtendedPromseInterface */ - public function delayedDelete(int $delay, &$timer = null): PromiseInterface + public function delayedDelete(int $delay, &$timer = null): Promise { $deferred = new Deferred(); @@ -925,9 +925,9 @@ public function delayedDelete(int $delay, &$timer = null): PromiseInterface * * @throws NoPermissionsException Missing read_message_history permission. * - * @return PromiseInterface + * @return Promise */ - public function react($emoticon): PromiseInterface + public function react($emoticon): Promise { if ($emoticon instanceof Emoji) { $emoticon = $emoticon->toReactionString(); @@ -956,9 +956,9 @@ public function react($emoticon): PromiseInterface * @throws \UnexpectedValueException Invalid reaction `$type`. * @throws NoPermissionsException Missing manage_messages permission when deleting others reaction. * - * @return PromiseInterface + * @return Promise */ - public function deleteReaction(int $type, $emoticon = null, ?string $id = null): PromiseInterface + public function deleteReaction(int $type, $emoticon = null, ?string $id = null): Promise { if ($emoticon instanceof Emoji) { $emoticon = $emoticon->toReactionString(); @@ -1000,9 +1000,9 @@ public function deleteReaction(int $type, $emoticon = null, ?string $id = null): * * @param MessageBuilder $message Contains the new contents of the message. Note that fields not specified in the builder will not be overwritten. * - * @return PromiseInterface + * @return Promise */ - public function edit(MessageBuilder $message): PromiseInterface + public function edit(MessageBuilder $message): Promise { return $this->_edit($message)->then(function ($response) { $this->fill((array) $response); @@ -1011,7 +1011,7 @@ public function edit(MessageBuilder $message): PromiseInterface }); } - private function _edit(MessageBuilder $message): PromiseInterface + private function _edit(MessageBuilder $message): Promise { if ($message->requiresMultipart()) { $multipart = $message->toMultipart(); @@ -1027,12 +1027,12 @@ private function _edit(MessageBuilder $message): PromiseInterface * * @link https://discord.com/developers/docs/resources/channel#delete-message * - * @return PromiseInterface + * @return Promise * * @throws \RuntimeException This type of message cannot be deleted. * @throws NoPermissionsException Missing manage_messages permission when deleting others message. */ - public function delete(): PromiseInterface + public function delete(): Promise { if (! $this->isDeletable()) { return reject(new \RuntimeException("Cannot delete this type of message: {$this->type}", 50021)); @@ -1055,9 +1055,9 @@ public function delete(): PromiseInterface * @param int $options['time'] Time in milliseconds until the collector finishes or false. * @param int $options['limit'] The amount of reactions allowed or false. * - * @return PromiseInterface> + * @return Promise> */ - public function createReactionCollector(callable $filter, array $options = []): PromiseInterface + public function createReactionCollector(callable $filter, array $options = []): Promise { $deferred = new Deferred(); $reactions = new Collection([], null, null); @@ -1106,9 +1106,9 @@ public function createReactionCollector(callable $filter, array $options = []): * * @param Embed $embed * - * @return PromiseInterface + * @return Promise */ - public function addEmbed(Embed $embed): PromiseInterface + public function addEmbed(Embed $embed): Promise { return $this->edit(MessageBuilder::new() ->addEmbed($embed)); diff --git a/src/Discord/Parts/Channel/Reaction.php b/src/Discord/Parts/Channel/Reaction.php index b12f3b23d..f9e780e23 100644 --- a/src/Discord/Parts/Channel/Reaction.php +++ b/src/Discord/Parts/Channel/Reaction.php @@ -17,7 +17,7 @@ use Discord\Parts\Guild\Guild; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\OptionsResolver; use function Discord\normalizePartId; @@ -70,7 +70,7 @@ public function isPartial(): bool /** * {@inheritDoc} */ - public function fetch(): PromiseInterface + public function fetch(): Promise { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_MESSAGE, $this->channel_id, $this->message_id)) ->then(function ($message) { @@ -101,9 +101,9 @@ protected function getIdAttribute(): string * * @link https://discord.com/developers/docs/resources/channel#get-reactions * - * @return PromiseInterface + * @return Promise */ - public function getUsers(array $options = []): PromiseInterface + public function getUsers(array $options = []): Promise { $query = Endpoint::bind(Endpoint::MESSAGE_REACTION_EMOJI, $this->channel_id, $this->message_id, urlencode($this->emoji->id === null ? $this->emoji->name : "{$this->emoji->name}:{$this->emoji->id}")); @@ -144,9 +144,9 @@ public function getUsers(array $options = []): PromiseInterface * * @see Message::getUsers() * - * @return PromiseInterface + * @return Promise */ - public function getAllUsers(): PromiseInterface + public function getAllUsers(): Promise { $response = Collection::for(User::class); $getUsers = function ($after = null) use (&$getUsers, $response) { diff --git a/src/Discord/Parts/Channel/Webhook.php b/src/Discord/Parts/Channel/Webhook.php index 2c585a623..6e97fca90 100644 --- a/src/Discord/Parts/Channel/Webhook.php +++ b/src/Discord/Parts/Channel/Webhook.php @@ -18,7 +18,7 @@ use Discord\Parts\Part; use Discord\Parts\User\User; use Discord\Repository\Channel\WebhookMessageRepository; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -85,9 +85,9 @@ class Webhook extends Part * @param MessageBuilder|array $data * @param array $queryparams Query string params to add to the request. * - * @return PromiseInterface + * @return Promise */ - public function execute($data, array $queryparams = []): PromiseInterface + public function execute($data, array $queryparams = []): Promise { $endpoint = Endpoint::bind(Endpoint::WEBHOOK_EXECUTE, $this->id, $this->token); @@ -129,9 +129,9 @@ public function execute($data, array $queryparams = []): PromiseInterface * @param MessageBuilder $builder The new message. * @param array $queryparams Query string params to add to the request. * - * @return PromiseInterface + * @return Promise */ - public function updateMessage(string $message_id, MessageBuilder $builder, array $queryparams = []): PromiseInterface + public function updateMessage(string $message_id, MessageBuilder $builder, array $queryparams = []): Promise { $endpoint = Endpoint::bind(Endpoint::WEBHOOK_MESSAGE, $this->id, $this->token, $message_id); diff --git a/src/Discord/Parts/Guild/Guild.php b/src/Discord/Parts/Guild/Guild.php index b076b0092..e697db889 100644 --- a/src/Discord/Parts/Guild/Guild.php +++ b/src/Discord/Parts/Guild/Guild.php @@ -39,7 +39,7 @@ use Discord\Repository\Guild\ScheduledEventRepository; use Discord\Repository\Guild\GuildTemplateRepository; use Discord\Repository\Guild\IntegrationRepository; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use ReflectionClass; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -399,9 +399,9 @@ protected function setStickersAttribute(?array $stickers): void * * @throws NoPermissionsException Missing manage_guild permission. * - * @return PromiseInterface + * @return Promise */ - public function getInvites(): PromiseInterface + public function getInvites(): Promise { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_guild) { @@ -429,9 +429,9 @@ public function getInvites(): PromiseInterface * * @throws NoPermissionsException Missing ban_members permission. * - * @return PromiseInterface + * @return Promise */ - public function unban($user): PromiseInterface + public function unban($user): Promise { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->ban_members) { @@ -720,9 +720,9 @@ protected function getFeatureWelcomeScreenEnabledAttribute(): bool * * @link https://discord.com/developers/docs/resources/voice#list-voice-regions * - * @return PromiseInterface + * @return Promise */ - public function getVoiceRegions(): PromiseInterface + public function getVoiceRegions(): Promise { if (null !== $this->regions) { return resolve($this->regions); @@ -747,9 +747,9 @@ public function getVoiceRegions(): PromiseInterface * * @throws NoPermissionsException Missing manage_roles permission. * - * @return PromiseInterface + * @return Promise */ - public function createRole(array $data = [], ?string $reason = null): PromiseInterface + public function createRole(array $data = [], ?string $reason = null): Promise { $botperms = $this->getBotPermissions(); @@ -775,9 +775,9 @@ public function createRole(array $data = [], ?string $reason = null): PromiseInt * @throws NoPermissionsException Missing manage_guild_expressions permission. * @throws FileNotFoundException File does not exist. * - * @return PromiseInterface + * @return Promise */ - public function createEmoji(array $options, ?string $filepath = null, ?string $reason = null): PromiseInterface + public function createEmoji(array $options, ?string $filepath = null, ?string $reason = null): Promise { $resolver = new OptionsResolver(); $resolver @@ -851,9 +851,9 @@ public function createEmoji(array $options, ?string $filepath = null, ?string $r * @throws \DomainException File format is not PNG, APNG, or Lottie JSON. * @throws \RuntimeException Guild is not verified or partnered to upload Lottie stickers. * - * @return PromiseInterface + * @return Promise */ - public function createSticker(array $options, string $filepath, ?string $reason = null): PromiseInterface + public function createSticker(array $options, string $filepath, ?string $reason = null): Promise { $resolver = new OptionsResolver(); $resolver @@ -951,9 +951,9 @@ public function createSticker(array $options, string $filepath, ?string $reason /** * Leaves the guild. * - * @return PromiseInterface + * @return Promise */ - public function leave(): PromiseInterface + public function leave(): Promise { return $this->discord->guilds->leave($this->id); } @@ -966,9 +966,9 @@ public function leave(): PromiseInterface * * @throws \RuntimeException Ownership not transferred correctly. * - * @return PromiseInterface + * @return Promise */ - public function transferOwnership($member, ?string $reason = null): PromiseInterface + public function transferOwnership($member, ?string $reason = null): Promise { if ($member instanceof Member) { $member = $member->id; @@ -993,11 +993,11 @@ public function transferOwnership($member, ?string $reason = null): PromiseInter * * @deprecated 10.0.0 Use `Channel::$rtc_region`. * - * @return PromiseInterface + * @return Promise * * @see Guild::REGION_DEFAULT The default region. */ - public function validateRegion(): PromiseInterface + public function validateRegion(): Promise { return $this->getVoiceRegions()->then(function () { $regions = $this->regions->map(function ($region) { @@ -1026,9 +1026,9 @@ public function validateRegion(): PromiseInterface * * @throws NoPermissionsException Missing view_audit_log permission. * - * @return PromiseInterface + * @return Promise */ - public function getAuditLog(array $options = []): PromiseInterface + public function getAuditLog(array $options = []): Promise { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1092,9 +1092,9 @@ public function getBotPermissions(): ?RolePermission * * @throws NoPermissionsException Missing manage_roles permission. * - * @return PromiseInterface + * @return Promise */ - public function updateRolePositions(array $roles): PromiseInterface + public function updateRolePositions(array $roles): Promise { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_roles) { @@ -1135,9 +1135,9 @@ public function updateRolePositions(array $roles): PromiseInterface * @param string|null $options['query'] Query string to match username(s) and nickname(s) against * @param int|null $options['limit'] How many entries are returned (default 1, minimum 1, maximum 1000) * - * @return PromiseInterface + * @return Promise */ - public function searchMembers(array $options): PromiseInterface + public function searchMembers(array $options): Promise { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1182,9 +1182,9 @@ public function searchMembers(array $options): PromiseInterface * * @throws NoPermissionsException Missing kick_members permission. * - * @return PromiseInterface The number of members that would be removed. + * @return Promise The number of members that would be removed. */ - public function getPruneCount(array $options = []): PromiseInterface + public function getPruneCount(array $options = []): Promise { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1238,9 +1238,9 @@ public function getPruneCount(array $options = []): PromiseInterface * * @throws NoPermissionsException Missing kick_members permission. * - * @return PromiseInterface The number of members that were removed in the prune operation. + * @return Promise The number of members that were removed in the prune operation. */ - public function beginPrune(array $options = [], ?string $reason = null): PromiseInterface + public function beginPrune(array $options = [], ?string $reason = null): Promise { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1289,9 +1289,9 @@ public function beginPrune(array $options = [], ?string $reason = null): Promise * * @throws NoPermissionsException Missing manage_guild permission when the welcome screen is not enabled. * - * @return PromiseInterface + * @return Promise */ - public function getWelcomeScreen(bool $fresh = false): PromiseInterface + public function getWelcomeScreen(bool $fresh = false): Promise { if (! $this->feature_welcome_screen_enabled) { $botperms = $this->getBotPermissions(); @@ -1337,9 +1337,9 @@ protected function getWelcomeScreenAttribute(): ?WelcomeScreen * * @throws NoPermissionsException Missing manage_guild permission. * - * @return PromiseInterface The updated Welcome Screen. + * @return Promise The updated Welcome Screen. */ - public function updateWelcomeScreen(array $options): PromiseInterface + public function updateWelcomeScreen(array $options): Promise { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1381,9 +1381,9 @@ public function updateWelcomeScreen(array $options): PromiseInterface * * @throws NoPermissionsException Missing manage_guild permission. * - * @return PromiseInterface + * @return Promise */ - public function getWidgetSettings(): PromiseInterface + public function getWidgetSettings(): Promise { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_guild) { @@ -1411,9 +1411,9 @@ public function getWidgetSettings(): PromiseInterface * * @throws NoPermissionsException Missing manage_guild permission. * - * @return PromiseInterface The updated guild widget object. + * @return Promise The updated guild widget object. */ - public function updateWidgetSettings(array $options, ?string $reason = null): PromiseInterface + public function updateWidgetSettings(array $options, ?string $reason = null): Promise { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1448,9 +1448,9 @@ public function updateWidgetSettings(array $options, ?string $reason = null): Pr * * @link https://discord.com/developers/docs/resources/guild#get-guild-widget * - * @return PromiseInterface + * @return Promise */ - public function getWidget(): PromiseInterface + public function getWidget(): Promise { return $this->factory->part(Widget::class, ['id' => $this->id])->fetch(); } @@ -1463,9 +1463,9 @@ public function getWidget(): PromiseInterface * @throws \RuntimeException No possible channels to create Invite on. * @throws NoPermissionsException * - * @return PromiseInterface + * @return Promise */ - public function createInvite(...$args): PromiseInterface + public function createInvite(...$args): Promise { $channel = $this->channels->find(function (Channel $channel) { if ($channel->canInvite()) { @@ -1494,9 +1494,9 @@ public function createInvite(...$args): PromiseInterface * @param int $level The new MFA level `Guild::MFA_NONE` or `Guild::MFA_ELEVATED`. * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface This guild. + * @return Promise This guild. */ - public function updateMFALevel(int $level, ?string $reason = null): PromiseInterface + public function updateMFALevel(int $level, ?string $reason = null): Promise { $headers = []; if (isset($reason)) { @@ -1525,9 +1525,9 @@ public function updateMFALevel(int $level, ?string $reason = null): PromiseInter * administrator for COMMUNITY or DISCOVERABLE. * manage_guild for INVITES_DISABLED or RAID_ALERTS_ENABLED. * - * @return PromiseInterface This guild. + * @return Promise This guild. */ - public function setFeatures(array $features, ?string $reason = null): PromiseInterface + public function setFeatures(array $features, ?string $reason = null): Promise { if ($botperms = $this->getBotPermissions()) { if ((isset($features['COMMUNITY']) || isset($features['DISCOVERABLE'])) && ! $botperms->administrator) { diff --git a/src/Discord/Parts/Guild/GuildTemplate.php b/src/Discord/Parts/Guild/GuildTemplate.php index 75c2993a4..f6d9e1871 100644 --- a/src/Discord/Parts/Guild/GuildTemplate.php +++ b/src/Discord/Parts/Guild/GuildTemplate.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -130,9 +130,9 @@ protected function getUpdatedAtAttribute(): Carbon * @param string $options['name'] The name of the guild (2-100 characters). * @param string|null $options['icon'] The base64 128x128 image for the guild icon. * - * @return PromiseInterface + * @return Promise */ - public function createGuild($options = []): PromiseInterface + public function createGuild($options = []): Promise { $resolver = new OptionsResolver(); $resolver diff --git a/src/Discord/Parts/Guild/ScheduledEvent.php b/src/Discord/Parts/Guild/ScheduledEvent.php index 429330633..d16082e66 100644 --- a/src/Discord/Parts/Guild/ScheduledEvent.php +++ b/src/Discord/Parts/Guild/ScheduledEvent.php @@ -17,7 +17,7 @@ use Discord\Parts\Channel\Channel; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\OptionsResolver; use function React\Promise\reject; @@ -95,9 +95,9 @@ class ScheduledEvent extends Part * * @throws \RangeException * - * @return PromiseInterface + * @return Promise */ - public function getUsers(array $options): PromiseInterface + public function getUsers(array $options): Promise { $resolver = new OptionsResolver(); $resolver->setDefaults(['limit' => 100, 'with_member' => false]); diff --git a/src/Discord/Parts/Guild/Widget.php b/src/Discord/Parts/Guild/Widget.php index adcff1596..332093df2 100644 --- a/src/Discord/Parts/Guild/Widget.php +++ b/src/Discord/Parts/Guild/Widget.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Http\Http; use Discord\Parts\Part; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * A Widget of a Guild. @@ -86,7 +86,7 @@ class Widget extends Part /** * {@inheritDoc} */ - public function fetch(): PromiseInterface + public function fetch(): Promise { return $this->http->get(Endpoint::bind(Endpoint::GUILD_WIDGET, $this->id)) ->then(function ($response) { diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index 208f6c979..eb7c21f1b 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -29,7 +29,7 @@ use Discord\Parts\User\Member; use Discord\Parts\User\User; use Discord\WebSockets\Event; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use function Discord\poly_strlen; use function React\Promise\reject; @@ -225,9 +225,9 @@ protected function getAppPermissionsAttribute(): ?ChannelPermission * * @throws \LogicException Interaction is not Message Component or Modal Submit. * - * @return PromiseInterface + * @return Promise */ - public function acknowledge(): PromiseInterface + public function acknowledge(): Promise { if ($this->type == InteractionType::APPLICATION_COMMAND) { return $this->acknowledgeWithResponse(); @@ -252,9 +252,9 @@ public function acknowledge(): PromiseInterface * * @throws \LogicException Interaction is not Application Command, Message Component, or Modal Submit. * - * @return PromiseInterface + * @return Promise */ - public function acknowledgeWithResponse(bool $ephemeral = false): PromiseInterface + public function acknowledgeWithResponse(bool $ephemeral = false): Promise { if (! in_array($this->type, [InteractionType::APPLICATION_COMMAND, InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only acknowledge application command, message component, or modal submit interactions.')); @@ -276,9 +276,9 @@ public function acknowledgeWithResponse(bool $ephemeral = false): PromiseInterfa * * @throws \LogicException Interaction is not Message Component. * - * @return PromiseInterface + * @return Promise */ - public function updateMessage(MessageBuilder $builder): PromiseInterface + public function updateMessage(MessageBuilder $builder): Promise { if (! in_array($this->type, [InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only update messages that occur due to a message component interaction.')); @@ -297,9 +297,9 @@ public function updateMessage(MessageBuilder $builder): PromiseInterface * * @throws \RuntimeException Interaction is not created yet. * - * @return PromiseInterface + * @return Promise */ - public function getOriginalResponse(): PromiseInterface + public function getOriginalResponse(): Promise { if (! $this->created) { return reject(new \RuntimeException('Interaction has not been created yet.')); @@ -322,15 +322,15 @@ public function getOriginalResponse(): PromiseInterface * * @throws \RuntimeException Interaction is not responded yet. * - * @return PromiseInterface + * @return Promise */ - public function updateOriginalResponse(MessageBuilder $builder): PromiseInterface + public function updateOriginalResponse(MessageBuilder $builder): Promise { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); } - return (function () use ($builder): PromiseInterface { + return (function () use ($builder): Promise { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -350,9 +350,9 @@ public function updateOriginalResponse(MessageBuilder $builder): PromiseInterfac * * @throws \RuntimeException Interaction is not responded yet. * - * @return PromiseInterface + * @return Promise */ - public function deleteOriginalResponse(): PromiseInterface + public function deleteOriginalResponse(): Promise { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); @@ -371,9 +371,9 @@ public function deleteOriginalResponse(): PromiseInterface * * @throws \RuntimeException Interaction is not responded yet. * - * @return PromiseInterface + * @return Promise */ - public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = false): PromiseInterface + public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = false): Promise { if (! $this->responded && $this->type != InteractionType::MESSAGE_COMPONENT) { return reject(new \RuntimeException('Cannot create a follow-up message as the interaction has not been responded to.')); @@ -383,7 +383,7 @@ public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = f $builder->_setFlags(Message::FLAG_EPHEMERAL); } - return (function () use ($builder): PromiseInterface { + return (function () use ($builder): Promise { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -406,9 +406,9 @@ public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = f * * @throws \LogicException Interaction is not Application Command, Message Component, or Modal Submit. * - * @return PromiseInterface + * @return Promise */ - public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = false): PromiseInterface + public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = false): Promise { if (! in_array($this->type, [InteractionType::APPLICATION_COMMAND, InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only acknowledge application command, message component, or modal submit interactions.')); @@ -437,9 +437,9 @@ public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = fa * * @throws \RuntimeException Interaction is already responded. * - * @return PromiseInterface + * @return Promise */ - protected function respond(array $payload, ?Multipart $multipart = null): PromiseInterface + protected function respond(array $payload, ?Multipart $multipart = null): Promise { if ($this->responded) { return reject(new \RuntimeException('Interaction has already been responded to.')); @@ -472,7 +472,7 @@ protected function respond(array $payload, ?Multipart $multipart = null): Promis * * @throws \RuntimeException Interaction is not responded yet. * - * @return PromiseInterface + * @return Promise */ public function updateFollowUpMessage(string $message_id, MessageBuilder $builder) { @@ -480,7 +480,7 @@ public function updateFollowUpMessage(string $message_id, MessageBuilder $builde return reject(new \RuntimeException('Cannot create a follow-up message as the interaction has not been responded to.')); } - return (function () use ($message_id, $builder): PromiseInterface { + return (function () use ($message_id, $builder): Promise { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -502,9 +502,9 @@ public function updateFollowUpMessage(string $message_id, MessageBuilder $builde * * @throws \RuntimeException Interaction is not created yet. * - * @return PromiseInterface + * @return Promise */ - public function getFollowUpMessage(string $message_id): PromiseInterface + public function getFollowUpMessage(string $message_id): Promise { if (! $this->created) { return reject(new \RuntimeException('Interaction has not been created yet.')); @@ -527,9 +527,9 @@ public function getFollowUpMessage(string $message_id): PromiseInterface * * @throws \RuntimeException Interaction is not responded yet. * - * @return PromiseInterface + * @return Promise */ - public function deleteFollowUpMessage(string $message_id): PromiseInterface + public function deleteFollowUpMessage(string $message_id): Promise { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); @@ -547,9 +547,9 @@ public function deleteFollowUpMessage(string $message_id): PromiseInterface * * @throws \LogicException Interaction is not Autocomplete. * - * @return PromiseInterface + * @return Promise */ - public function autoCompleteResult(array $choices): PromiseInterface + public function autoCompleteResult(array $choices): Promise { if ($this->type != InteractionType::APPLICATION_COMMAND_AUTOCOMPLETE) { return reject(new \LogicException('You can only respond command option results with auto complete interactions.')); @@ -574,9 +574,9 @@ public function autoCompleteResult(array $choices): PromiseInterface * @throws \LogicException Interaction is Ping or Modal Submit. * @throws \LengthException Modal title is longer than 45 characters. * - * @return PromiseInterface + * @return Promise */ - public function showModal(string $title, string $custom_id, array $components, ?callable $submit = null): PromiseInterface + public function showModal(string $title, string $custom_id, array $components, ?callable $submit = null): Promise { if (in_array($this->type, [InteractionType::PING, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You cannot pop up a modal from a ping or modal submit interaction.')); diff --git a/src/Discord/Parts/Part.php b/src/Discord/Parts/Part.php index c13909d16..17e39b181 100644 --- a/src/Discord/Parts/Part.php +++ b/src/Discord/Parts/Part.php @@ -17,7 +17,7 @@ use Discord\Factory\Factory; use Discord\Http\Http; use JsonSerializable; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * This class is the base of all objects that are returned. All "Parts" extend @@ -149,9 +149,9 @@ public function isPartial(): bool * * @throws \RuntimeException The part is not fetchable. * - * @return PromiseInterface + * @return Promise */ - public function fetch(): PromiseInterface + public function fetch(): Promise { throw new \RuntimeException('This part is not fetchable.'); } diff --git a/src/Discord/Parts/Thread/Member.php b/src/Discord/Parts/Thread/Member.php index a429a5553..cf673b0f6 100644 --- a/src/Discord/Parts/Thread/Member.php +++ b/src/Discord/Parts/Thread/Member.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * Represents a member that belongs to a thread. Not the same as a user nor a @@ -70,9 +70,9 @@ protected function getJoinTimestampAttribute(): Carbon * * @link https://discord.com/developers/docs/resources/channel#remove-thread-member * - * @return PromiseInterface + * @return Promise */ - public function remove(): PromiseInterface + public function remove(): Promise { return $this->http->delete(Endpoint::bind(Endpoint::THREAD_MEMBER, $this->id, $this->user_id)); } diff --git a/src/Discord/Parts/Thread/Thread.php b/src/Discord/Parts/Thread/Thread.php index 6079e2c93..3bc531aae 100644 --- a/src/Discord/Parts/Thread/Thread.php +++ b/src/Discord/Parts/Thread/Thread.php @@ -29,7 +29,7 @@ use Discord\Repository\Thread\MemberRepository; use Discord\WebSockets\Event; use React\Promise\Deferred; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\OptionsResolver; use Traversable; @@ -74,7 +74,7 @@ * @property MessageRepository $messages Repository of messages sent in the thread. * @property MemberRepository $members Repository of members in the thread. * - * @method PromiseInterface sendMessage(MessageBuilder $builder) + * @method Promise sendMessage(MessageBuilder $builder) */ class Thread extends Part { @@ -304,9 +304,9 @@ protected function getCreateTimestampAttribute(): ?Carbon * * @link https://discord.com/developers/docs/resources/channel#join-thread * - * @return PromiseInterface + * @return Promise */ - public function join(): PromiseInterface + public function join(): Promise { return $this->http->put(Endpoint::bind(Endpoint::THREAD_MEMBER_ME, $this->id)); } @@ -318,9 +318,9 @@ public function join(): PromiseInterface * * @param User|Member|string $user User to add. Can be one of the user objects or a user ID. * - * @return PromiseInterface + * @return Promise */ - public function addMember($user): PromiseInterface + public function addMember($user): Promise { if ($user instanceof User || $user instanceof Member) { $user = $user->id; @@ -334,9 +334,9 @@ public function addMember($user): PromiseInterface * * @link https://discord.com/developers/docs/resources/channel#leave-thread * - * @return PromiseInterface + * @return Promise */ - public function leave(): PromiseInterface + public function leave(): Promise { return $this->http->delete(Endpoint::bind(Endpoint::THREAD_MEMBER_ME, $this->id)); } @@ -348,9 +348,9 @@ public function leave(): PromiseInterface * * @param User|Member|ThreadMember|string $user User to remove. Can be one of the user objects or a user ID. * - * @return PromiseInterface + * @return Promise */ - public function removeMember($user): PromiseInterface + public function removeMember($user): Promise { if ($user instanceof User || $user instanceof Member) { $user = $user->id; @@ -367,9 +367,9 @@ public function removeMember($user): PromiseInterface * @param string $name New thread name. * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise */ - public function rename(string $name, ?string $reason = null): PromiseInterface + public function rename(string $name, ?string $reason = null): Promise { $headers = []; if (isset($reason)) { @@ -389,9 +389,9 @@ public function rename(string $name, ?string $reason = null): PromiseInterface * * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise */ - public function archive(?string $reason = null): PromiseInterface + public function archive(?string $reason = null): Promise { $headers = []; if (isset($reason)) { @@ -411,9 +411,9 @@ public function archive(?string $reason = null): PromiseInterface * * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise */ - public function unarchive(?string $reason = null): PromiseInterface + public function unarchive(?string $reason = null): Promise { $headers = []; if (isset($reason)) { @@ -434,9 +434,9 @@ public function unarchive(?string $reason = null): PromiseInterface * @param int $duration Duration in minutes. * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise */ - public function setAutoArchiveDuration(int $duration, ?string $reason = null): PromiseInterface + public function setAutoArchiveDuration(int $duration, ?string $reason = null): Promise { $headers = []; if (isset($reason)) { @@ -456,11 +456,11 @@ public function setAutoArchiveDuration(int $duration, ?string $reason = null): P * * @link https://discord.com/developers/docs/resources/channel#get-pinned-messages * - * @return PromiseInterface> + * @return Promise> * * @todo Make it in a trait along with Channel */ - public function getPinnedMessages(): PromiseInterface + public function getPinnedMessages(): Promise { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_PINS, $this->id)) ->then(function ($responses) { @@ -482,11 +482,11 @@ public function getPinnedMessages(): PromiseInterface * @param array|Traversable $messages An array of messages to delete. * @param string|null $reason Reason for Audit Log (only for bulk messages). * - * @return PromiseInterface + * @return Promise * * @todo Make it in a trait along with Channel */ - public function deleteMessages($messages, ?string $reason = null): PromiseInterface + public function deleteMessages($messages, ?string $reason = null): Promise { if (! is_array($messages) && ! ($messages instanceof Traversable)) { return reject(new \InvalidArgumentException('$messages must be an array or implement Traversable.')); @@ -536,11 +536,11 @@ public function deleteMessages($messages, ?string $reason = null): PromiseInterf * * @param array $options * - * @return PromiseInterface> + * @return Promise> * * @todo Make it in a trait along with Channel */ - public function getMessageHistory(array $options): PromiseInterface + public function getMessageHistory(array $options): Promise { $resolver = new OptionsResolver(); $resolver @@ -600,11 +600,11 @@ public function getMessageHistory(array $options): PromiseInterface * * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise * * @todo Make it in a trait along with Channel */ - public function pinMessage(Message $message, ?string $reason = null): PromiseInterface + public function pinMessage(Message $message, ?string $reason = null): Promise { if ($message->pinned) { return reject(new \RuntimeException('This message is already pinned.')); @@ -636,11 +636,11 @@ public function pinMessage(Message $message, ?string $reason = null): PromiseInt * * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise * * @todo Make it in a trait along with Channel */ - public function unpinMessage(Message $message, ?string $reason = null): PromiseInterface + public function unpinMessage(Message $message, ?string $reason = null): Promise { if (! $message->pinned) { return reject(new \RuntimeException('This message is not pinned.')); @@ -677,11 +677,11 @@ public function unpinMessage(Message $message, ?string $reason = null): PromiseI * @param array|null $allowed_mentions Allowed mentions object for the message. * @param Message|null $replyTo Sends the message as a reply to the given message instance. * - * @return PromiseInterface + * @return Promise * * @todo Make it in a trait along with Channel */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): Promise { // Backwards compatible support for old `sendMessage` function signature. if (! ($message instanceof MessageBuilder)) { @@ -727,11 +727,11 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @param Embed $embed Embed to send. * - * @return PromiseInterface + * @return Promise * * @todo Make it in a trait along with Channel */ - public function sendEmbed(Embed $embed): PromiseInterface + public function sendEmbed(Embed $embed): Promise { return $this->sendMessage(MessageBuilder::new() ->addEmbed($embed)); @@ -746,9 +746,9 @@ public function sendEmbed(Embed $embed): PromiseInterface * * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise */ - public function broadcastTyping(): PromiseInterface + public function broadcastTyping(): Promise { return $this->http->post(Endpoint::bind(Endpoint::CHANNEL_TYPING, $this->id)); } @@ -761,11 +761,11 @@ public function broadcastTyping(): PromiseInterface * @param int $options ['time'] Time in milliseconds until the collector finishes or false. * @param int $options ['limit'] The amount of messages allowed or false. * - * @return PromiseInterface> + * @return Promise> * * @todo Make it in a trait along with Channel */ - public function createMessageCollector(callable $filter, array $options = []): PromiseInterface + public function createMessageCollector(callable $filter, array $options = []): Promise { $deferred = new Deferred(); $messages = new Collection([], null, null); diff --git a/src/Discord/Parts/User/Client.php b/src/Discord/Parts/User/Client.php index 71b0dd45d..98c1419d9 100644 --- a/src/Discord/Parts/User/Client.php +++ b/src/Discord/Parts/User/Client.php @@ -18,7 +18,7 @@ use Discord\Repository\GuildRepository; use Discord\Repository\PrivateChannelRepository; use Discord\Repository\UserRepository; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * The client is the main interface for the client. Most calls on the main class are forwarded here. @@ -142,9 +142,9 @@ protected function getAvatarHashAttribute(): ?string /** * Saves the client instance. * - * @return PromiseInterface + * @return Promise */ - public function save(): PromiseInterface + public function save(): Promise { return $this->http->patch(Endpoint::USER_CURRENT, $this->getUpdatableAttributes()); } diff --git a/src/Discord/Parts/User/Member.php b/src/Discord/Parts/User/Member.php index c12d64769..95838a699 100644 --- a/src/Discord/Parts/User/Member.php +++ b/src/Discord/Parts/User/Member.php @@ -28,7 +28,7 @@ use Discord\Parts\Permissions\RolePermission; use Discord\Parts\Thread\Thread; use Discord\Parts\WebSockets\PresenceUpdate; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use function React\Promise\reject; @@ -63,7 +63,7 @@ * @property Collection|Activity[] $activities User's current activities. * @property object $client_status Current client status. * - * @method PromiseInterface sendMessage(MessageBuilder $builder) + * @method Promise sendMessage(MessageBuilder $builder) */ class Member extends Part { @@ -129,9 +129,9 @@ public function updateFromPresence(PresenceUpdate $presence): PresenceUpdate * * @throws \RuntimeException Member has no `$guild` * - * @return PromiseInterface + * @return Promise */ - public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): PromiseInterface + public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): Promise { if (! $guild = $this->guild) { return reject(new \RuntimeException('Member has no Guild Part')); @@ -148,9 +148,9 @@ public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): * * @throws NoPermissionsException Missing manage_nicknames permission. * - * @return PromiseInterface + * @return Promise */ - public function setNickname(?string $nick = null, ?string $reason = null): PromiseInterface + public function setNickname(?string $nick = null, ?string $reason = null): Promise { $payload = [ 'nick' => $nick ?? '', @@ -188,9 +188,9 @@ public function setNickname(?string $nick = null, ?string $reason = null): Promi * @param Channel|?string $channel The channel to move the member to. * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise */ - public function moveMember($channel, ?string $reason = null): PromiseInterface + public function moveMember($channel, ?string $reason = null): Promise { if ($channel instanceof Channel) { $channel = $channel->id; @@ -218,9 +218,9 @@ public function moveMember($channel, ?string $reason = null): PromiseInterface * @throws \RuntimeException * @throws NoPermissionsException Missing manage_roles permission. * - * @return PromiseInterface + * @return Promise */ - public function addRole($role, ?string $reason = null): PromiseInterface + public function addRole($role, ?string $reason = null): Promise { if ($role instanceof Role) { $role = $role->id; @@ -262,9 +262,9 @@ public function addRole($role, ?string $reason = null): PromiseInterface * * @throws NoPermissionsException Missing manage_roles permission. * - * @return PromiseInterface + * @return Promise */ - public function removeRole($role, ?string $reason = null): PromiseInterface + public function removeRole($role, ?string $reason = null): Promise { if ($role instanceof Role) { $role = $role->id; @@ -301,9 +301,9 @@ public function removeRole($role, ?string $reason = null): PromiseInterface * * @throws NoPermissionsException Missing manage_roles permission. * - * @return PromiseInterface + * @return Promise */ - public function setRoles(array $roles, ?string $reason = null): PromiseInterface + public function setRoles(array $roles, ?string $reason = null): Promise { foreach ($roles as $i => $role) { if ($role instanceof Role) { @@ -348,9 +348,9 @@ public function setRoles(array $roles, ?string $reason = null): PromiseInterface * * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): Promise { if ($user = $this->user) { return $user->sendMessage($message, $tts, $embed, $allowed_mentions, $replyTo); @@ -483,9 +483,9 @@ public function getPermissions($channel = null): ?RolePermission * * @throws NoPermissionsException Missing moderate_members permission. * - * @return PromiseInterface + * @return Promise */ - public function timeoutMember(?Carbon $communication_disabled_until, ?string $reason = null): PromiseInterface + public function timeoutMember(?Carbon $communication_disabled_until, ?string $reason = null): Promise { if ($guild = $this->guild) { if ($botperms = $guild->getBotPermissions()) { @@ -516,9 +516,9 @@ public function timeoutMember(?Carbon $communication_disabled_until, ?string $re * * @throws NoPermissionsException Missing `moderate_members` permission. * - * @return PromiseInterface + * @return Promise */ - public function setBypassesVerification(bool $bypasses_verification, ?string $reason = null): PromiseInterface + public function setBypassesVerification(bool $bypasses_verification, ?string $reason = null): Promise { if ($guild = $this->guild) { if ($botperms = $guild->getBotPermissions()) { diff --git a/src/Discord/Parts/User/User.php b/src/Discord/Parts/User/User.php index ca8f69294..c2dde1508 100644 --- a/src/Discord/Parts/User/User.php +++ b/src/Discord/Parts/User/User.php @@ -16,7 +16,7 @@ use Discord\Parts\Channel\Channel; use Discord\Parts\Part; use Discord\Parts\Channel\Message; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use function React\Promise\resolve; @@ -47,7 +47,7 @@ * @property int|null $premium_type Type of nitro subscription. * @property int|null $public_flags Public flags on the user. * - * @method PromiseInterface sendMessage(MessageBuilder $builder) + * @method Promise sendMessage(MessageBuilder $builder) */ class User extends Part { @@ -100,9 +100,9 @@ class User extends Part * * @link https://discord.com/developers/docs/resources/user#create-dm * - * @return PromiseInterface + * @return Promise */ - public function getPrivateChannel(): PromiseInterface + public function getPrivateChannel(): Promise { if ($channel = $this->discord->private_channels->get('recipient_id', $this->id)) { return resolve($channel); @@ -130,9 +130,9 @@ public function getPrivateChannel(): PromiseInterface * @param array|null $allowed_mentions Allowed mentions object for the message. * @param Message|null $replyTo Sends the message as a reply to the given message instance. * - * @return PromiseInterface + * @return Promise */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): Promise { return $this->getPrivateChannel()->then(function (Channel $channel) use ($message, $tts, $embed, $allowed_mentions, $replyTo) { return $channel->sendMessage($message, $tts, $embed, $allowed_mentions, $replyTo); @@ -146,9 +146,9 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise */ - public function broadcastTyping(): PromiseInterface + public function broadcastTyping(): Promise { return $this->getPrivateChannel()->then(function (Channel $channel) { return $channel->broadcastTyping(); diff --git a/src/Discord/Parts/WebSockets/MessageReaction.php b/src/Discord/Parts/WebSockets/MessageReaction.php index 294a084a6..48119b9e3 100644 --- a/src/Discord/Parts/WebSockets/MessageReaction.php +++ b/src/Discord/Parts/WebSockets/MessageReaction.php @@ -19,7 +19,7 @@ use Discord\Parts\Part; use Discord\Parts\User\Member; use Discord\Parts\User\User; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use function React\Promise\reject; use function React\Promise\resolve; @@ -71,7 +71,7 @@ public function isPartial(): bool /** * {@inheritDoc} */ - public function fetch(): PromiseInterface + public function fetch(): Promise { $promise = resolve(); @@ -229,14 +229,14 @@ protected function getEmojiAttribute(): Emoji * * @throws \RuntimeException Reaction has no user id. * - * @return PromiseInterface + * @return Promise * * @see Message::deleteReaction() * * @link https://discord.com/developers/docs/resources/channel#delete-own-reaction * @link https://discord.com/developers/docs/resources/channel#delete-user-reaction */ - public function delete(?int $type = null): PromiseInterface + public function delete(?int $type = null): Promise { if ($type === null) { if ($this->user_id == $this->discord->id) { diff --git a/src/Discord/Repository/AbstractRepository.php b/src/Discord/Repository/AbstractRepository.php index 61e89b4d4..9450404f9 100755 --- a/src/Discord/Repository/AbstractRepository.php +++ b/src/Discord/Repository/AbstractRepository.php @@ -18,7 +18,7 @@ use Discord\Http\Endpoint; use Discord\Http\Http; use Discord\Parts\Part; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Traversable; use WeakReference; @@ -100,11 +100,11 @@ public function __construct(Discord $discord, array $vars = []) * * @param array $queryparams Query string params to add to the request (no validation) * - * @return PromiseInterface + * @return Promise * * @throws \Exception */ - public function freshen(array $queryparams = []): PromiseInterface + public function freshen(array $queryparams = []): Promise { if (! isset($this->endpoints['all'])) { return reject(new \Exception('You cannot freshen this repository.')); @@ -134,9 +134,9 @@ public function freshen(array $queryparams = []): PromiseInterface /** * @param object $response * - * @return PromiseInterface + * @return Promise */ - protected function cacheFreshen($response): PromiseInterface + protected function cacheFreshen($response): Promise { foreach ($response as $value) { $value = array_merge($this->vars, (array) $value); @@ -174,11 +174,11 @@ public function create(array $attributes = [], bool $created = false): Part * @param Part $part The part to save. * @param string|null $reason Reason for Audit Log (if supported). * - * @return PromiseInterface + * @return Promise * * @throws \Exception */ - public function save(Part $part, ?string $reason = null): PromiseInterface + public function save(Part $part, ?string $reason = null): Promise { if ($part->created) { if (! isset($this->endpoints['update'])) { @@ -219,11 +219,11 @@ public function save(Part $part, ?string $reason = null): PromiseInterface * @param Part|string $part The part to delete. * @param string|null $reason Reason for Audit Log (if supported). * - * @return PromiseInterface + * @return Promise * * @throws \Exception */ - public function delete($part, ?string $reason = null): PromiseInterface + public function delete($part, ?string $reason = null): Promise { if (! isset($part)) { return reject(new \Exception('You cannot delete a non-existant part.')); @@ -265,11 +265,11 @@ public function delete($part, ?string $reason = null): PromiseInterface * @param Part $part The part to get fresh values. * @param array $queryparams Query string params to add to the request (no validation) * - * @return PromiseInterface + * @return Promise * * @throws \Exception */ - public function fresh(Part $part, array $queryparams = []): PromiseInterface + public function fresh(Part $part, array $queryparams = []): Promise { if (! $part->created) { return reject(new \Exception('You cannot get a non-existant part.')); @@ -301,9 +301,9 @@ public function fresh(Part $part, array $queryparams = []): PromiseInterface * * @throws \Exception * - * @return PromiseInterface + * @return Promise */ - public function fetch(string $id, bool $fresh = false): PromiseInterface + public function fetch(string $id, bool $fresh = false): Promise { if (! $fresh) { if (isset($this->items[$id])) { @@ -391,9 +391,9 @@ public function get(string $discrim, $key) * * @param string|int $offset * - * @return PromiseInterface + * @return Promise */ - public function cacheGet($offset): PromiseInterface + public function cacheGet($offset): Promise { return resolve($this->offsetGet($offset) ?? $this->cache->get($offset)); } @@ -444,9 +444,9 @@ public function pull($key, $default = null) * @param string|int $key * @param ?Part $default * - * @return PromiseInterface + * @return Promise */ - public function cachePull($key, $default = null): PromiseInterface + public function cachePull($key, $default = null): Promise { return $this->cacheGet($key)->then(fn ($item) => ($item === null) ? $default : $this->cache->delete($key)->then(fn ($success) => $item)); } diff --git a/src/Discord/Repository/Channel/ReactionRepository.php b/src/Discord/Repository/Channel/ReactionRepository.php index 6a7f73247..ac00d1ca4 100644 --- a/src/Discord/Repository/Channel/ReactionRepository.php +++ b/src/Discord/Repository/Channel/ReactionRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Channel\Reaction; use Discord\Repository\AbstractRepository; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * Contains reactions on a message. @@ -51,11 +51,11 @@ class ReactionRepository extends AbstractRepository * * @param Reaction|string $part The Reaction part or unicode emoji to delete. * - * @return PromiseInterface + * @return Promise * * @since 10.0.0 */ - public function delete($part, ?string $reason = null): PromiseInterface + public function delete($part, ?string $reason = null): Promise { // Deal with unicode emoji if (is_string($part) && ! is_numeric($part)) { diff --git a/src/Discord/Repository/Channel/ThreadRepository.php b/src/Discord/Repository/Channel/ThreadRepository.php index 8018ccd16..028e6a951 100644 --- a/src/Discord/Repository/Channel/ThreadRepository.php +++ b/src/Discord/Repository/Channel/ThreadRepository.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Thread\Thread; use Discord\Repository\AbstractRepository; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use function React\Promise\resolve; @@ -53,7 +53,7 @@ class ThreadRepository extends AbstractRepository /** * {@inheritDoc} */ - protected function cacheFreshen($response): PromiseInterface + protected function cacheFreshen($response): Promise { foreach ($response->threads as $value) { $value = array_merge($this->vars, (array) $value); @@ -87,9 +87,9 @@ protected function cacheFreshen($response): PromiseInterface * * @link https://discord.com/developers/docs/resources/channel#list-active-threads * - * @return PromiseInterface> + * @return Promise> */ - public function active(): PromiseInterface + public function active(): Promise { return $this->http->get(Endpoint::bind(Endpoint::GUILD_THREADS_ACTIVE, $this->vars['guild_id'])) ->then(function ($response) { @@ -111,9 +111,9 @@ public function active(): PromiseInterface * * @throws \InvalidArgumentException * - * @return PromiseInterface> + * @return Promise> */ - public function archived(bool $private = false, bool $joined = false, ?int $limit = null, $before = null): PromiseInterface + public function archived(bool $private = false, bool $joined = false, ?int $limit = null, $before = null): Promise { if ($joined) { if (! $private) { diff --git a/src/Discord/Repository/Guild/BanRepository.php b/src/Discord/Repository/Guild/BanRepository.php index 0c975d6c5..d333a6815 100644 --- a/src/Discord/Repository/Guild/BanRepository.php +++ b/src/Discord/Repository/Guild/BanRepository.php @@ -16,7 +16,7 @@ use Discord\Parts\User\Member; use Discord\Parts\User\User; use Discord\Repository\AbstractRepository; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -63,9 +63,9 @@ class BanRepository extends AbstractRepository * @param array $options Array of Ban options 'delete_message_seconds' or 'delete_message_days' (deprecated). * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise */ - public function ban($user, array $options = [], ?string $reason = null): PromiseInterface + public function ban($user, array $options = [], ?string $reason = null): Promise { $content = []; $headers = []; @@ -122,9 +122,9 @@ public function ban($user, array $options = [], ?string $reason = null): Promise * @param User|Ban|string $ban User or Ban Part, or User ID * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise */ - public function unban($ban, ?string $reason = null): PromiseInterface + public function unban($ban, ?string $reason = null): Promise { if ($ban instanceof User || $ban instanceof Member) { $ban = $ban->id; diff --git a/src/Discord/Repository/Guild/GuildTemplateRepository.php b/src/Discord/Repository/Guild/GuildTemplateRepository.php index 865f5bc0d..519ca46f8 100644 --- a/src/Discord/Repository/Guild/GuildTemplateRepository.php +++ b/src/Discord/Repository/Guild/GuildTemplateRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\GuildTemplate; use Discord\Repository\AbstractRepository; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * Contains guild templates of a guild. @@ -58,9 +58,9 @@ class GuildTemplateRepository extends AbstractRepository * * @param string $template_code The guild template code. * - * @return PromiseInterface + * @return Promise */ - public function sync(string $template_code): PromiseInterface + public function sync(string $template_code): Promise { return $this->http->put(Endpoint::bind(Endpoint::GUILD_TEMPLATE, $this->vars['guild_id'], $template_code))->then(function ($guild_template) use ($template_code) { return $this->cache->get($template_code)->then(function ($guildTemplate) use ($guild_template, $template_code) { diff --git a/src/Discord/Repository/Guild/MemberRepository.php b/src/Discord/Repository/Guild/MemberRepository.php index 91ab0ada7..23eada336 100755 --- a/src/Discord/Repository/Guild/MemberRepository.php +++ b/src/Discord/Repository/Guild/MemberRepository.php @@ -15,7 +15,7 @@ use Discord\Parts\User\Member; use Discord\Repository\AbstractRepository; use React\Promise\Deferred; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * Contains members of a guild. @@ -56,9 +56,9 @@ class MemberRepository extends AbstractRepository * @param Member $member The member to kick. * @param string|null $reason Reason for Audit Log. * - * @return PromiseInterface + * @return Promise */ - public function kick(Member $member, ?string $reason = null): PromiseInterface + public function kick(Member $member, ?string $reason = null): Promise { return $this->delete($member, $reason); } @@ -68,7 +68,7 @@ public function kick(Member $member, ?string $reason = null): PromiseInterface * * @param array $queryparams Query string params to add to the request, leave null to paginate all members (Warning: Be careful to use this on very large guild) */ - public function freshen(array $queryparams = null): PromiseInterface + public function freshen(array $queryparams = null): Promise { if (isset($queryparams)) { return parent::freshen($queryparams); diff --git a/src/Discord/Repository/Guild/ScheduledEventRepository.php b/src/Discord/Repository/Guild/ScheduledEventRepository.php index 46e49f694..132266cec 100644 --- a/src/Discord/Repository/Guild/ScheduledEventRepository.php +++ b/src/Discord/Repository/Guild/ScheduledEventRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\ScheduledEvent; use Discord\Repository\AbstractRepository; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use function React\Promise\resolve; @@ -55,9 +55,9 @@ class ScheduledEventRepository extends AbstractRepository * * @param bool $with_user_count Whether to include number of users subscribed to each event * - * @return PromiseInterface + * @return Promise */ - public function fetch(string $id, bool $fresh = false, bool $with_user_count = false): PromiseInterface + public function fetch(string $id, bool $fresh = false, bool $with_user_count = false): Promise { if (! $with_user_count) { return parent::fetch($id, $fresh); diff --git a/src/Discord/Repository/GuildRepository.php b/src/Discord/Repository/GuildRepository.php index aaf165576..fcc285cc2 100755 --- a/src/Discord/Repository/GuildRepository.php +++ b/src/Discord/Repository/GuildRepository.php @@ -13,7 +13,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\Guild; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * Contains guilds that the client is in. @@ -54,9 +54,9 @@ class GuildRepository extends AbstractRepository * * @param Guild|string $guild * - * @return PromiseInterface + * @return Promise */ - public function leave($guild): PromiseInterface + public function leave($guild): Promise { if ($guild instanceof Guild) { $guild = $guild->id; diff --git a/src/Discord/Voice/OggPage.php b/src/Discord/Voice/OggPage.php index d9e616b35..fe57d9cf1 100644 --- a/src/Discord/Voice/OggPage.php +++ b/src/Discord/Voice/OggPage.php @@ -13,7 +13,7 @@ use Discord\Helpers\Buffer; use Generator; -use React\Promise\PromiseInterface; +use React\Promise\Promise; /** * Represents a page in an Ogg container. @@ -65,11 +65,11 @@ private function __construct( * @param Buffer $buffer Buffer to read the Ogg page from. * @param ?int $timeout Time in milliseconds before a buffer read times out. * - * @return PromiseInterface Promise containing the Ogg page. + * @return Promise Promise containing the Ogg page. * * @throws \UnexpectedValueException If the buffer is out of sync and an invalid header is read. */ - public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): PromiseInterface + public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): Promise { $header = null; $pageSegments = []; diff --git a/src/Discord/Voice/OggStream.php b/src/Discord/Voice/OggStream.php index 166925a89..9370fbf17 100644 --- a/src/Discord/Voice/OggStream.php +++ b/src/Discord/Voice/OggStream.php @@ -13,7 +13,7 @@ use Discord\Exceptions\BufferTimedOutException; use Discord\Helpers\Buffer; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use React\Promise\Promise; use function React\Promise\resolve; @@ -65,9 +65,9 @@ private function __construct( * @param Buffer $buffer Buffer to read Ogg Opus packets from. * @param ?int $timeout Time in milliseconds before a buffer read times out. * - * @return PromiseInterface A promise containing the Ogg stream. + * @return Promise A promise containing the Ogg stream. */ - public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): PromiseInterface + public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): Promise { /** @var OpusHead */ $header = null; @@ -86,9 +86,9 @@ public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): PromiseIn /** * Attempt to get a packet from the Ogg stream. * - * @return PromiseInterface Promise containing an Opus packet. If null, indicates EOF. + * @return Promise Promise containing an Opus packet. If null, indicates EOF. */ - public function getPacket(): PromiseInterface + public function getPacket(): Promise { if ($this->packets === null) { return resolve(null); @@ -113,9 +113,9 @@ public function getPacket(): PromiseInterface * Attempt to read an Ogg page from the buffer and parse it into Opus * packets. * - * @return PromiseInterface Promise containing an array of Opus packets. + * @return Promise Promise containing an array of Opus packets. */ - private function parsePackets(): PromiseInterface + private function parsePackets(): Promise { return new Promise(function ($resolve, $reject) { OggPage::fromBuffer($this->buffer, timeout: 0)->then(function ($page) use ($resolve) { diff --git a/src/Discord/Voice/VoiceClient.php b/src/Discord/Voice/VoiceClient.php index b3d9764b3..c7a5d2630 100644 --- a/src/Discord/Voice/VoiceClient.php +++ b/src/Discord/Voice/VoiceClient.php @@ -29,7 +29,7 @@ use Psr\Log\LoggerInterface; use React\ChildProcess\Process; use React\Promise\Deferred; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use React\Stream\ReadableResourceStream as Stream; use React\EventLoop\TimerInterface; use React\Stream\ReadableResourceStream; @@ -400,7 +400,7 @@ public function start() public function initSockets(): void { $wsfac = new WsFactory($this->loop); - /** @var PromiseInterface */ + /** @var Promise */ $promise = $wsfac("wss://{$this->endpoint}?v={$this->version}"); $promise->then([$this, 'handleWebSocketConnection'], [$this, 'handleWebSocketError']); @@ -438,7 +438,7 @@ public function handleWebSocketConnection(WebSocket $ws): void $buffer[1] = "\x01"; $buffer[3] = "\x46"; $buffer->writeUInt32BE($this->ssrc, 4); - /** @var PromiseInterface */ + /** @var Promise */ $promise = $udpfac->createClient("{$data->d->ip}:{$this->udpPort}"); $promise->then(function (Socket $client) use (&$ws, &$firstPack, &$ip, &$port, $buffer) { @@ -686,9 +686,9 @@ public function handleVoiceServerChange(array $data = []): void * @throws FileNotFoundException * @throws \RuntimeException * - * @return PromiseInterface + * @return Promise */ - public function playFile(string $file, int $channels = 2): PromiseInterface + public function playFile(string $file, int $channels = 2): Promise { $deferred = new Deferred(); @@ -726,9 +726,9 @@ public function playFile(string $file, int $channels = 2): PromiseInterface * @throws \RuntimeException * @throws \InvalidArgumentException Thrown when the stream passed to playRawStream is not a valid resource. * - * @return PromiseInterface + * @return Promise */ - public function playRawStream($stream, int $channels = 2, int $audioRate = 48000): PromiseInterface + public function playRawStream($stream, int $channels = 2, int $audioRate = 48000): Promise { $deferred = new Deferred(); @@ -773,9 +773,9 @@ public function playRawStream($stream, int $channels = 2, int $audioRate = 48000 * @throws \RuntimeException * @throws \InvalidArgumentException * - * @return PromiseInterface + * @return Promise */ - public function playOggStream($stream): PromiseInterface + public function playOggStream($stream): Promise { $deferred = new Deferred(); @@ -885,13 +885,13 @@ public function playOggStream($stream): PromiseInterface * * @param resource|Process|Stream $stream The DCA stream to be sent. * - * @return PromiseInterface + * @return Promise * @throws \Exception * * @deprecated 10.0.0 DCA is now deprecated in DiscordPHP, switch to using * `playOggStream` with raw Ogg Opus. */ - public function playDCAStream($stream): PromiseInterface + public function playDCAStream($stream): Promise { $deferred = new Deferred(); diff --git a/src/Discord/functions.php b/src/Discord/functions.php index c060d2c31..c288e8617 100644 --- a/src/Discord/functions.php +++ b/src/Discord/functions.php @@ -22,7 +22,7 @@ use React\EventLoop\LoopInterface; use React\Promise\Deferred; use React\Promise\Promise; -use React\Promise\PromiseInterface; +use React\Promise\Promise; use Symfony\Component\OptionsResolver\Options; /** @@ -336,7 +336,7 @@ function deferFind($array, callable $callback, $loop = null): Promise * Attempts to return a resolved value from a synchronous promise. * Like await() but only for resolvable blocking promise without touching the loop. * - * @param PromiseInterface $promiseInterface The synchronous promise. + * @param Promise $promiseInterface The synchronous promise. * * @return mixed null if failed to return. * @@ -344,7 +344,7 @@ function deferFind($array, callable $callback, $loop = null): Promise * * @since 10.0.0 */ -function nowait(PromiseInterface $promiseInterface) +function nowait(Promise $promiseInterface) { $resolved = null; From 093170c50466253cc86f6afc822bed6d3c8864a8 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Tue, 1 Aug 2023 16:29:27 +0200 Subject: [PATCH 08/19] Revert "Change PromiseInterface to Promise" This reverts commit 03d842e97f2bd37b385d1254f629e9a484348147. --- src/Discord/Builders/Components/Button.php | 4 +- .../Builders/Components/SelectMenu.php | 4 +- src/Discord/Discord.php | 18 ++-- src/Discord/Helpers/Buffer.php | 14 +-- src/Discord/Helpers/CacheWrapper.php | 30 +++---- src/Discord/Parts/Channel/Channel.php | 80 ++++++++--------- src/Discord/Parts/Channel/Message.php | 46 +++++----- src/Discord/Parts/Channel/Reaction.php | 12 +-- src/Discord/Parts/Channel/Webhook.php | 10 +-- src/Discord/Parts/Guild/Guild.php | 90 +++++++++---------- src/Discord/Parts/Guild/GuildTemplate.php | 6 +- src/Discord/Parts/Guild/ScheduledEvent.php | 6 +- src/Discord/Parts/Guild/Widget.php | 4 +- .../Parts/Interactions/Interaction.php | 62 ++++++------- src/Discord/Parts/Part.php | 6 +- src/Discord/Parts/Thread/Member.php | 6 +- src/Discord/Parts/Thread/Thread.php | 72 +++++++-------- src/Discord/Parts/User/Client.php | 6 +- src/Discord/Parts/User/Member.php | 40 ++++----- src/Discord/Parts/User/User.php | 16 ++-- .../Parts/WebSockets/MessageReaction.php | 8 +- src/Discord/Repository/AbstractRepository.php | 34 +++---- .../Repository/Channel/ReactionRepository.php | 6 +- .../Repository/Channel/ThreadRepository.php | 12 +-- .../Repository/Guild/BanRepository.php | 10 +-- .../Guild/GuildTemplateRepository.php | 6 +- .../Repository/Guild/MemberRepository.php | 8 +- .../Guild/ScheduledEventRepository.php | 6 +- src/Discord/Repository/GuildRepository.php | 6 +- src/Discord/Voice/OggPage.php | 6 +- src/Discord/Voice/OggStream.php | 14 +-- src/Discord/Voice/VoiceClient.php | 22 ++--- src/Discord/functions.php | 6 +- 33 files changed, 338 insertions(+), 338 deletions(-) diff --git a/src/Discord/Builders/Components/Button.php b/src/Discord/Builders/Components/Button.php index 9127005f5..480921bc7 100644 --- a/src/Discord/Builders/Components/Button.php +++ b/src/Discord/Builders/Components/Button.php @@ -15,7 +15,7 @@ use Discord\Parts\Guild\Emoji; use Discord\Parts\Interactions\Interaction; use Discord\WebSockets\Event; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use function Discord\poly_strlen; @@ -343,7 +343,7 @@ public function setListener(?callable $callback, Discord $discord, bool $oneOff } }; - if ($response instanceof Promise) { + if ($response instanceof PromiseInterface) { $response->then($ack); } else { $ack(); diff --git a/src/Discord/Builders/Components/SelectMenu.php b/src/Discord/Builders/Components/SelectMenu.php index 70da37866..cb557904e 100644 --- a/src/Discord/Builders/Components/SelectMenu.php +++ b/src/Discord/Builders/Components/SelectMenu.php @@ -15,7 +15,7 @@ use Discord\Helpers\Collection; use Discord\Parts\Interactions\Interaction; use Discord\WebSockets\Event; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use function Discord\poly_strlen; @@ -263,7 +263,7 @@ public function setListener(?callable $callback, Discord $discord, bool $oneOff } }; - if ($response instanceof Promise) { + if ($response instanceof PromiseInterface) { $response->then($ack); } else { $ack(); diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index 6546bf819..159834c42 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -50,7 +50,7 @@ use Psr\Log\LoggerInterface; use React\Cache\ArrayCache; use React\Promise\Deferred; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use React\Socket\Connector as SocketConnector; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -469,7 +469,7 @@ protected function handleReady(object $data) $unavailable = []; foreach ($content->guilds as $guild) { - /** @var Promise */ + /** @var PromiseInterface */ $promise = coroutine([$event, 'handle'], $guild); $promise->then(function ($d) use (&$unavailable) { @@ -806,12 +806,12 @@ protected function handleDispatch(object $data): void if (! $this->emittedInit && (! in_array($data->t, $parse))) { $this->unparsedPackets[] = function () use (&$handler, &$deferred, &$data) { - /** @var Promise */ + /** @var PromiseInterface */ $promise = coroutine([$handler, 'handle'], $data->d); $promise->then([$deferred, 'resolve'], [$deferred, 'reject']); }; } else { - /** @var Promise */ + /** @var PromiseInterface */ $promise = coroutine([$handler, 'handle'], $data->d); $promise->then([$deferred, 'resolve'], [$deferred, 'reject']); } @@ -1090,7 +1090,7 @@ protected function connectWs(): void $this->logger->info('starting connection to websocket', ['gateway' => $this->gateway]); - /** @var Promise */ + /** @var PromiseInterface */ $promise = ($this->wsFactory)($this->gateway); $promise->then([$this, 'handleWsConnection'], [$this, 'handleWsConnectionFailed']); }); @@ -1213,9 +1213,9 @@ public function getVoiceClient(string $guild_id): ?VoiceClient * * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface */ - public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, ?LoggerInterface $logger = null, bool $check = true): Promise + public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, ?LoggerInterface $logger = null, bool $check = true): PromiseInterface { $deferred = new Deferred(); @@ -1309,9 +1309,9 @@ public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, * * @param string|null $gateway Gateway URL to set. * - * @return Promise + * @return PromiseInterface */ - protected function setGateway(?string $gateway = null): Promise + protected function setGateway(?string $gateway = null): PromiseInterface { $deferred = new Deferred(); $defaultSession = [ diff --git a/src/Discord/Helpers/Buffer.php b/src/Discord/Helpers/Buffer.php index adf3ce533..71fff963e 100644 --- a/src/Discord/Helpers/Buffer.php +++ b/src/Discord/Helpers/Buffer.php @@ -15,7 +15,7 @@ use Evenement\EventEmitter; use React\EventLoop\LoopInterface; use React\Promise\Deferred; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use React\Stream\WritableStreamInterface; /** @@ -107,11 +107,11 @@ private function readRaw(int $length) * @param null|string $format Format to read the bytes in. See `pack()`. * @param int $timeout Time in milliseconds before the read times out. * - * @return Promise + * @return PromiseInterface * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function read(int $length, ?string $format = null, ?int $timeout = -1): Promise + public function read(int $length, ?string $format = null, ?int $timeout = -1): PromiseInterface { $deferred = new Deferred(); @@ -153,11 +153,11 @@ public function read(int $length, ?string $format = null, ?int $timeout = -1): P * * @param int $timeout Time in milliseconds before the read times out. * - * @return Promise + * @return PromiseInterface * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function readInt32(int $timeout = -1): Promise + public function readInt32(int $timeout = -1): PromiseInterface { return $this->read(4, 'l', $timeout); } @@ -167,11 +167,11 @@ public function readInt32(int $timeout = -1): Promise * * @param int $timeout Time in milliseconds before the read times out. * - * @return Promise + * @return PromiseInterface * * @throws \RuntimeException When there is an error unpacking the read bytes. */ - public function readInt16(int $timeout = -1): Promise + public function readInt16(int $timeout = -1): PromiseInterface { return $this->read(2, 'v', $timeout); } diff --git a/src/Discord/Helpers/CacheWrapper.php b/src/Discord/Helpers/CacheWrapper.php index 5f25b75f1..3789f9197 100644 --- a/src/Discord/Helpers/CacheWrapper.php +++ b/src/Discord/Helpers/CacheWrapper.php @@ -14,7 +14,7 @@ use Discord\Discord; use Discord\Parts\Part; use React\Cache\ArrayCache; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Throwable; use WeakReference; @@ -108,7 +108,7 @@ public function __destruct() * @param string $key * @param mixed $default * - * @return Promise + * @return PromiseInterface */ public function get($key, $default = null) { @@ -128,7 +128,7 @@ public function get($key, $default = null) return reject($throwable); } - if ($result instanceof Promise) { + if ($result instanceof PromiseInterface) { return $result->then($handleValue); } @@ -141,7 +141,7 @@ public function get($key, $default = null) * @param string $key * @param Part $value * - * @return Promise + * @return PromiseInterface */ public function set($key, $value, $ttl = null) { @@ -162,7 +162,7 @@ public function set($key, $value, $ttl = null) return reject($throwable); } - if ($result instanceof Promise) { + if ($result instanceof PromiseInterface) { return $result->then($handleValue); } @@ -174,7 +174,7 @@ public function set($key, $value, $ttl = null) * * @param string $key * - * @return Promise|bool + * @return PromiseInterface|bool */ public function delete($key) { @@ -192,7 +192,7 @@ public function delete($key) return reject($throwable); } - if ($result instanceof Promise) { + if ($result instanceof PromiseInterface) { return $result->then($handleValue); } @@ -207,7 +207,7 @@ public function delete($key) * @param array $keys * @param ?Part $default * - * @return Promise + * @return PromiseInterface */ public function getMultiple(array $keys, $default = null) { @@ -230,7 +230,7 @@ public function getMultiple(array $keys, $default = null) return reject($throwable); } - if ($result instanceof Promise) { + if ($result instanceof PromiseInterface) { return $result->then($handleValue); } @@ -254,7 +254,7 @@ public function getMultiple(array $keys, $default = null) * @param Part[] $values * @param ?int $ttl * - * @return Promise + * @return PromiseInterface */ public function setMultiple(array $values, $ttl = null) { @@ -274,7 +274,7 @@ public function setMultiple(array $values, $ttl = null) * * @param array $keys * - * @return Promise + * @return PromiseInterface */ public function deleteMultiple(array $keys) { @@ -297,7 +297,7 @@ public function deleteMultiple(array $keys) return reject($throwable); } - if ($result instanceof Promise) { + if ($result instanceof PromiseInterface) { return $result->then($handleValue); } @@ -318,7 +318,7 @@ public function deleteMultiple(array $keys) * * For react/cache 0.5 polyfill. * - * @return Promise + * @return PromiseInterface */ public function clear() { @@ -332,7 +332,7 @@ public function clear() * * @param string $key * - * @return Promise + * @return PromiseInterface */ public function has($key) { @@ -354,7 +354,7 @@ public function has($key) return reject($throwable); } - if ($result instanceof Promise) { + if ($result instanceof PromiseInterface) { return $result->then($handleValue); } diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index fcc3d2a6f..77460291e 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -38,7 +38,7 @@ use Discord\Repository\Channel\StageInstanceRepository; use Discord\Repository\Channel\ThreadRepository; use React\Promise\Deferred; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Traversable; @@ -97,7 +97,7 @@ * @property InviteRepository $invites Invites in the channel. * @property StageInstanceRepository $stage_instances Stage instances in the channel. * - * @method Promise sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class Channel extends Part { @@ -293,9 +293,9 @@ protected function getLastPinTimestampAttribute(): ?Carbon * * @link https://discord.com/developers/docs/resources/channel#get-pinned-messages * - * @return Promise> + * @return PromiseInterface> */ - public function getPinnedMessages(): Promise + public function getPinnedMessages(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_PINS, $this->id)) ->then(function ($responses) { @@ -321,9 +321,9 @@ public function getPinnedMessages(): Promise * * @throws InvalidOverwriteException * - * @return Promise + * @return PromiseInterface */ - public function setPermissions(Part $part, array $allow = [], array $deny = [], ?string $reason = null): Promise + public function setPermissions(Part $part, array $allow = [], array $deny = [], ?string $reason = null): PromiseInterface { if ($part instanceof Member) { $type = Overwrite::TYPE_MEMBER; @@ -362,9 +362,9 @@ public function setPermissions(Part $part, array $allow = [], array $deny = [], * @throws NoPermissionsException Missing manage_roles permission. * @throws InvalidOverwriteException Overwrite type is not member or role. * - * @return Promise + * @return PromiseInterface */ - public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = null): Promise + public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = null): PromiseInterface { if ($this->guild_id && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_roles) { @@ -408,13 +408,13 @@ public function setOverwrite(Part $part, Overwrite $overwrite, ?string $reason = * @param int|null $position The new channel position, not relative to category. * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface * * @throws \RuntimeException * @throws \InvalidArgumentException * @throws NoPermissionsException Missing manage_channels permission in either channel. */ - public function setCategory($category, ?int $position = null, ?string $reason = null): Promise + public function setCategory($category, ?int $position = null, ?string $reason = null): PromiseInterface { if (! in_array($this->type, [self::TYPE_GUILD_TEXT, self::TYPE_GUILD_VOICE, self::TYPE_GUILD_ANNOUNCEMENT, self::TYPE_GUILD_FORUM])) { return reject(new \RuntimeException('You can only move Text, Voice, Announcement or Forum channel type.')); @@ -472,9 +472,9 @@ public function setCategory($category, ?int $position = null, ?string $reason = * @throws \RuntimeException * @throws NoPermissionsException Missing move_members permission. * - * @return Promise + * @return PromiseInterface */ - public function moveMember($member, ?string $reason = null): Promise + public function moveMember($member, ?string $reason = null): PromiseInterface { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot move a member in a text channel.')); @@ -507,9 +507,9 @@ public function moveMember($member, ?string $reason = null): Promise * @throws \RuntimeException * @throws NoPermissionsException Missing mute_members permission. * - * @return Promise + * @return PromiseInterface */ - public function muteMember($member, ?string $reason = null): Promise + public function muteMember($member, ?string $reason = null): PromiseInterface { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot mute a member in a text channel.')); @@ -542,9 +542,9 @@ public function muteMember($member, ?string $reason = null): Promise * @throws \RuntimeException * @throws NoPermissionsException Missing mute_members permission. * - * @return Promise + * @return PromiseInterface */ - public function unmuteMember($member, ?string $reason = null): Promise + public function unmuteMember($member, ?string $reason = null): PromiseInterface { if (! $this->isVoiceBased()) { return reject(new \RuntimeException('You cannot unmute a member in a text channel.')); @@ -585,9 +585,9 @@ public function unmuteMember($member, ?string $reason = null): Promise * * @throws NoPermissionsException Missing create_instant_invite permission. * - * @return Promise + * @return PromiseInterface */ - public function createInvite($options = [], ?string $reason = null): Promise + public function createInvite($options = [], ?string $reason = null): PromiseInterface { if (! $this->canInvite()) { return reject(new \RuntimeException('You cannot create invite in this type of channel.')); @@ -651,9 +651,9 @@ public function createInvite($options = [], ?string $reason = null): Promise * @throws \InvalidArgumentException * @throws NoPermissionsException Missing manage_messages permission. * - * @return Promise + * @return PromiseInterface */ - public function deleteMessages($messages, ?string $reason = null): Promise + public function deleteMessages($messages, ?string $reason = null): PromiseInterface { if (! is_array($messages) && ! ($messages instanceof Traversable)) { return reject(new \InvalidArgumentException('$messages must be an array or implement Traversable.')); @@ -706,9 +706,9 @@ public function deleteMessages($messages, ?string $reason = null): Promise * * @throws NoPermissionsException Missing manage_messages permission. * - * @return Promise + * @return PromiseInterface */ - public function limitDelete(int $value, ?string $reason = null): Promise + public function limitDelete(int $value, ?string $reason = null): PromiseInterface { if ($botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -732,9 +732,9 @@ public function limitDelete(int $value, ?string $reason = null): Promise * Or also missing `connect` permission for text in voice. * @throws \RangeException * - * @return Promise> + * @return PromiseInterface> */ - public function getMessageHistory(array $options): Promise + public function getMessageHistory(array $options): PromiseInterface { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->read_message_history) { @@ -796,9 +796,9 @@ public function getMessageHistory(array $options): Promise * @throws NoPermissionsException Missing manage_messages permission. * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface */ - public function pinMessage(Message $message, ?string $reason = null): Promise + public function pinMessage(Message $message, ?string $reason = null): PromiseInterface { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -837,9 +837,9 @@ public function pinMessage(Message $message, ?string $reason = null): Promise * @throws NoPermissionsException Missing manage_messages permission. * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface */ - public function unpinMessage(Message $message, ?string $reason = null): Promise + public function unpinMessage(Message $message, ?string $reason = null): PromiseInterface { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->manage_messages) { @@ -967,11 +967,11 @@ protected function getDefaultReactionEmojiAttribute(): ?Reaction * create_public_threads when creating a public thread. * send_messages when creating a forum post. * - * @return Promise + * @return PromiseInterface * * @since 10.0.0 Arguments for `$name`, `$private` and `$auto_archive_duration` are now inside `$options` */ - public function startThread(array|string $options, string|null|bool $reason = null, int $_auto_archive_duration = 1440, ?string $_reason = null): Promise + public function startThread(array|string $options, string|null|bool $reason = null, int $_auto_archive_duration = 1440, ?string $_reason = null): PromiseInterface { // Old v7 signature if (is_string($options)) { @@ -1124,9 +1124,9 @@ public function startThread(array|string $options, string|null|bool $reason = nu * @throws \RuntimeException * @throws NoPermissionsException Missing various permissions depending on the message body. * - * @return Promise + * @return PromiseInterface */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): Promise + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface { // Backwards compatible support for old `sendMessage` function signature. if (! ($message instanceof MessageBuilder)) { @@ -1190,9 +1190,9 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @param Embed $embed Embed to send. * - * @return Promise + * @return PromiseInterface */ - public function sendEmbed(Embed $embed): Promise + public function sendEmbed(Embed $embed): PromiseInterface { return $this->sendMessage(MessageBuilder::new() ->addEmbed($embed)); @@ -1210,9 +1210,9 @@ public function sendEmbed(Embed $embed): Promise * @param string|null $content Message content to send with the file. * @param bool $tts Whether to send the message with TTS. * - * @return Promise + * @return PromiseInterface */ - public function sendFile(string $filepath, ?string $filename = null, ?string $content = null, bool $tts = false): Promise + public function sendFile(string $filepath, ?string $filename = null, ?string $content = null, bool $tts = false): PromiseInterface { $builder = MessageBuilder::new() ->setTts($tts) @@ -1232,9 +1232,9 @@ public function sendFile(string $filepath, ?string $filename = null, ?string $co * * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface */ - public function broadcastTyping(): Promise + public function broadcastTyping(): PromiseInterface { if (! $this->isTextBased()) { return reject(new \RuntimeException('You cannot broadcast typing to a voice channel.')); @@ -1251,9 +1251,9 @@ public function broadcastTyping(): Promise * @param int $options['time'] Time in milliseconds until the collector finishes or false. * @param int $options['limit'] The amount of messages allowed or false. * - * @return Promise> + * @return PromiseInterface> */ - public function createMessageCollector(callable $filter, array $options = []): Promise + public function createMessageCollector(callable $filter, array $options = []): PromiseInterface { $deferred = new Deferred(); $messages = new Collection([], null, null); diff --git a/src/Discord/Parts/Channel/Message.php b/src/Discord/Parts/Channel/Message.php index 4a00607e6..ee5831ba1 100644 --- a/src/Discord/Parts/Channel/Message.php +++ b/src/Discord/Parts/Channel/Message.php @@ -32,7 +32,7 @@ use Discord\Repository\Channel\ReactionRepository; use React\EventLoop\TimerInterface; use React\Promise\Deferred; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use function React\Promise\reject; @@ -739,11 +739,11 @@ public function getLinkAttribute(): ?string * @throws \RuntimeException Channel type is not guild text or news. * @throws NoPermissionsException Missing create_public_threads permission to create or manage_threads permission to set rate_limit_per_user. * - * @return Promise + * @return PromiseInterface * * @since 10.0.0 Arguments for `$name` and `$auto_archive_duration` are now inside `$options` */ - public function startThread(array|string $options, string|null|int $reason = null, ?string $_reason = null): Promise + public function startThread(array|string $options, string|null|int $reason = null, ?string $_reason = null): PromiseInterface { // Old v7 signature if (is_string($options)) { @@ -819,9 +819,9 @@ public function startThread(array|string $options, string|null|int $reason = nul * * @param string|MessageBuilder $message The reply message. * - * @return Promise + * @return PromiseInterface */ - public function reply($message): Promise + public function reply($message): PromiseInterface { $channel = $this->channel; @@ -844,9 +844,9 @@ public function reply($message): Promise * send_messages if this message author is the bot. * manage_messages if this message author is other user. * - * @return Promise + * @return PromiseInterface */ - public function crosspost(): Promise + public function crosspost(): PromiseInterface { if ($this->crossposted) { return reject(new \RuntimeException('This message has already been crossposted.')); @@ -882,9 +882,9 @@ public function crosspost(): Promise * @param int $delay Delay after text will be sent in milliseconds. * @param TimerInterface &$timer Delay timer passed by reference. * - * @return Promise + * @return PromiseInterface */ - public function delayedReply($message, int $delay, &$timer = null): Promise + public function delayedReply($message, int $delay, &$timer = null): PromiseInterface { $deferred = new Deferred(); @@ -905,7 +905,7 @@ public function delayedReply($message, int $delay, &$timer = null): Promise * * @return ExtendedPromseInterface */ - public function delayedDelete(int $delay, &$timer = null): Promise + public function delayedDelete(int $delay, &$timer = null): PromiseInterface { $deferred = new Deferred(); @@ -925,9 +925,9 @@ public function delayedDelete(int $delay, &$timer = null): Promise * * @throws NoPermissionsException Missing read_message_history permission. * - * @return Promise + * @return PromiseInterface */ - public function react($emoticon): Promise + public function react($emoticon): PromiseInterface { if ($emoticon instanceof Emoji) { $emoticon = $emoticon->toReactionString(); @@ -956,9 +956,9 @@ public function react($emoticon): Promise * @throws \UnexpectedValueException Invalid reaction `$type`. * @throws NoPermissionsException Missing manage_messages permission when deleting others reaction. * - * @return Promise + * @return PromiseInterface */ - public function deleteReaction(int $type, $emoticon = null, ?string $id = null): Promise + public function deleteReaction(int $type, $emoticon = null, ?string $id = null): PromiseInterface { if ($emoticon instanceof Emoji) { $emoticon = $emoticon->toReactionString(); @@ -1000,9 +1000,9 @@ public function deleteReaction(int $type, $emoticon = null, ?string $id = null): * * @param MessageBuilder $message Contains the new contents of the message. Note that fields not specified in the builder will not be overwritten. * - * @return Promise + * @return PromiseInterface */ - public function edit(MessageBuilder $message): Promise + public function edit(MessageBuilder $message): PromiseInterface { return $this->_edit($message)->then(function ($response) { $this->fill((array) $response); @@ -1011,7 +1011,7 @@ public function edit(MessageBuilder $message): Promise }); } - private function _edit(MessageBuilder $message): Promise + private function _edit(MessageBuilder $message): PromiseInterface { if ($message->requiresMultipart()) { $multipart = $message->toMultipart(); @@ -1027,12 +1027,12 @@ private function _edit(MessageBuilder $message): Promise * * @link https://discord.com/developers/docs/resources/channel#delete-message * - * @return Promise + * @return PromiseInterface * * @throws \RuntimeException This type of message cannot be deleted. * @throws NoPermissionsException Missing manage_messages permission when deleting others message. */ - public function delete(): Promise + public function delete(): PromiseInterface { if (! $this->isDeletable()) { return reject(new \RuntimeException("Cannot delete this type of message: {$this->type}", 50021)); @@ -1055,9 +1055,9 @@ public function delete(): Promise * @param int $options['time'] Time in milliseconds until the collector finishes or false. * @param int $options['limit'] The amount of reactions allowed or false. * - * @return Promise> + * @return PromiseInterface> */ - public function createReactionCollector(callable $filter, array $options = []): Promise + public function createReactionCollector(callable $filter, array $options = []): PromiseInterface { $deferred = new Deferred(); $reactions = new Collection([], null, null); @@ -1106,9 +1106,9 @@ public function createReactionCollector(callable $filter, array $options = []): * * @param Embed $embed * - * @return Promise + * @return PromiseInterface */ - public function addEmbed(Embed $embed): Promise + public function addEmbed(Embed $embed): PromiseInterface { return $this->edit(MessageBuilder::new() ->addEmbed($embed)); diff --git a/src/Discord/Parts/Channel/Reaction.php b/src/Discord/Parts/Channel/Reaction.php index f9e780e23..b12f3b23d 100644 --- a/src/Discord/Parts/Channel/Reaction.php +++ b/src/Discord/Parts/Channel/Reaction.php @@ -17,7 +17,7 @@ use Discord\Parts\Guild\Guild; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use function Discord\normalizePartId; @@ -70,7 +70,7 @@ public function isPartial(): bool /** * {@inheritDoc} */ - public function fetch(): Promise + public function fetch(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_MESSAGE, $this->channel_id, $this->message_id)) ->then(function ($message) { @@ -101,9 +101,9 @@ protected function getIdAttribute(): string * * @link https://discord.com/developers/docs/resources/channel#get-reactions * - * @return Promise + * @return PromiseInterface */ - public function getUsers(array $options = []): Promise + public function getUsers(array $options = []): PromiseInterface { $query = Endpoint::bind(Endpoint::MESSAGE_REACTION_EMOJI, $this->channel_id, $this->message_id, urlencode($this->emoji->id === null ? $this->emoji->name : "{$this->emoji->name}:{$this->emoji->id}")); @@ -144,9 +144,9 @@ public function getUsers(array $options = []): Promise * * @see Message::getUsers() * - * @return Promise + * @return PromiseInterface */ - public function getAllUsers(): Promise + public function getAllUsers(): PromiseInterface { $response = Collection::for(User::class); $getUsers = function ($after = null) use (&$getUsers, $response) { diff --git a/src/Discord/Parts/Channel/Webhook.php b/src/Discord/Parts/Channel/Webhook.php index 6e97fca90..2c585a623 100644 --- a/src/Discord/Parts/Channel/Webhook.php +++ b/src/Discord/Parts/Channel/Webhook.php @@ -18,7 +18,7 @@ use Discord\Parts\Part; use Discord\Parts\User\User; use Discord\Repository\Channel\WebhookMessageRepository; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -85,9 +85,9 @@ class Webhook extends Part * @param MessageBuilder|array $data * @param array $queryparams Query string params to add to the request. * - * @return Promise + * @return PromiseInterface */ - public function execute($data, array $queryparams = []): Promise + public function execute($data, array $queryparams = []): PromiseInterface { $endpoint = Endpoint::bind(Endpoint::WEBHOOK_EXECUTE, $this->id, $this->token); @@ -129,9 +129,9 @@ public function execute($data, array $queryparams = []): Promise * @param MessageBuilder $builder The new message. * @param array $queryparams Query string params to add to the request. * - * @return Promise + * @return PromiseInterface */ - public function updateMessage(string $message_id, MessageBuilder $builder, array $queryparams = []): Promise + public function updateMessage(string $message_id, MessageBuilder $builder, array $queryparams = []): PromiseInterface { $endpoint = Endpoint::bind(Endpoint::WEBHOOK_MESSAGE, $this->id, $this->token, $message_id); diff --git a/src/Discord/Parts/Guild/Guild.php b/src/Discord/Parts/Guild/Guild.php index e697db889..b076b0092 100644 --- a/src/Discord/Parts/Guild/Guild.php +++ b/src/Discord/Parts/Guild/Guild.php @@ -39,7 +39,7 @@ use Discord\Repository\Guild\ScheduledEventRepository; use Discord\Repository\Guild\GuildTemplateRepository; use Discord\Repository\Guild\IntegrationRepository; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use ReflectionClass; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -399,9 +399,9 @@ protected function setStickersAttribute(?array $stickers): void * * @throws NoPermissionsException Missing manage_guild permission. * - * @return Promise + * @return PromiseInterface */ - public function getInvites(): Promise + public function getInvites(): PromiseInterface { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_guild) { @@ -429,9 +429,9 @@ public function getInvites(): Promise * * @throws NoPermissionsException Missing ban_members permission. * - * @return Promise + * @return PromiseInterface */ - public function unban($user): Promise + public function unban($user): PromiseInterface { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->ban_members) { @@ -720,9 +720,9 @@ protected function getFeatureWelcomeScreenEnabledAttribute(): bool * * @link https://discord.com/developers/docs/resources/voice#list-voice-regions * - * @return Promise + * @return PromiseInterface */ - public function getVoiceRegions(): Promise + public function getVoiceRegions(): PromiseInterface { if (null !== $this->regions) { return resolve($this->regions); @@ -747,9 +747,9 @@ public function getVoiceRegions(): Promise * * @throws NoPermissionsException Missing manage_roles permission. * - * @return Promise + * @return PromiseInterface */ - public function createRole(array $data = [], ?string $reason = null): Promise + public function createRole(array $data = [], ?string $reason = null): PromiseInterface { $botperms = $this->getBotPermissions(); @@ -775,9 +775,9 @@ public function createRole(array $data = [], ?string $reason = null): Promise * @throws NoPermissionsException Missing manage_guild_expressions permission. * @throws FileNotFoundException File does not exist. * - * @return Promise + * @return PromiseInterface */ - public function createEmoji(array $options, ?string $filepath = null, ?string $reason = null): Promise + public function createEmoji(array $options, ?string $filepath = null, ?string $reason = null): PromiseInterface { $resolver = new OptionsResolver(); $resolver @@ -851,9 +851,9 @@ public function createEmoji(array $options, ?string $filepath = null, ?string $r * @throws \DomainException File format is not PNG, APNG, or Lottie JSON. * @throws \RuntimeException Guild is not verified or partnered to upload Lottie stickers. * - * @return Promise + * @return PromiseInterface */ - public function createSticker(array $options, string $filepath, ?string $reason = null): Promise + public function createSticker(array $options, string $filepath, ?string $reason = null): PromiseInterface { $resolver = new OptionsResolver(); $resolver @@ -951,9 +951,9 @@ public function createSticker(array $options, string $filepath, ?string $reason /** * Leaves the guild. * - * @return Promise + * @return PromiseInterface */ - public function leave(): Promise + public function leave(): PromiseInterface { return $this->discord->guilds->leave($this->id); } @@ -966,9 +966,9 @@ public function leave(): Promise * * @throws \RuntimeException Ownership not transferred correctly. * - * @return Promise + * @return PromiseInterface */ - public function transferOwnership($member, ?string $reason = null): Promise + public function transferOwnership($member, ?string $reason = null): PromiseInterface { if ($member instanceof Member) { $member = $member->id; @@ -993,11 +993,11 @@ public function transferOwnership($member, ?string $reason = null): Promise * * @deprecated 10.0.0 Use `Channel::$rtc_region`. * - * @return Promise + * @return PromiseInterface * * @see Guild::REGION_DEFAULT The default region. */ - public function validateRegion(): Promise + public function validateRegion(): PromiseInterface { return $this->getVoiceRegions()->then(function () { $regions = $this->regions->map(function ($region) { @@ -1026,9 +1026,9 @@ public function validateRegion(): Promise * * @throws NoPermissionsException Missing view_audit_log permission. * - * @return Promise + * @return PromiseInterface */ - public function getAuditLog(array $options = []): Promise + public function getAuditLog(array $options = []): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1092,9 +1092,9 @@ public function getBotPermissions(): ?RolePermission * * @throws NoPermissionsException Missing manage_roles permission. * - * @return Promise + * @return PromiseInterface */ - public function updateRolePositions(array $roles): Promise + public function updateRolePositions(array $roles): PromiseInterface { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_roles) { @@ -1135,9 +1135,9 @@ public function updateRolePositions(array $roles): Promise * @param string|null $options['query'] Query string to match username(s) and nickname(s) against * @param int|null $options['limit'] How many entries are returned (default 1, minimum 1, maximum 1000) * - * @return Promise + * @return PromiseInterface */ - public function searchMembers(array $options): Promise + public function searchMembers(array $options): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1182,9 +1182,9 @@ public function searchMembers(array $options): Promise * * @throws NoPermissionsException Missing kick_members permission. * - * @return Promise The number of members that would be removed. + * @return PromiseInterface The number of members that would be removed. */ - public function getPruneCount(array $options = []): Promise + public function getPruneCount(array $options = []): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1238,9 +1238,9 @@ public function getPruneCount(array $options = []): Promise * * @throws NoPermissionsException Missing kick_members permission. * - * @return Promise The number of members that were removed in the prune operation. + * @return PromiseInterface The number of members that were removed in the prune operation. */ - public function beginPrune(array $options = [], ?string $reason = null): Promise + public function beginPrune(array $options = [], ?string $reason = null): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1289,9 +1289,9 @@ public function beginPrune(array $options = [], ?string $reason = null): Promise * * @throws NoPermissionsException Missing manage_guild permission when the welcome screen is not enabled. * - * @return Promise + * @return PromiseInterface */ - public function getWelcomeScreen(bool $fresh = false): Promise + public function getWelcomeScreen(bool $fresh = false): PromiseInterface { if (! $this->feature_welcome_screen_enabled) { $botperms = $this->getBotPermissions(); @@ -1337,9 +1337,9 @@ protected function getWelcomeScreenAttribute(): ?WelcomeScreen * * @throws NoPermissionsException Missing manage_guild permission. * - * @return Promise The updated Welcome Screen. + * @return PromiseInterface The updated Welcome Screen. */ - public function updateWelcomeScreen(array $options): Promise + public function updateWelcomeScreen(array $options): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1381,9 +1381,9 @@ public function updateWelcomeScreen(array $options): Promise * * @throws NoPermissionsException Missing manage_guild permission. * - * @return Promise + * @return PromiseInterface */ - public function getWidgetSettings(): Promise + public function getWidgetSettings(): PromiseInterface { $botperms = $this->getBotPermissions(); if ($botperms && ! $botperms->manage_guild) { @@ -1411,9 +1411,9 @@ public function getWidgetSettings(): Promise * * @throws NoPermissionsException Missing manage_guild permission. * - * @return Promise The updated guild widget object. + * @return PromiseInterface The updated guild widget object. */ - public function updateWidgetSettings(array $options, ?string $reason = null): Promise + public function updateWidgetSettings(array $options, ?string $reason = null): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefined([ @@ -1448,9 +1448,9 @@ public function updateWidgetSettings(array $options, ?string $reason = null): Pr * * @link https://discord.com/developers/docs/resources/guild#get-guild-widget * - * @return Promise + * @return PromiseInterface */ - public function getWidget(): Promise + public function getWidget(): PromiseInterface { return $this->factory->part(Widget::class, ['id' => $this->id])->fetch(); } @@ -1463,9 +1463,9 @@ public function getWidget(): Promise * @throws \RuntimeException No possible channels to create Invite on. * @throws NoPermissionsException * - * @return Promise + * @return PromiseInterface */ - public function createInvite(...$args): Promise + public function createInvite(...$args): PromiseInterface { $channel = $this->channels->find(function (Channel $channel) { if ($channel->canInvite()) { @@ -1494,9 +1494,9 @@ public function createInvite(...$args): Promise * @param int $level The new MFA level `Guild::MFA_NONE` or `Guild::MFA_ELEVATED`. * @param string|null $reason Reason for Audit Log. * - * @return Promise This guild. + * @return PromiseInterface This guild. */ - public function updateMFALevel(int $level, ?string $reason = null): Promise + public function updateMFALevel(int $level, ?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -1525,9 +1525,9 @@ public function updateMFALevel(int $level, ?string $reason = null): Promise * administrator for COMMUNITY or DISCOVERABLE. * manage_guild for INVITES_DISABLED or RAID_ALERTS_ENABLED. * - * @return Promise This guild. + * @return PromiseInterface This guild. */ - public function setFeatures(array $features, ?string $reason = null): Promise + public function setFeatures(array $features, ?string $reason = null): PromiseInterface { if ($botperms = $this->getBotPermissions()) { if ((isset($features['COMMUNITY']) || isset($features['DISCOVERABLE'])) && ! $botperms->administrator) { diff --git a/src/Discord/Parts/Guild/GuildTemplate.php b/src/Discord/Parts/Guild/GuildTemplate.php index f6d9e1871..75c2993a4 100644 --- a/src/Discord/Parts/Guild/GuildTemplate.php +++ b/src/Discord/Parts/Guild/GuildTemplate.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -130,9 +130,9 @@ protected function getUpdatedAtAttribute(): Carbon * @param string $options['name'] The name of the guild (2-100 characters). * @param string|null $options['icon'] The base64 128x128 image for the guild icon. * - * @return Promise + * @return PromiseInterface */ - public function createGuild($options = []): Promise + public function createGuild($options = []): PromiseInterface { $resolver = new OptionsResolver(); $resolver diff --git a/src/Discord/Parts/Guild/ScheduledEvent.php b/src/Discord/Parts/Guild/ScheduledEvent.php index d16082e66..429330633 100644 --- a/src/Discord/Parts/Guild/ScheduledEvent.php +++ b/src/Discord/Parts/Guild/ScheduledEvent.php @@ -17,7 +17,7 @@ use Discord\Parts\Channel\Channel; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use function React\Promise\reject; @@ -95,9 +95,9 @@ class ScheduledEvent extends Part * * @throws \RangeException * - * @return Promise + * @return PromiseInterface */ - public function getUsers(array $options): Promise + public function getUsers(array $options): PromiseInterface { $resolver = new OptionsResolver(); $resolver->setDefaults(['limit' => 100, 'with_member' => false]); diff --git a/src/Discord/Parts/Guild/Widget.php b/src/Discord/Parts/Guild/Widget.php index 332093df2..adcff1596 100644 --- a/src/Discord/Parts/Guild/Widget.php +++ b/src/Discord/Parts/Guild/Widget.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Http\Http; use Discord\Parts\Part; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * A Widget of a Guild. @@ -86,7 +86,7 @@ class Widget extends Part /** * {@inheritDoc} */ - public function fetch(): Promise + public function fetch(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::GUILD_WIDGET, $this->id)) ->then(function ($response) { diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index eb7c21f1b..208f6c979 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -29,7 +29,7 @@ use Discord\Parts\User\Member; use Discord\Parts\User\User; use Discord\WebSockets\Event; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use function Discord\poly_strlen; use function React\Promise\reject; @@ -225,9 +225,9 @@ protected function getAppPermissionsAttribute(): ?ChannelPermission * * @throws \LogicException Interaction is not Message Component or Modal Submit. * - * @return Promise + * @return PromiseInterface */ - public function acknowledge(): Promise + public function acknowledge(): PromiseInterface { if ($this->type == InteractionType::APPLICATION_COMMAND) { return $this->acknowledgeWithResponse(); @@ -252,9 +252,9 @@ public function acknowledge(): Promise * * @throws \LogicException Interaction is not Application Command, Message Component, or Modal Submit. * - * @return Promise + * @return PromiseInterface */ - public function acknowledgeWithResponse(bool $ephemeral = false): Promise + public function acknowledgeWithResponse(bool $ephemeral = false): PromiseInterface { if (! in_array($this->type, [InteractionType::APPLICATION_COMMAND, InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only acknowledge application command, message component, or modal submit interactions.')); @@ -276,9 +276,9 @@ public function acknowledgeWithResponse(bool $ephemeral = false): Promise * * @throws \LogicException Interaction is not Message Component. * - * @return Promise + * @return PromiseInterface */ - public function updateMessage(MessageBuilder $builder): Promise + public function updateMessage(MessageBuilder $builder): PromiseInterface { if (! in_array($this->type, [InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only update messages that occur due to a message component interaction.')); @@ -297,9 +297,9 @@ public function updateMessage(MessageBuilder $builder): Promise * * @throws \RuntimeException Interaction is not created yet. * - * @return Promise + * @return PromiseInterface */ - public function getOriginalResponse(): Promise + public function getOriginalResponse(): PromiseInterface { if (! $this->created) { return reject(new \RuntimeException('Interaction has not been created yet.')); @@ -322,15 +322,15 @@ public function getOriginalResponse(): Promise * * @throws \RuntimeException Interaction is not responded yet. * - * @return Promise + * @return PromiseInterface */ - public function updateOriginalResponse(MessageBuilder $builder): Promise + public function updateOriginalResponse(MessageBuilder $builder): PromiseInterface { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); } - return (function () use ($builder): Promise { + return (function () use ($builder): PromiseInterface { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -350,9 +350,9 @@ public function updateOriginalResponse(MessageBuilder $builder): Promise * * @throws \RuntimeException Interaction is not responded yet. * - * @return Promise + * @return PromiseInterface */ - public function deleteOriginalResponse(): Promise + public function deleteOriginalResponse(): PromiseInterface { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); @@ -371,9 +371,9 @@ public function deleteOriginalResponse(): Promise * * @throws \RuntimeException Interaction is not responded yet. * - * @return Promise + * @return PromiseInterface */ - public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = false): Promise + public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = false): PromiseInterface { if (! $this->responded && $this->type != InteractionType::MESSAGE_COMPONENT) { return reject(new \RuntimeException('Cannot create a follow-up message as the interaction has not been responded to.')); @@ -383,7 +383,7 @@ public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = f $builder->_setFlags(Message::FLAG_EPHEMERAL); } - return (function () use ($builder): Promise { + return (function () use ($builder): PromiseInterface { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -406,9 +406,9 @@ public function sendFollowUpMessage(MessageBuilder $builder, bool $ephemeral = f * * @throws \LogicException Interaction is not Application Command, Message Component, or Modal Submit. * - * @return Promise + * @return PromiseInterface */ - public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = false): Promise + public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = false): PromiseInterface { if (! in_array($this->type, [InteractionType::APPLICATION_COMMAND, InteractionType::MESSAGE_COMPONENT, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You can only acknowledge application command, message component, or modal submit interactions.')); @@ -437,9 +437,9 @@ public function respondWithMessage(MessageBuilder $builder, bool $ephemeral = fa * * @throws \RuntimeException Interaction is already responded. * - * @return Promise + * @return PromiseInterface */ - protected function respond(array $payload, ?Multipart $multipart = null): Promise + protected function respond(array $payload, ?Multipart $multipart = null): PromiseInterface { if ($this->responded) { return reject(new \RuntimeException('Interaction has already been responded to.')); @@ -472,7 +472,7 @@ protected function respond(array $payload, ?Multipart $multipart = null): Promis * * @throws \RuntimeException Interaction is not responded yet. * - * @return Promise + * @return PromiseInterface */ public function updateFollowUpMessage(string $message_id, MessageBuilder $builder) { @@ -480,7 +480,7 @@ public function updateFollowUpMessage(string $message_id, MessageBuilder $builde return reject(new \RuntimeException('Cannot create a follow-up message as the interaction has not been responded to.')); } - return (function () use ($message_id, $builder): Promise { + return (function () use ($message_id, $builder): PromiseInterface { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -502,9 +502,9 @@ public function updateFollowUpMessage(string $message_id, MessageBuilder $builde * * @throws \RuntimeException Interaction is not created yet. * - * @return Promise + * @return PromiseInterface */ - public function getFollowUpMessage(string $message_id): Promise + public function getFollowUpMessage(string $message_id): PromiseInterface { if (! $this->created) { return reject(new \RuntimeException('Interaction has not been created yet.')); @@ -527,9 +527,9 @@ public function getFollowUpMessage(string $message_id): Promise * * @throws \RuntimeException Interaction is not responded yet. * - * @return Promise + * @return PromiseInterface */ - public function deleteFollowUpMessage(string $message_id): Promise + public function deleteFollowUpMessage(string $message_id): PromiseInterface { if (! $this->responded) { return reject(new \RuntimeException('Interaction has not been responded to.')); @@ -547,9 +547,9 @@ public function deleteFollowUpMessage(string $message_id): Promise * * @throws \LogicException Interaction is not Autocomplete. * - * @return Promise + * @return PromiseInterface */ - public function autoCompleteResult(array $choices): Promise + public function autoCompleteResult(array $choices): PromiseInterface { if ($this->type != InteractionType::APPLICATION_COMMAND_AUTOCOMPLETE) { return reject(new \LogicException('You can only respond command option results with auto complete interactions.')); @@ -574,9 +574,9 @@ public function autoCompleteResult(array $choices): Promise * @throws \LogicException Interaction is Ping or Modal Submit. * @throws \LengthException Modal title is longer than 45 characters. * - * @return Promise + * @return PromiseInterface */ - public function showModal(string $title, string $custom_id, array $components, ?callable $submit = null): Promise + public function showModal(string $title, string $custom_id, array $components, ?callable $submit = null): PromiseInterface { if (in_array($this->type, [InteractionType::PING, InteractionType::MODAL_SUBMIT])) { return reject(new \LogicException('You cannot pop up a modal from a ping or modal submit interaction.')); diff --git a/src/Discord/Parts/Part.php b/src/Discord/Parts/Part.php index 17e39b181..c13909d16 100644 --- a/src/Discord/Parts/Part.php +++ b/src/Discord/Parts/Part.php @@ -17,7 +17,7 @@ use Discord\Factory\Factory; use Discord\Http\Http; use JsonSerializable; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * This class is the base of all objects that are returned. All "Parts" extend @@ -149,9 +149,9 @@ public function isPartial(): bool * * @throws \RuntimeException The part is not fetchable. * - * @return Promise + * @return PromiseInterface */ - public function fetch(): Promise + public function fetch(): PromiseInterface { throw new \RuntimeException('This part is not fetchable.'); } diff --git a/src/Discord/Parts/Thread/Member.php b/src/Discord/Parts/Thread/Member.php index cf673b0f6..a429a5553 100644 --- a/src/Discord/Parts/Thread/Member.php +++ b/src/Discord/Parts/Thread/Member.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Part; use Discord\Parts\User\User; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * Represents a member that belongs to a thread. Not the same as a user nor a @@ -70,9 +70,9 @@ protected function getJoinTimestampAttribute(): Carbon * * @link https://discord.com/developers/docs/resources/channel#remove-thread-member * - * @return Promise + * @return PromiseInterface */ - public function remove(): Promise + public function remove(): PromiseInterface { return $this->http->delete(Endpoint::bind(Endpoint::THREAD_MEMBER, $this->id, $this->user_id)); } diff --git a/src/Discord/Parts/Thread/Thread.php b/src/Discord/Parts/Thread/Thread.php index 3bc531aae..6079e2c93 100644 --- a/src/Discord/Parts/Thread/Thread.php +++ b/src/Discord/Parts/Thread/Thread.php @@ -29,7 +29,7 @@ use Discord\Repository\Thread\MemberRepository; use Discord\WebSockets\Event; use React\Promise\Deferred; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Traversable; @@ -74,7 +74,7 @@ * @property MessageRepository $messages Repository of messages sent in the thread. * @property MemberRepository $members Repository of members in the thread. * - * @method Promise sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class Thread extends Part { @@ -304,9 +304,9 @@ protected function getCreateTimestampAttribute(): ?Carbon * * @link https://discord.com/developers/docs/resources/channel#join-thread * - * @return Promise + * @return PromiseInterface */ - public function join(): Promise + public function join(): PromiseInterface { return $this->http->put(Endpoint::bind(Endpoint::THREAD_MEMBER_ME, $this->id)); } @@ -318,9 +318,9 @@ public function join(): Promise * * @param User|Member|string $user User to add. Can be one of the user objects or a user ID. * - * @return Promise + * @return PromiseInterface */ - public function addMember($user): Promise + public function addMember($user): PromiseInterface { if ($user instanceof User || $user instanceof Member) { $user = $user->id; @@ -334,9 +334,9 @@ public function addMember($user): Promise * * @link https://discord.com/developers/docs/resources/channel#leave-thread * - * @return Promise + * @return PromiseInterface */ - public function leave(): Promise + public function leave(): PromiseInterface { return $this->http->delete(Endpoint::bind(Endpoint::THREAD_MEMBER_ME, $this->id)); } @@ -348,9 +348,9 @@ public function leave(): Promise * * @param User|Member|ThreadMember|string $user User to remove. Can be one of the user objects or a user ID. * - * @return Promise + * @return PromiseInterface */ - public function removeMember($user): Promise + public function removeMember($user): PromiseInterface { if ($user instanceof User || $user instanceof Member) { $user = $user->id; @@ -367,9 +367,9 @@ public function removeMember($user): Promise * @param string $name New thread name. * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface */ - public function rename(string $name, ?string $reason = null): Promise + public function rename(string $name, ?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -389,9 +389,9 @@ public function rename(string $name, ?string $reason = null): Promise * * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface */ - public function archive(?string $reason = null): Promise + public function archive(?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -411,9 +411,9 @@ public function archive(?string $reason = null): Promise * * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface */ - public function unarchive(?string $reason = null): Promise + public function unarchive(?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -434,9 +434,9 @@ public function unarchive(?string $reason = null): Promise * @param int $duration Duration in minutes. * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface */ - public function setAutoArchiveDuration(int $duration, ?string $reason = null): Promise + public function setAutoArchiveDuration(int $duration, ?string $reason = null): PromiseInterface { $headers = []; if (isset($reason)) { @@ -456,11 +456,11 @@ public function setAutoArchiveDuration(int $duration, ?string $reason = null): P * * @link https://discord.com/developers/docs/resources/channel#get-pinned-messages * - * @return Promise> + * @return PromiseInterface> * * @todo Make it in a trait along with Channel */ - public function getPinnedMessages(): Promise + public function getPinnedMessages(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::CHANNEL_PINS, $this->id)) ->then(function ($responses) { @@ -482,11 +482,11 @@ public function getPinnedMessages(): Promise * @param array|Traversable $messages An array of messages to delete. * @param string|null $reason Reason for Audit Log (only for bulk messages). * - * @return Promise + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function deleteMessages($messages, ?string $reason = null): Promise + public function deleteMessages($messages, ?string $reason = null): PromiseInterface { if (! is_array($messages) && ! ($messages instanceof Traversable)) { return reject(new \InvalidArgumentException('$messages must be an array or implement Traversable.')); @@ -536,11 +536,11 @@ public function deleteMessages($messages, ?string $reason = null): Promise * * @param array $options * - * @return Promise> + * @return PromiseInterface> * * @todo Make it in a trait along with Channel */ - public function getMessageHistory(array $options): Promise + public function getMessageHistory(array $options): PromiseInterface { $resolver = new OptionsResolver(); $resolver @@ -600,11 +600,11 @@ public function getMessageHistory(array $options): Promise * * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function pinMessage(Message $message, ?string $reason = null): Promise + public function pinMessage(Message $message, ?string $reason = null): PromiseInterface { if ($message->pinned) { return reject(new \RuntimeException('This message is already pinned.')); @@ -636,11 +636,11 @@ public function pinMessage(Message $message, ?string $reason = null): Promise * * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function unpinMessage(Message $message, ?string $reason = null): Promise + public function unpinMessage(Message $message, ?string $reason = null): PromiseInterface { if (! $message->pinned) { return reject(new \RuntimeException('This message is not pinned.')); @@ -677,11 +677,11 @@ public function unpinMessage(Message $message, ?string $reason = null): Promise * @param array|null $allowed_mentions Allowed mentions object for the message. * @param Message|null $replyTo Sends the message as a reply to the given message instance. * - * @return Promise + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): Promise + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface { // Backwards compatible support for old `sendMessage` function signature. if (! ($message instanceof MessageBuilder)) { @@ -727,11 +727,11 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @param Embed $embed Embed to send. * - * @return Promise + * @return PromiseInterface * * @todo Make it in a trait along with Channel */ - public function sendEmbed(Embed $embed): Promise + public function sendEmbed(Embed $embed): PromiseInterface { return $this->sendMessage(MessageBuilder::new() ->addEmbed($embed)); @@ -746,9 +746,9 @@ public function sendEmbed(Embed $embed): Promise * * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface */ - public function broadcastTyping(): Promise + public function broadcastTyping(): PromiseInterface { return $this->http->post(Endpoint::bind(Endpoint::CHANNEL_TYPING, $this->id)); } @@ -761,11 +761,11 @@ public function broadcastTyping(): Promise * @param int $options ['time'] Time in milliseconds until the collector finishes or false. * @param int $options ['limit'] The amount of messages allowed or false. * - * @return Promise> + * @return PromiseInterface> * * @todo Make it in a trait along with Channel */ - public function createMessageCollector(callable $filter, array $options = []): Promise + public function createMessageCollector(callable $filter, array $options = []): PromiseInterface { $deferred = new Deferred(); $messages = new Collection([], null, null); diff --git a/src/Discord/Parts/User/Client.php b/src/Discord/Parts/User/Client.php index 98c1419d9..71b0dd45d 100644 --- a/src/Discord/Parts/User/Client.php +++ b/src/Discord/Parts/User/Client.php @@ -18,7 +18,7 @@ use Discord\Repository\GuildRepository; use Discord\Repository\PrivateChannelRepository; use Discord\Repository\UserRepository; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * The client is the main interface for the client. Most calls on the main class are forwarded here. @@ -142,9 +142,9 @@ protected function getAvatarHashAttribute(): ?string /** * Saves the client instance. * - * @return Promise + * @return PromiseInterface */ - public function save(): Promise + public function save(): PromiseInterface { return $this->http->patch(Endpoint::USER_CURRENT, $this->getUpdatableAttributes()); } diff --git a/src/Discord/Parts/User/Member.php b/src/Discord/Parts/User/Member.php index 95838a699..c12d64769 100644 --- a/src/Discord/Parts/User/Member.php +++ b/src/Discord/Parts/User/Member.php @@ -28,7 +28,7 @@ use Discord\Parts\Permissions\RolePermission; use Discord\Parts\Thread\Thread; use Discord\Parts\WebSockets\PresenceUpdate; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use function React\Promise\reject; @@ -63,7 +63,7 @@ * @property Collection|Activity[] $activities User's current activities. * @property object $client_status Current client status. * - * @method Promise sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class Member extends Part { @@ -129,9 +129,9 @@ public function updateFromPresence(PresenceUpdate $presence): PresenceUpdate * * @throws \RuntimeException Member has no `$guild` * - * @return Promise + * @return PromiseInterface */ - public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): Promise + public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): PromiseInterface { if (! $guild = $this->guild) { return reject(new \RuntimeException('Member has no Guild Part')); @@ -148,9 +148,9 @@ public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): * * @throws NoPermissionsException Missing manage_nicknames permission. * - * @return Promise + * @return PromiseInterface */ - public function setNickname(?string $nick = null, ?string $reason = null): Promise + public function setNickname(?string $nick = null, ?string $reason = null): PromiseInterface { $payload = [ 'nick' => $nick ?? '', @@ -188,9 +188,9 @@ public function setNickname(?string $nick = null, ?string $reason = null): Promi * @param Channel|?string $channel The channel to move the member to. * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface */ - public function moveMember($channel, ?string $reason = null): Promise + public function moveMember($channel, ?string $reason = null): PromiseInterface { if ($channel instanceof Channel) { $channel = $channel->id; @@ -218,9 +218,9 @@ public function moveMember($channel, ?string $reason = null): Promise * @throws \RuntimeException * @throws NoPermissionsException Missing manage_roles permission. * - * @return Promise + * @return PromiseInterface */ - public function addRole($role, ?string $reason = null): Promise + public function addRole($role, ?string $reason = null): PromiseInterface { if ($role instanceof Role) { $role = $role->id; @@ -262,9 +262,9 @@ public function addRole($role, ?string $reason = null): Promise * * @throws NoPermissionsException Missing manage_roles permission. * - * @return Promise + * @return PromiseInterface */ - public function removeRole($role, ?string $reason = null): Promise + public function removeRole($role, ?string $reason = null): PromiseInterface { if ($role instanceof Role) { $role = $role->id; @@ -301,9 +301,9 @@ public function removeRole($role, ?string $reason = null): Promise * * @throws NoPermissionsException Missing manage_roles permission. * - * @return Promise + * @return PromiseInterface */ - public function setRoles(array $roles, ?string $reason = null): Promise + public function setRoles(array $roles, ?string $reason = null): PromiseInterface { foreach ($roles as $i => $role) { if ($role instanceof Role) { @@ -348,9 +348,9 @@ public function setRoles(array $roles, ?string $reason = null): Promise * * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): Promise + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface { if ($user = $this->user) { return $user->sendMessage($message, $tts, $embed, $allowed_mentions, $replyTo); @@ -483,9 +483,9 @@ public function getPermissions($channel = null): ?RolePermission * * @throws NoPermissionsException Missing moderate_members permission. * - * @return Promise + * @return PromiseInterface */ - public function timeoutMember(?Carbon $communication_disabled_until, ?string $reason = null): Promise + public function timeoutMember(?Carbon $communication_disabled_until, ?string $reason = null): PromiseInterface { if ($guild = $this->guild) { if ($botperms = $guild->getBotPermissions()) { @@ -516,9 +516,9 @@ public function timeoutMember(?Carbon $communication_disabled_until, ?string $re * * @throws NoPermissionsException Missing `moderate_members` permission. * - * @return Promise + * @return PromiseInterface */ - public function setBypassesVerification(bool $bypasses_verification, ?string $reason = null): Promise + public function setBypassesVerification(bool $bypasses_verification, ?string $reason = null): PromiseInterface { if ($guild = $this->guild) { if ($botperms = $guild->getBotPermissions()) { diff --git a/src/Discord/Parts/User/User.php b/src/Discord/Parts/User/User.php index c2dde1508..ca8f69294 100644 --- a/src/Discord/Parts/User/User.php +++ b/src/Discord/Parts/User/User.php @@ -16,7 +16,7 @@ use Discord\Parts\Channel\Channel; use Discord\Parts\Part; use Discord\Parts\Channel\Message; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -47,7 +47,7 @@ * @property int|null $premium_type Type of nitro subscription. * @property int|null $public_flags Public flags on the user. * - * @method Promise sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class User extends Part { @@ -100,9 +100,9 @@ class User extends Part * * @link https://discord.com/developers/docs/resources/user#create-dm * - * @return Promise + * @return PromiseInterface */ - public function getPrivateChannel(): Promise + public function getPrivateChannel(): PromiseInterface { if ($channel = $this->discord->private_channels->get('recipient_id', $this->id)) { return resolve($channel); @@ -130,9 +130,9 @@ public function getPrivateChannel(): Promise * @param array|null $allowed_mentions Allowed mentions object for the message. * @param Message|null $replyTo Sends the message as a reply to the given message instance. * - * @return Promise + * @return PromiseInterface */ - public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): Promise + public function sendMessage($message, bool $tts = false, $embed = null, $allowed_mentions = null, ?Message $replyTo = null): PromiseInterface { return $this->getPrivateChannel()->then(function (Channel $channel) use ($message, $tts, $embed, $allowed_mentions, $replyTo) { return $channel->sendMessage($message, $tts, $embed, $allowed_mentions, $replyTo); @@ -146,9 +146,9 @@ public function sendMessage($message, bool $tts = false, $embed = null, $allowed * * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface */ - public function broadcastTyping(): Promise + public function broadcastTyping(): PromiseInterface { return $this->getPrivateChannel()->then(function (Channel $channel) { return $channel->broadcastTyping(); diff --git a/src/Discord/Parts/WebSockets/MessageReaction.php b/src/Discord/Parts/WebSockets/MessageReaction.php index 48119b9e3..294a084a6 100644 --- a/src/Discord/Parts/WebSockets/MessageReaction.php +++ b/src/Discord/Parts/WebSockets/MessageReaction.php @@ -19,7 +19,7 @@ use Discord\Parts\Part; use Discord\Parts\User\Member; use Discord\Parts\User\User; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use function React\Promise\reject; use function React\Promise\resolve; @@ -71,7 +71,7 @@ public function isPartial(): bool /** * {@inheritDoc} */ - public function fetch(): Promise + public function fetch(): PromiseInterface { $promise = resolve(); @@ -229,14 +229,14 @@ protected function getEmojiAttribute(): Emoji * * @throws \RuntimeException Reaction has no user id. * - * @return Promise + * @return PromiseInterface * * @see Message::deleteReaction() * * @link https://discord.com/developers/docs/resources/channel#delete-own-reaction * @link https://discord.com/developers/docs/resources/channel#delete-user-reaction */ - public function delete(?int $type = null): Promise + public function delete(?int $type = null): PromiseInterface { if ($type === null) { if ($this->user_id == $this->discord->id) { diff --git a/src/Discord/Repository/AbstractRepository.php b/src/Discord/Repository/AbstractRepository.php index 9450404f9..61e89b4d4 100755 --- a/src/Discord/Repository/AbstractRepository.php +++ b/src/Discord/Repository/AbstractRepository.php @@ -18,7 +18,7 @@ use Discord\Http\Endpoint; use Discord\Http\Http; use Discord\Parts\Part; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Traversable; use WeakReference; @@ -100,11 +100,11 @@ public function __construct(Discord $discord, array $vars = []) * * @param array $queryparams Query string params to add to the request (no validation) * - * @return Promise + * @return PromiseInterface * * @throws \Exception */ - public function freshen(array $queryparams = []): Promise + public function freshen(array $queryparams = []): PromiseInterface { if (! isset($this->endpoints['all'])) { return reject(new \Exception('You cannot freshen this repository.')); @@ -134,9 +134,9 @@ public function freshen(array $queryparams = []): Promise /** * @param object $response * - * @return Promise + * @return PromiseInterface */ - protected function cacheFreshen($response): Promise + protected function cacheFreshen($response): PromiseInterface { foreach ($response as $value) { $value = array_merge($this->vars, (array) $value); @@ -174,11 +174,11 @@ public function create(array $attributes = [], bool $created = false): Part * @param Part $part The part to save. * @param string|null $reason Reason for Audit Log (if supported). * - * @return Promise + * @return PromiseInterface * * @throws \Exception */ - public function save(Part $part, ?string $reason = null): Promise + public function save(Part $part, ?string $reason = null): PromiseInterface { if ($part->created) { if (! isset($this->endpoints['update'])) { @@ -219,11 +219,11 @@ public function save(Part $part, ?string $reason = null): Promise * @param Part|string $part The part to delete. * @param string|null $reason Reason for Audit Log (if supported). * - * @return Promise + * @return PromiseInterface * * @throws \Exception */ - public function delete($part, ?string $reason = null): Promise + public function delete($part, ?string $reason = null): PromiseInterface { if (! isset($part)) { return reject(new \Exception('You cannot delete a non-existant part.')); @@ -265,11 +265,11 @@ public function delete($part, ?string $reason = null): Promise * @param Part $part The part to get fresh values. * @param array $queryparams Query string params to add to the request (no validation) * - * @return Promise + * @return PromiseInterface * * @throws \Exception */ - public function fresh(Part $part, array $queryparams = []): Promise + public function fresh(Part $part, array $queryparams = []): PromiseInterface { if (! $part->created) { return reject(new \Exception('You cannot get a non-existant part.')); @@ -301,9 +301,9 @@ public function fresh(Part $part, array $queryparams = []): Promise * * @throws \Exception * - * @return Promise + * @return PromiseInterface */ - public function fetch(string $id, bool $fresh = false): Promise + public function fetch(string $id, bool $fresh = false): PromiseInterface { if (! $fresh) { if (isset($this->items[$id])) { @@ -391,9 +391,9 @@ public function get(string $discrim, $key) * * @param string|int $offset * - * @return Promise + * @return PromiseInterface */ - public function cacheGet($offset): Promise + public function cacheGet($offset): PromiseInterface { return resolve($this->offsetGet($offset) ?? $this->cache->get($offset)); } @@ -444,9 +444,9 @@ public function pull($key, $default = null) * @param string|int $key * @param ?Part $default * - * @return Promise + * @return PromiseInterface */ - public function cachePull($key, $default = null): Promise + public function cachePull($key, $default = null): PromiseInterface { return $this->cacheGet($key)->then(fn ($item) => ($item === null) ? $default : $this->cache->delete($key)->then(fn ($success) => $item)); } diff --git a/src/Discord/Repository/Channel/ReactionRepository.php b/src/Discord/Repository/Channel/ReactionRepository.php index ac00d1ca4..6a7f73247 100644 --- a/src/Discord/Repository/Channel/ReactionRepository.php +++ b/src/Discord/Repository/Channel/ReactionRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Channel\Reaction; use Discord\Repository\AbstractRepository; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * Contains reactions on a message. @@ -51,11 +51,11 @@ class ReactionRepository extends AbstractRepository * * @param Reaction|string $part The Reaction part or unicode emoji to delete. * - * @return Promise + * @return PromiseInterface * * @since 10.0.0 */ - public function delete($part, ?string $reason = null): Promise + public function delete($part, ?string $reason = null): PromiseInterface { // Deal with unicode emoji if (is_string($part) && ! is_numeric($part)) { diff --git a/src/Discord/Repository/Channel/ThreadRepository.php b/src/Discord/Repository/Channel/ThreadRepository.php index 028e6a951..8018ccd16 100644 --- a/src/Discord/Repository/Channel/ThreadRepository.php +++ b/src/Discord/Repository/Channel/ThreadRepository.php @@ -15,7 +15,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Thread\Thread; use Discord\Repository\AbstractRepository; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -53,7 +53,7 @@ class ThreadRepository extends AbstractRepository /** * {@inheritDoc} */ - protected function cacheFreshen($response): Promise + protected function cacheFreshen($response): PromiseInterface { foreach ($response->threads as $value) { $value = array_merge($this->vars, (array) $value); @@ -87,9 +87,9 @@ protected function cacheFreshen($response): Promise * * @link https://discord.com/developers/docs/resources/channel#list-active-threads * - * @return Promise> + * @return PromiseInterface> */ - public function active(): Promise + public function active(): PromiseInterface { return $this->http->get(Endpoint::bind(Endpoint::GUILD_THREADS_ACTIVE, $this->vars['guild_id'])) ->then(function ($response) { @@ -111,9 +111,9 @@ public function active(): Promise * * @throws \InvalidArgumentException * - * @return Promise> + * @return PromiseInterface> */ - public function archived(bool $private = false, bool $joined = false, ?int $limit = null, $before = null): Promise + public function archived(bool $private = false, bool $joined = false, ?int $limit = null, $before = null): PromiseInterface { if ($joined) { if (! $private) { diff --git a/src/Discord/Repository/Guild/BanRepository.php b/src/Discord/Repository/Guild/BanRepository.php index d333a6815..0c975d6c5 100644 --- a/src/Discord/Repository/Guild/BanRepository.php +++ b/src/Discord/Repository/Guild/BanRepository.php @@ -16,7 +16,7 @@ use Discord\Parts\User\Member; use Discord\Parts\User\User; use Discord\Repository\AbstractRepository; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -63,9 +63,9 @@ class BanRepository extends AbstractRepository * @param array $options Array of Ban options 'delete_message_seconds' or 'delete_message_days' (deprecated). * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface */ - public function ban($user, array $options = [], ?string $reason = null): Promise + public function ban($user, array $options = [], ?string $reason = null): PromiseInterface { $content = []; $headers = []; @@ -122,9 +122,9 @@ public function ban($user, array $options = [], ?string $reason = null): Promise * @param User|Ban|string $ban User or Ban Part, or User ID * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface */ - public function unban($ban, ?string $reason = null): Promise + public function unban($ban, ?string $reason = null): PromiseInterface { if ($ban instanceof User || $ban instanceof Member) { $ban = $ban->id; diff --git a/src/Discord/Repository/Guild/GuildTemplateRepository.php b/src/Discord/Repository/Guild/GuildTemplateRepository.php index 519ca46f8..865f5bc0d 100644 --- a/src/Discord/Repository/Guild/GuildTemplateRepository.php +++ b/src/Discord/Repository/Guild/GuildTemplateRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\GuildTemplate; use Discord\Repository\AbstractRepository; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * Contains guild templates of a guild. @@ -58,9 +58,9 @@ class GuildTemplateRepository extends AbstractRepository * * @param string $template_code The guild template code. * - * @return Promise + * @return PromiseInterface */ - public function sync(string $template_code): Promise + public function sync(string $template_code): PromiseInterface { return $this->http->put(Endpoint::bind(Endpoint::GUILD_TEMPLATE, $this->vars['guild_id'], $template_code))->then(function ($guild_template) use ($template_code) { return $this->cache->get($template_code)->then(function ($guildTemplate) use ($guild_template, $template_code) { diff --git a/src/Discord/Repository/Guild/MemberRepository.php b/src/Discord/Repository/Guild/MemberRepository.php index 23eada336..91ab0ada7 100755 --- a/src/Discord/Repository/Guild/MemberRepository.php +++ b/src/Discord/Repository/Guild/MemberRepository.php @@ -15,7 +15,7 @@ use Discord\Parts\User\Member; use Discord\Repository\AbstractRepository; use React\Promise\Deferred; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * Contains members of a guild. @@ -56,9 +56,9 @@ class MemberRepository extends AbstractRepository * @param Member $member The member to kick. * @param string|null $reason Reason for Audit Log. * - * @return Promise + * @return PromiseInterface */ - public function kick(Member $member, ?string $reason = null): Promise + public function kick(Member $member, ?string $reason = null): PromiseInterface { return $this->delete($member, $reason); } @@ -68,7 +68,7 @@ public function kick(Member $member, ?string $reason = null): Promise * * @param array $queryparams Query string params to add to the request, leave null to paginate all members (Warning: Be careful to use this on very large guild) */ - public function freshen(array $queryparams = null): Promise + public function freshen(array $queryparams = null): PromiseInterface { if (isset($queryparams)) { return parent::freshen($queryparams); diff --git a/src/Discord/Repository/Guild/ScheduledEventRepository.php b/src/Discord/Repository/Guild/ScheduledEventRepository.php index 132266cec..46e49f694 100644 --- a/src/Discord/Repository/Guild/ScheduledEventRepository.php +++ b/src/Discord/Repository/Guild/ScheduledEventRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\ScheduledEvent; use Discord\Repository\AbstractRepository; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -55,9 +55,9 @@ class ScheduledEventRepository extends AbstractRepository * * @param bool $with_user_count Whether to include number of users subscribed to each event * - * @return Promise + * @return PromiseInterface */ - public function fetch(string $id, bool $fresh = false, bool $with_user_count = false): Promise + public function fetch(string $id, bool $fresh = false, bool $with_user_count = false): PromiseInterface { if (! $with_user_count) { return parent::fetch($id, $fresh); diff --git a/src/Discord/Repository/GuildRepository.php b/src/Discord/Repository/GuildRepository.php index fcc285cc2..aaf165576 100755 --- a/src/Discord/Repository/GuildRepository.php +++ b/src/Discord/Repository/GuildRepository.php @@ -13,7 +13,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\Guild; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * Contains guilds that the client is in. @@ -54,9 +54,9 @@ class GuildRepository extends AbstractRepository * * @param Guild|string $guild * - * @return Promise + * @return PromiseInterface */ - public function leave($guild): Promise + public function leave($guild): PromiseInterface { if ($guild instanceof Guild) { $guild = $guild->id; diff --git a/src/Discord/Voice/OggPage.php b/src/Discord/Voice/OggPage.php index fe57d9cf1..d9e616b35 100644 --- a/src/Discord/Voice/OggPage.php +++ b/src/Discord/Voice/OggPage.php @@ -13,7 +13,7 @@ use Discord\Helpers\Buffer; use Generator; -use React\Promise\Promise; +use React\Promise\PromiseInterface; /** * Represents a page in an Ogg container. @@ -65,11 +65,11 @@ private function __construct( * @param Buffer $buffer Buffer to read the Ogg page from. * @param ?int $timeout Time in milliseconds before a buffer read times out. * - * @return Promise Promise containing the Ogg page. + * @return PromiseInterface Promise containing the Ogg page. * * @throws \UnexpectedValueException If the buffer is out of sync and an invalid header is read. */ - public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): Promise + public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): PromiseInterface { $header = null; $pageSegments = []; diff --git a/src/Discord/Voice/OggStream.php b/src/Discord/Voice/OggStream.php index 9370fbf17..166925a89 100644 --- a/src/Discord/Voice/OggStream.php +++ b/src/Discord/Voice/OggStream.php @@ -13,7 +13,7 @@ use Discord\Exceptions\BufferTimedOutException; use Discord\Helpers\Buffer; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use React\Promise\Promise; use function React\Promise\resolve; @@ -65,9 +65,9 @@ private function __construct( * @param Buffer $buffer Buffer to read Ogg Opus packets from. * @param ?int $timeout Time in milliseconds before a buffer read times out. * - * @return Promise A promise containing the Ogg stream. + * @return PromiseInterface A promise containing the Ogg stream. */ - public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): Promise + public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): PromiseInterface { /** @var OpusHead */ $header = null; @@ -86,9 +86,9 @@ public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): Promise /** * Attempt to get a packet from the Ogg stream. * - * @return Promise Promise containing an Opus packet. If null, indicates EOF. + * @return PromiseInterface Promise containing an Opus packet. If null, indicates EOF. */ - public function getPacket(): Promise + public function getPacket(): PromiseInterface { if ($this->packets === null) { return resolve(null); @@ -113,9 +113,9 @@ public function getPacket(): Promise * Attempt to read an Ogg page from the buffer and parse it into Opus * packets. * - * @return Promise Promise containing an array of Opus packets. + * @return PromiseInterface Promise containing an array of Opus packets. */ - private function parsePackets(): Promise + private function parsePackets(): PromiseInterface { return new Promise(function ($resolve, $reject) { OggPage::fromBuffer($this->buffer, timeout: 0)->then(function ($page) use ($resolve) { diff --git a/src/Discord/Voice/VoiceClient.php b/src/Discord/Voice/VoiceClient.php index c7a5d2630..b3d9764b3 100644 --- a/src/Discord/Voice/VoiceClient.php +++ b/src/Discord/Voice/VoiceClient.php @@ -29,7 +29,7 @@ use Psr\Log\LoggerInterface; use React\ChildProcess\Process; use React\Promise\Deferred; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use React\Stream\ReadableResourceStream as Stream; use React\EventLoop\TimerInterface; use React\Stream\ReadableResourceStream; @@ -400,7 +400,7 @@ public function start() public function initSockets(): void { $wsfac = new WsFactory($this->loop); - /** @var Promise */ + /** @var PromiseInterface */ $promise = $wsfac("wss://{$this->endpoint}?v={$this->version}"); $promise->then([$this, 'handleWebSocketConnection'], [$this, 'handleWebSocketError']); @@ -438,7 +438,7 @@ public function handleWebSocketConnection(WebSocket $ws): void $buffer[1] = "\x01"; $buffer[3] = "\x46"; $buffer->writeUInt32BE($this->ssrc, 4); - /** @var Promise */ + /** @var PromiseInterface */ $promise = $udpfac->createClient("{$data->d->ip}:{$this->udpPort}"); $promise->then(function (Socket $client) use (&$ws, &$firstPack, &$ip, &$port, $buffer) { @@ -686,9 +686,9 @@ public function handleVoiceServerChange(array $data = []): void * @throws FileNotFoundException * @throws \RuntimeException * - * @return Promise + * @return PromiseInterface */ - public function playFile(string $file, int $channels = 2): Promise + public function playFile(string $file, int $channels = 2): PromiseInterface { $deferred = new Deferred(); @@ -726,9 +726,9 @@ public function playFile(string $file, int $channels = 2): Promise * @throws \RuntimeException * @throws \InvalidArgumentException Thrown when the stream passed to playRawStream is not a valid resource. * - * @return Promise + * @return PromiseInterface */ - public function playRawStream($stream, int $channels = 2, int $audioRate = 48000): Promise + public function playRawStream($stream, int $channels = 2, int $audioRate = 48000): PromiseInterface { $deferred = new Deferred(); @@ -773,9 +773,9 @@ public function playRawStream($stream, int $channels = 2, int $audioRate = 48000 * @throws \RuntimeException * @throws \InvalidArgumentException * - * @return Promise + * @return PromiseInterface */ - public function playOggStream($stream): Promise + public function playOggStream($stream): PromiseInterface { $deferred = new Deferred(); @@ -885,13 +885,13 @@ public function playOggStream($stream): Promise * * @param resource|Process|Stream $stream The DCA stream to be sent. * - * @return Promise + * @return PromiseInterface * @throws \Exception * * @deprecated 10.0.0 DCA is now deprecated in DiscordPHP, switch to using * `playOggStream` with raw Ogg Opus. */ - public function playDCAStream($stream): Promise + public function playDCAStream($stream): PromiseInterface { $deferred = new Deferred(); diff --git a/src/Discord/functions.php b/src/Discord/functions.php index c288e8617..c060d2c31 100644 --- a/src/Discord/functions.php +++ b/src/Discord/functions.php @@ -22,7 +22,7 @@ use React\EventLoop\LoopInterface; use React\Promise\Deferred; use React\Promise\Promise; -use React\Promise\Promise; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\Options; /** @@ -336,7 +336,7 @@ function deferFind($array, callable $callback, $loop = null): Promise * Attempts to return a resolved value from a synchronous promise. * Like await() but only for resolvable blocking promise without touching the loop. * - * @param Promise $promiseInterface The synchronous promise. + * @param PromiseInterface $promiseInterface The synchronous promise. * * @return mixed null if failed to return. * @@ -344,7 +344,7 @@ function deferFind($array, callable $callback, $loop = null): Promise * * @since 10.0.0 */ -function nowait(Promise $promiseInterface) +function nowait(PromiseInterface $promiseInterface) { $resolved = null; From 9d99ce5abba715a2fd38e614738eadf91d83afd5 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 09:27:24 -0500 Subject: [PATCH 09/19] Bump wyrihaximus/react-cache-redis to ^4.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a2b2584de..18bf3d568 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "friendsofphp/php-cs-fixer": "^3", "phpunit/phpunit": "^9.4.4", "davidcole1340/reactsh": "dev-master", - "wyrihaximus/react-cache-redis": "^3.0 || >=4.0 <4.4", + "wyrihaximus/react-cache-redis": "^4.5", "symfony/cache": "^5.4" }, "autoload": { From 909ef7d4d3d44a837116c023483e09a2cc0f133e Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 09:34:56 -0500 Subject: [PATCH 10/19] Fix imports for Discord.php --- src/Discord/Discord.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index 58c437705..3783b02a9 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -15,7 +15,6 @@ use Discord\Factory\Factory; use Discord\Helpers\BigInt; use Discord\Helpers\CacheConfig; -use Discord\Helpers\Deferred; use Discord\Helpers\RegisteredCommand; use Discord\Http\Drivers\React; use Discord\Http\Endpoint; @@ -51,13 +50,6 @@ use React\EventLoop\Loop; use React\EventLoop\LoopInterface; use React\EventLoop\TimerInterface; -use Discord\Helpers\RegisteredCommand; -use Discord\Http\Drivers\React; -use Discord\Http\Endpoint; -use Evenement\EventEmitterTrait; -use Monolog\Formatter\LineFormatter; -use Psr\Log\LoggerInterface; -use React\Cache\ArrayCache; use React\Promise\Deferred; use React\Promise\PromiseInterface; use React\Socket\Connector as SocketConnector; From f4dba22c56da0e88ad62e738cc89b68086abbea0 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 09:45:13 -0500 Subject: [PATCH 11/19] v2/v3 consistency for resolved promise See https://github.com/reactphp/promise/releases/tag/v3.0.0 which recommends using null instead --- src/Discord/Discord.php | 4 ++-- src/Discord/Voice/VoiceClient.php | 12 ++++++------ src/Discord/WebSockets/Events/GuildCreate.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index 3783b02a9..a8104b903 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -497,7 +497,7 @@ protected function handleReady(object $data) unset($unavailable[$guild->id]); } if (count($unavailable) < 1) { - $guildLoad->resolve(true); + $guildLoad->resolve(null); } }; $this->on(Event::GUILD_CREATE, $onGuildCreate); @@ -512,7 +512,7 @@ protected function handleReady(object $data) unset($unavailable[$guild->id]); } if (count($unavailable) < 1) { - $guildLoad->resolve(true); + $guildLoad->resolve(null); } }; $this->on(Event::GUILD_DELETE, $onGuildDelete); diff --git a/src/Discord/Voice/VoiceClient.php b/src/Discord/Voice/VoiceClient.php index 8b6a461de..b2059cb6c 100644 --- a/src/Discord/Voice/VoiceClient.php +++ b/src/Discord/Voice/VoiceClient.php @@ -302,7 +302,7 @@ class VoiceClient extends EventEmitter * @var bool Whether the voice client is reconnecting. */ protected $reconnecting = false; - + /** * Is the voice client being closed by user? * @@ -818,10 +818,10 @@ public function playOggStream($stream): PromiseInterface $ogg = null; $loops = 0; - + $readOpus = function () use ($deferred, &$ogg, &$readOpus, &$loops) { $this->readOpusTimer = null; - + $loops += 1; // If the client is paused, delay by frame size and check again. @@ -836,7 +836,7 @@ public function playOggStream($stream): PromiseInterface // EOF for Ogg stream. if (null === $packet) { $this->reset(); - $deferred->resolve(true); + $deferred->resolve(null); return; } @@ -861,7 +861,7 @@ public function playOggStream($stream): PromiseInterface $this->readOpusTimer = $this->loop->addTimer($delay, $readOpus); }, function ($e) use ($deferred) { $this->reset(); - $deferred->resolve(true); + $deferred->resolve(null); }); }; @@ -963,7 +963,7 @@ public function playDCAStream($stream): PromiseInterface $this->readOpusTimer = $this->loop->addTimer(($this->frameSize - 1) / 1000, $readOpus); }, function () use ($deferred) { $this->reset(); - $deferred->resolve(true); + $deferred->resolve(null); }); }; diff --git a/src/Discord/WebSockets/Events/GuildCreate.php b/src/Discord/WebSockets/Events/GuildCreate.php index 3cd1f7cfc..a26bd2fa6 100644 --- a/src/Discord/WebSockets/Events/GuildCreate.php +++ b/src/Discord/WebSockets/Events/GuildCreate.php @@ -121,7 +121,7 @@ public function handle($data) } $this->http->get($bind)->then(function ($bans) use (&$banPagination, $guildPart, $loadBans) { if (empty($bans)) { - $loadBans->resolve(true); + $loadBans->resolve(null); return; } From 21a80017933948dac7ddce4b7e17225e4fc54b8f Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 09:52:48 -0500 Subject: [PATCH 12/19] Fix typo Users->User --- src/Discord/Parts/Channel/Reaction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Discord/Parts/Channel/Reaction.php b/src/Discord/Parts/Channel/Reaction.php index a77a74124..e1a13ff5a 100644 --- a/src/Discord/Parts/Channel/Reaction.php +++ b/src/Discord/Parts/Channel/Reaction.php @@ -139,7 +139,7 @@ protected function getIdAttribute(): string * * @link https://discord.com/developers/docs/resources/channel#get-reactions * - * @return PromiseInterface + * @return PromiseInterface */ public function getUsers(array $options = []): PromiseInterface { @@ -182,7 +182,7 @@ public function getUsers(array $options = []): PromiseInterface * * @see Message::getUsers() * - * @return PromiseInterface + * @return PromiseInterface */ public function getAllUsers(): PromiseInterface { From ea4d81817f7240d521282993b4e0c5635d3cbb77 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 11:02:31 -0500 Subject: [PATCH 13/19] Fix typo in Thread --- src/Discord/Parts/Thread/Thread.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Discord/Parts/Thread/Thread.php b/src/Discord/Parts/Thread/Thread.php index c692eccaf..c302cf2be 100644 --- a/src/Discord/Parts/Thread/Thread.php +++ b/src/Discord/Parts/Thread/Thread.php @@ -546,11 +546,11 @@ public function deleteMessages($messages, ?string $reason = null): PromiseInterf * @param string|Message|null $options['after'] Get messages after this message ID. * @param int|null $options['limit'] Max number of messages to return (1-100). Defaults to 50. * - * @return PromiseInterface + * @return PromiseInterface> * * @todo Make it in a trait along with Channel */ - public function getMessageHistory(array $options = []): Promise + public function getMessageHistory(array $options = []): PromiseInterface { $resolver = new OptionsResolver(); $resolver From d695e1d11023ace169eced07ce0d13e4e2bdcb91 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 11:03:37 -0500 Subject: [PATCH 14/19] Fix incorrect return types --- src/Discord/Parts/Channel/Channel.php | 2 +- src/Discord/functions.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index 310b521da..975d59739 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -739,7 +739,7 @@ public function limitDelete(int $value, ?string $reason = null): PromiseInterfac * @return PromiseInterface> * @todo Make it in a trait along with Thread */ - public function getMessageHistory(array $options = []): Promise + public function getMessageHistory(array $options = []): PromiseInterface { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->read_message_history) { diff --git a/src/Discord/functions.php b/src/Discord/functions.php index 1e3736e48..13ede39b6 100644 --- a/src/Discord/functions.php +++ b/src/Discord/functions.php @@ -296,7 +296,7 @@ function escapeMarkdown(string $text): string * @since 10.0.0 Handle `$canceller` internally, use `cancel()` from the returned promise. * @since 7.1.0 */ -function deferFind($array, callable $callback, $loop = null): Promise +function deferFind($array, callable $callback, $loop = null): PromiseInterface { $cancelled = false; $deferred = new Deferred(function () use (&$cancelled) { From de953072629b3d3ac8fa451221ddf069d2f68fe4 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 11:06:16 -0500 Subject: [PATCH 15/19] Update Channel.php --- src/Discord/Parts/Channel/Channel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index 975d59739..e5a75f3eb 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -736,7 +736,7 @@ public function limitDelete(int $value, ?string $reason = null): PromiseInterfac * Or also missing `connect` permission for text in voice. * @throws \RangeException * - * @return PromiseInterface> + * @return PromiseInterface> * @todo Make it in a trait along with Thread */ public function getMessageHistory(array $options = []): PromiseInterface From 3cd3581e5d439d13428beded064b4a5029b01e8f Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 11:08:26 -0500 Subject: [PATCH 16/19] PromiseInterface return types --- src/Discord/Discord.php | 2 +- src/Discord/Parts/Channel/Message.php | 2 +- src/Discord/Parts/Channel/Poll.php | 6 +++--- src/Discord/Parts/Channel/Poll/PollAnswer.php | 6 +++--- src/Discord/Parts/Interactions/Interaction.php | 2 +- src/Discord/Parts/User/Member.php | 4 ++-- src/Discord/Repository/Channel/PollAnswerRepository.php | 2 +- src/Discord/Repository/EmojiRepository.php | 6 +++--- src/Discord/Repository/Guild/SoundRepository.php | 6 +++--- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index a8104b903..d0ed139f8 100644 --- a/src/Discord/Discord.php +++ b/src/Discord/Discord.php @@ -1230,7 +1230,7 @@ public function getVoiceClient(string $guild_id): ?VoiceClient * @since 10.0.0 Removed argument $check that has no effect (it is always checked) * @since 4.0.0 * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, ?LoggerInterface $logger = null, bool $check = true): PromiseInterface { diff --git a/src/Discord/Parts/Channel/Message.php b/src/Discord/Parts/Channel/Message.php index b5b45cc85..ebe1485c7 100644 --- a/src/Discord/Parts/Channel/Message.php +++ b/src/Discord/Parts/Channel/Message.php @@ -925,7 +925,7 @@ public function delayedReply($message, int $delay, &$timer = null): PromiseInter * @param int $delay Time to delay the delete by, in milliseconds. * @param TimerInterface &$timer Delay timer passed by reference. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ public function delayedDelete(int $delay, &$timer = null): PromiseInterface { diff --git a/src/Discord/Parts/Channel/Poll.php b/src/Discord/Parts/Channel/Poll.php index f5648caf0..6420e5242 100644 --- a/src/Discord/Parts/Channel/Poll.php +++ b/src/Discord/Parts/Channel/Poll.php @@ -19,7 +19,7 @@ use Discord\Parts\Channel\Poll\PollResults; use Discord\Parts\Part; use Discord\Repository\Channel\PollAnswerRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * A message poll. @@ -128,9 +128,9 @@ protected function getResultsAttribute(): ?PollResults * * @link https://discord.com/developers/docs/resources/poll#end-poll * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function expire(): ExtendedPromiseInterface + public function expire(): PromiseInterface { return $this->http->post(Endpoint::bind(Endpoint::MESSAGE_POLL_EXPIRE, $this->channel_id, $this->message_id)) ->then(function ($response) { diff --git a/src/Discord/Parts/Channel/Poll/PollAnswer.php b/src/Discord/Parts/Channel/Poll/PollAnswer.php index 5f0eb863d..2bfc021a5 100644 --- a/src/Discord/Parts/Channel/Poll/PollAnswer.php +++ b/src/Discord/Parts/Channel/Poll/PollAnswer.php @@ -19,7 +19,7 @@ use Discord\Parts\Part; use Discord\Parts\Thread\Thread; use Discord\Parts\User\User; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use function Discord\normalizePartId; @@ -140,9 +140,9 @@ protected function getGuildAttribute(): ?Guild * * @throws \OutOfRangeException * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function getVoters(array $options = []): ExtendedPromiseInterface + public function getVoters(array $options = []): PromiseInterface { $query = Endpoint::bind(Endpoint::MESSAGE_POLL_ANSWER, $this->channel_id, $this->message_id, $this->answer_id); diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index 01a83c72d..0def5a361 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -489,7 +489,7 @@ protected function respond(array $payload, ?Multipart $multipart = null): Promis * * @return PromiseInterface */ - public function updateFollowUpMessage(string $message_id, MessageBuilder $builder): ExtendedPromiseInterface + public function updateFollowUpMessage(string $message_id, MessageBuilder $builder): PromiseInterface { if (! $this->responded) { return reject(new \RuntimeException('Cannot create a follow-up message as the interaction has not been responded to.')); diff --git a/src/Discord/Parts/User/Member.php b/src/Discord/Parts/User/Member.php index a27b3d15b..cdf2088e7 100644 --- a/src/Discord/Parts/User/Member.php +++ b/src/Discord/Parts/User/Member.php @@ -158,9 +158,9 @@ public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): * @throws \RuntimeException Member has no `$guild`. * @throws NoPermissionsException Missing `kick_members` permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function kick(?string $reason = null): ExtendedPromiseInterface + public function kick(?string $reason = null): PromiseInterface { return $this->discord->guilds->cacheGet($this->guild_id)->then(function (?Guild $guild) use ($reason) { if (null === $guild) { diff --git a/src/Discord/Repository/Channel/PollAnswerRepository.php b/src/Discord/Repository/Channel/PollAnswerRepository.php index 782ac5535..55f50be7e 100644 --- a/src/Discord/Repository/Channel/PollAnswerRepository.php +++ b/src/Discord/Repository/Channel/PollAnswerRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Channel\Poll\PollAnswer; use Discord\Repository\AbstractRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; /** * Contains poll answers on a poll in a message. diff --git a/src/Discord/Repository/EmojiRepository.php b/src/Discord/Repository/EmojiRepository.php index 2771358d7..6e024748e 100644 --- a/src/Discord/Repository/EmojiRepository.php +++ b/src/Discord/Repository/EmojiRepository.php @@ -14,7 +14,7 @@ use Discord\Discord; use Discord\Http\Endpoint; use Discord\Parts\Guild\Emoji; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -63,9 +63,9 @@ public function __construct(Discord $discord, array $vars = []) /** * @param object $response * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - protected function cacheFreshen($response): ExtendedPromiseInterface + protected function cacheFreshen($response): PromiseInterface { foreach ($response as $value) foreach ($value as $value) { $value = array_merge($this->vars, (array) $value); diff --git a/src/Discord/Repository/Guild/SoundRepository.php b/src/Discord/Repository/Guild/SoundRepository.php index dc5236e7d..b7d2889e6 100644 --- a/src/Discord/Repository/Guild/SoundRepository.php +++ b/src/Discord/Repository/Guild/SoundRepository.php @@ -14,7 +14,7 @@ use Discord\Http\Endpoint; use Discord\Parts\Guild\Sound; use Discord\Repository\AbstractRepository; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use function React\Promise\resolve; @@ -60,9 +60,9 @@ class SoundRepository extends AbstractRepository /** * @param object $response * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - protected function cacheFreshen($response): ExtendedPromiseInterface + protected function cacheFreshen($response): PromiseInterface { foreach ($response as $value) foreach ($value as $value) { $value = array_merge($this->vars, (array) $value); From af46f1b7c8c9bd15aa99e3476cd8dac2ae1a9af5 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 11:09:47 -0500 Subject: [PATCH 17/19] Fix incorrect return type in doc block --- src/Discord/Parts/Channel/Channel.php | 2 +- src/Discord/Parts/Thread/Thread.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index e5a75f3eb..d9a548b85 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -1267,7 +1267,7 @@ public function broadcastTyping(): PromiseInterface * @param int $options['time'] Time in milliseconds until the collector finishes or false. * @param int $options['limit'] The amount of messages allowed or false. * - * @return PromiseInterface> + * @return PromiseInterface> */ public function createMessageCollector(callable $filter, array $options = []): PromiseInterface { diff --git a/src/Discord/Parts/Thread/Thread.php b/src/Discord/Parts/Thread/Thread.php index c302cf2be..044d5e605 100644 --- a/src/Discord/Parts/Thread/Thread.php +++ b/src/Discord/Parts/Thread/Thread.php @@ -770,7 +770,7 @@ public function broadcastTyping(): PromiseInterface * @param int $options ['time'] Time in milliseconds until the collector finishes or false. * @param int $options ['limit'] The amount of messages allowed or false. * - * @return PromiseInterface> + * @return PromiseInterface> * * @todo Make it in a trait along with Channel */ From aa1735e9b09fe3e66ba6d5e0079daf7727ff3d20 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 11:12:25 -0500 Subject: [PATCH 18/19] Fix incorrect return type in doc block --- src/Discord/Parts/Channel/Channel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index d9a548b85..92110c1de 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -295,7 +295,7 @@ protected function getLastPinTimestampAttribute(): ?Carbon * * @link https://discord.com/developers/docs/resources/channel#get-pinned-messages * - * @return PromiseInterface> + * @return PromiseInterface> */ public function getPinnedMessages(): PromiseInterface { From 6649ba5bf1940c7342c2ec068b6d17ff68d850a6 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 20 Nov 2024 11:14:55 -0500 Subject: [PATCH 19/19] Remove unused import --- src/Discord/Repository/Channel/PollAnswerRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Discord/Repository/Channel/PollAnswerRepository.php b/src/Discord/Repository/Channel/PollAnswerRepository.php index 55f50be7e..6bcb69163 100644 --- a/src/Discord/Repository/Channel/PollAnswerRepository.php +++ b/src/Discord/Repository/Channel/PollAnswerRepository.php @@ -14,7 +14,6 @@ use Discord\Http\Endpoint; use Discord\Parts\Channel\Poll\PollAnswer; use Discord\Repository\AbstractRepository; -use React\Promise\PromiseInterface; /** * Contains poll answers on a poll in a message.