From a9bb7fc55bd128110a678a7cc214fe0835a2e6c9 Mon Sep 17 00:00:00 2001 From: Alexander Maassen Date: Wed, 20 Nov 2024 17:19:49 +0100 Subject: [PATCH] Promise v3 (#1157) * 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(null) - updated $deferred->reject() to $deferred->reject(throwable) - bumped wyrihaximus/react-cache-redis to ^4.5 - fixed some imports, doc blocks, and return types --------- Co-authored-by: Valithor Obsidion See https://github.com/reactphp/promise/releases/tag/v3.0.0 for BC recommendations. --- composer.json | 3 +- src/Discord/Discord.php | 45 +++++----- src/Discord/Helpers/Buffer.php | 15 ++-- src/Discord/Helpers/Deferred.php | 28 ------ .../Helpers/ExtendedPromisorInterface.php | 30 ------- src/Discord/Parts/Channel/Channel.php | 83 +++++++++-------- src/Discord/Parts/Channel/Message.php | 54 +++++------ src/Discord/Parts/Channel/Poll.php | 6 +- src/Discord/Parts/Channel/Poll/PollAnswer.php | 6 +- 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 | 64 ++++++------- 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 | 44 ++++----- src/Discord/Parts/User/User.php | 16 ++-- .../Parts/WebSockets/MessageReaction.php | 8 +- src/Discord/Repository/AbstractRepository.php | 34 +++---- .../Channel/PollAnswerRepository.php | 1 - .../Repository/Channel/ReactionRepository.php | 6 +- .../Repository/Channel/ThreadRepository.php | 12 +-- src/Discord/Repository/EmojiRepository.php | 6 +- .../Repository/Guild/BanRepository.php | 10 +-- .../Guild/GuildTemplateRepository.php | 6 +- .../Repository/Guild/MemberRepository.php | 10 +-- .../Guild/ScheduledEventRepository.php | 6 +- .../Repository/Guild/SoundRepository.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 | 43 +++++---- src/Discord/WebSockets/Events/GuildCreate.php | 6 +- src/Discord/functions.php | 4 +- 39 files changed, 367 insertions(+), 433 deletions(-) delete mode 100644 src/Discord/Helpers/Deferred.php delete mode 100644 src/Discord/Helpers/ExtendedPromisorInterface.php diff --git a/composer.json b/composer.json index 2102074e3..18bf3d568 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", @@ -38,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": { diff --git a/src/Discord/Discord.php b/src/Discord/Discord.php index 5a5828b8d..d0ed139f8 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,7 +50,8 @@ use React\EventLoop\Loop; use React\EventLoop\LoopInterface; use React\EventLoop\TimerInterface; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\Deferred; +use React\Promise\PromiseInterface; use React\Socket\Connector as SocketConnector; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -468,10 +468,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; } @@ -497,7 +497,7 @@ protected function handleReady(object $data) unset($unavailable[$guild->id]); } if (count($unavailable) < 1) { - $guildLoad->resolve(); + $guildLoad->resolve(null); } }; $this->on(Event::GUILD_CREATE, $onGuildCreate); @@ -512,18 +512,18 @@ protected function handleReady(object $data) unset($unavailable[$guild->id]); } if (count($unavailable) < 1) { - $guildLoad->resolve(); + $guildLoad->resolve(null); } }; $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(); + }); } /** @@ -775,7 +775,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 { @@ -809,14 +809,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'], [$deferred, 'reject']); }; } else { - /** @var ExtendedPromiseInterface */ + /** @var PromiseInterface */ $promise = coroutine([$handler, 'handle'], $data->d); - $promise->done([$deferred, 'resolve'], [$deferred, 'reject']); + $promise->then([$deferred, 'resolve'], [$deferred, 'reject']); } } @@ -1079,7 +1079,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); @@ -1093,12 +1093,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'], [$this, 'handleWsConnectionFailed']); }); } @@ -1233,9 +1230,9 @@ 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): ExtendedPromiseInterface + public function joinVoiceChannel(Channel $channel, $mute = false, $deaf = true, ?LoggerInterface $logger = null, bool $check = true): PromiseInterface { $deferred = new Deferred(); @@ -1329,9 +1326,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 = [ @@ -1359,7 +1356,7 @@ 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 interested in assisting us with sharding support development.'); } 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 03ffe14d5..92110c1de 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 Stringable; use Symfony\Component\OptionsResolver\OptionsResolver; use Traversable; @@ -98,7 +98,7 @@ * @property InviteRepository $invites Invites in the channel. * @property StageInstanceRepository $stage_instances Stage instances in the channel. * - * @method ExtendedPromiseInterface sendMessage(MessageBuilder|string $builder) + * @method PromiseInterface sendMessage(MessageBuilder|string $builder) */ class Channel extends Part implements Stringable { @@ -295,9 +295,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) { @@ -323,9 +323,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; @@ -364,9 +364,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) { @@ -410,13 +410,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.')); @@ -474,9 +474,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.')); @@ -509,9 +509,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.')); @@ -544,9 +544,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.')); @@ -587,9 +587,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.')); @@ -653,9 +653,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.')); @@ -708,9 +708,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) { @@ -736,11 +736,10 @@ public function limitDelete(int $value, ?string $reason = null): ExtendedPromise * Or also missing `connect` permission for text in voice. * @throws \RangeException * - * @return ExtendedPromiseInterface - * + * @return PromiseInterface> * @todo Make it in a trait along with Thread */ - public function getMessageHistory(array $options = []): ExtendedPromiseInterface + public function getMessageHistory(array $options = []): PromiseInterface { if (! $this->is_private && $botperms = $this->getBotPermissions()) { if (! $botperms->read_message_history) { @@ -803,9 +802,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) { @@ -844,9 +843,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) { @@ -979,11 +978,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)) { @@ -1137,9 +1136,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)) { @@ -1207,9 +1206,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)); @@ -1227,9 +1226,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) @@ -1249,9 +1248,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.')); @@ -1268,9 +1267,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 a4ba657de..ebe1485c7 100644 --- a/src/Discord/Parts/Channel/Message.php +++ b/src/Discord/Parts/Channel/Message.php @@ -23,7 +23,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; @@ -33,7 +32,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; @@ -760,11 +760,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)) { @@ -841,9 +841,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; @@ -866,9 +866,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.')); @@ -904,14 +904,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'], [$deferred, 'reject']); }); return $deferred->promise(); @@ -925,14 +925,14 @@ public function delayedReply($message, int $delay, &$timer = null): ExtendedProm * @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): 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'], [$deferred, 'reject']); }); return $deferred->promise(); @@ -947,9 +947,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(); @@ -978,9 +978,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(); @@ -1022,9 +1022,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); @@ -1033,7 +1033,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(); @@ -1049,12 +1049,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)); @@ -1077,9 +1077,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); @@ -1128,9 +1128,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/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/Channel/Reaction.php b/src/Discord/Parts/Channel/Reaction.php index 8bd472c23..e1a13ff5a 100644 --- a/src/Discord/Parts/Channel/Reaction.php +++ b/src/Discord/Parts/Channel/Reaction.php @@ -18,7 +18,7 @@ use Discord\Parts\Part; use Discord\Parts\Thread\Thread; use Discord\Parts\User\User; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use stdClass; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -73,7 +73,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) { @@ -139,9 +139,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}")); @@ -182,9 +182,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 0829b120d..5ec937eb6 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 Message returned if wait parameter is set true. + * @return PromiseInterface Message returned if wait parameter is set true. */ - public function execute($data, array $queryparams = []): ExtendedPromiseInterface + public function execute($data, array $queryparams = []): PromiseInterface { $endpoint = Endpoint::bind(Endpoint::WEBHOOK_EXECUTE, $this->id, $this->token); @@ -127,9 +127,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 323542598..215bd8a76 100644 --- a/src/Discord/Parts/Guild/Guild.php +++ b/src/Discord/Parts/Guild/Guild.php @@ -40,7 +40,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; @@ -423,9 +423,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) { @@ -453,9 +453,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) { @@ -744,9 +744,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); @@ -771,9 +771,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(); @@ -799,9 +799,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 @@ -875,9 +875,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 @@ -975,9 +975,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); } @@ -990,9 +990,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; @@ -1017,11 +1017,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) { @@ -1050,9 +1050,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([ @@ -1112,9 +1112,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) { @@ -1155,9 +1155,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([ @@ -1202,9 +1202,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([ @@ -1256,9 +1256,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([ @@ -1307,9 +1307,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(); @@ -1355,9 +1355,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([ @@ -1399,9 +1399,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) { @@ -1429,9 +1429,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([ @@ -1466,9 +1466,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 (new Widget($this->discord, ['id' => $this->id]))->fetch(); } @@ -1481,9 +1481,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()) { @@ -1512,9 +1512,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)) { @@ -1543,9 +1543,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 06c9d403c..311edb97b 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 Stringable; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -131,9 +131,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 17e01e1ff..49b571776 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; @@ -97,9 +97,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 d82266daf..d14a25f7f 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 e6cb818cb..0def5a361 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -28,7 +28,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; @@ -244,9 +244,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 == self::TYPE_APPLICATION_COMMAND) { return $this->acknowledgeWithResponse(); @@ -271,9 +271,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, [self::TYPE_APPLICATION_COMMAND, self::TYPE_MESSAGE_COMPONENT, self::TYPE_MODAL_SUBMIT])) { return reject(new \LogicException('You can only acknowledge application command, message component, or modal submit interactions.')); @@ -295,9 +295,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, [self::TYPE_MESSAGE_COMPONENT, self::TYPE_MODAL_SUBMIT])) { return reject(new \LogicException('You can only update messages that occur due to a message component interaction.')); @@ -316,9 +316,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.')); @@ -341,15 +341,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(); @@ -367,9 +367,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.')); @@ -388,9 +388,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 != self::TYPE_MESSAGE_COMPONENT) { return reject(new \RuntimeException('Cannot create a follow-up message as the interaction has not been responded to.')); @@ -400,7 +400,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(); @@ -421,9 +421,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, [self::TYPE_APPLICATION_COMMAND, self::TYPE_MESSAGE_COMPONENT, self::TYPE_MODAL_SUBMIT])) { return reject(new \LogicException('You can only acknowledge application command, message component, or modal submit interactions.')); @@ -452,9 +452,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.')); @@ -487,15 +487,15 @@ 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): 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.')); } - return (function () use ($message_id, $builder): ExtendedPromiseInterface { + return (function () use ($message_id, $builder): PromiseInterface { if ($builder->requiresMultipart()) { $multipart = $builder->toMultipart(); @@ -515,9 +515,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.')); @@ -540,9 +540,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.')); @@ -560,9 +560,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 != self::TYPE_APPLICATION_COMMAND_AUTOCOMPLETE) { return reject(new \LogicException('You can only respond command option results with auto complete interactions.')); @@ -587,9 +587,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, [self::TYPE_PING, self::TYPE_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 99e3be2fa..46c9a498f 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 824997ace..f6f9faaf5 100644 --- a/src/Discord/Parts/Thread/Member.php +++ b/src/Discord/Parts/Thread/Member.php @@ -17,7 +17,7 @@ use Discord\Parts\Part; use Discord\Parts\User\Member as GuildMember; 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 @@ -111,9 +111,9 @@ private function getGuildAttribute(): ?Guild * * @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 8afe71b99..044d5e605 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 Stringable; 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 implements Stringable { @@ -310,9 +310,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)); } @@ -324,9 +324,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; @@ -340,9 +340,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)); } @@ -354,9 +354,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; @@ -373,9 +373,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)) { @@ -395,9 +395,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)) { @@ -417,9 +417,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)) { @@ -440,9 +440,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)) { @@ -462,11 +462,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) { @@ -488,11 +488,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.')); @@ -546,11 +546,11 @@ public function deleteMessages($messages, ?string $reason = null): ExtendedPromi * @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 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 @@ -611,11 +611,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.')); @@ -647,11 +647,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.')); @@ -688,11 +688,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)) { @@ -736,11 +736,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)); @@ -755,9 +755,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)); } @@ -770,11 +770,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 5b4532914..bd56b9545 100644 --- a/src/Discord/Parts/User/Client.php +++ b/src/Discord/Parts/User/Client.php @@ -20,7 +20,7 @@ use Discord\Repository\PrivateChannelRepository; use Discord\Repository\SoundRepository; 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. @@ -89,7 +89,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; }); @@ -148,9 +148,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 803e5f7d3..cdf2088e7 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 Stringable; use function React\Promise\reject; @@ -64,7 +64,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 implements Stringable { @@ -131,9 +131,9 @@ public function updateFromPresence(PresenceUpdate $presence): PresenceUpdate * @throws \RuntimeException Member has no `$guild`. * @throws NoPermissionsException Missing `ban_members` permission. * - * @return ExtendedPromiseInterface + * @return PromiseInterface */ - public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): ExtendedPromiseInterface + public function ban(?int $daysToDeleteMessages = null, ?string $reason = null): PromiseInterface { return $this->discord->guilds->cacheGet($this->guild_id)->then(function (?Guild $guild) use ($daysToDeleteMessages, $reason) { if (null === $guild) { @@ -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) { @@ -185,9 +185,9 @@ public function kick(?string $reason = null): ExtendedPromiseInterface * * @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 ?? '', @@ -225,9 +225,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; @@ -253,9 +253,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; @@ -297,9 +297,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; @@ -336,9 +336,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) { @@ -383,9 +383,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); @@ -518,9 +518,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()) { @@ -551,9 +551,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 fe1339eb3..ede24fc90 100644 --- a/src/Discord/Parts/User/User.php +++ b/src/Discord/Parts/User/User.php @@ -17,7 +17,7 @@ use Discord\Parts\Channel\Channel; use Discord\Parts\Part; use Discord\Parts\Channel\Message; -use React\Promise\ExtendedPromiseInterface; +use React\Promise\PromiseInterface; use Stringable; use function React\Promise\resolve; @@ -51,7 +51,7 @@ * @property int|null $avatar_decoration The user's avatar decoration URL. * @property int|null $avatar_decoration_hash The user's avatar decoration hash. * - * @method ExtendedPromiseInterface sendMessage(MessageBuilder $builder) + * @method PromiseInterface sendMessage(MessageBuilder $builder) */ class User extends Part implements Stringable { @@ -105,9 +105,9 @@ class User extends Part implements Stringable * * @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); @@ -135,9 +135,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() @@ -151,9 +151,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(fn (Channel $channel) => $channel->broadcastTyping()); } diff --git a/src/Discord/Parts/WebSockets/MessageReaction.php b/src/Discord/Parts/WebSockets/MessageReaction.php index 37108df3c..8028e8f5f 100644 --- a/src/Discord/Parts/WebSockets/MessageReaction.php +++ b/src/Discord/Parts/WebSockets/MessageReaction.php @@ -20,7 +20,7 @@ use Discord\Parts\Thread\Thread; 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; @@ -72,7 +72,7 @@ public function isPartial(): bool /** * {@inheritDoc} */ - public function fetch(): ExtendedPromiseInterface + public function fetch(): PromiseInterface { $promise = resolve(); @@ -228,14 +228,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 427c2d3e6..bf526514c 100755 --- a/src/Discord/Repository/AbstractRepository.php +++ b/src/Discord/Repository/AbstractRepository.php @@ -19,7 +19,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; @@ -105,11 +105,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.')); @@ -139,9 +139,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); @@ -179,11 +179,11 @@ public function create(array|object $attributes = [], bool $created = false): Pa * @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'])) { @@ -230,11 +230,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-existent part.')); @@ -276,11 +276,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-existent part.')); @@ -312,9 +312,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])) { @@ -403,9 +403,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)); } @@ -456,9 +456,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/PollAnswerRepository.php b/src/Discord/Repository/Channel/PollAnswerRepository.php index 782ac5535..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\ExtendedPromiseInterface; /** * Contains poll answers on a poll in a message. diff --git a/src/Discord/Repository/Channel/ReactionRepository.php b/src/Discord/Repository/Channel/ReactionRepository.php index fc8c98d51..d6f231739 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. @@ -52,11 +52,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 d511f9a1b..e4dabada2 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(fn ($response) => $this->handleThreadPaginationResponse($response)); @@ -109,9 +109,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/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/BanRepository.php b/src/Discord/Repository/Guild/BanRepository.php index 5f1b87abf..cef2afdbc 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 { $headers = []; @@ -119,9 +119,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 7fd029c04..4a0952264 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. @@ -60,9 +60,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 0bd93687a..2bc7966d3 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 1a44ac18e..cfd4c1f8d 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/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); diff --git a/src/Discord/Repository/GuildRepository.php b/src/Discord/Repository/GuildRepository.php index 35f7cc0f9..da217eee5 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 ed1e1505b..b2059cb6c 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; @@ -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? * @@ -398,13 +398,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'], [$this, 'handleWebSocketError']); } /** @@ -439,10 +436,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; @@ -685,9 +682,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(); @@ -725,9 +722,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(); @@ -772,9 +769,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(); @@ -821,10 +818,10 @@ public function playOggStream($stream): ExtendedPromiseInterface $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. @@ -839,7 +836,7 @@ public function playOggStream($stream): ExtendedPromiseInterface // EOF for Ogg stream. if (null === $packet) { $this->reset(); - $deferred->resolve(); + $deferred->resolve(null); return; } @@ -864,7 +861,7 @@ public function playOggStream($stream): ExtendedPromiseInterface $this->readOpusTimer = $this->loop->addTimer($delay, $readOpus); }, function ($e) use ($deferred) { $this->reset(); - $deferred->resolve(); + $deferred->resolve(null); }); }; @@ -884,13 +881,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(); @@ -966,7 +963,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(null); }); }; diff --git a/src/Discord/WebSockets/Events/GuildCreate.php b/src/Discord/WebSockets/Events/GuildCreate.php index 021ab2db8..a26bd2fa6 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(null); return; } diff --git a/src/Discord/functions.php b/src/Discord/functions.php index 9c8ecc3bb..13ede39b6 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; @@ -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) {