diff --git a/src/Discord/Builders/CommandBuilder.php b/src/Discord/Builders/CommandBuilder.php index df463b29f..147f8946b 100644 --- a/src/Discord/Builders/CommandBuilder.php +++ b/src/Discord/Builders/CommandBuilder.php @@ -86,9 +86,12 @@ public function toArray(): array { $arrCommand = [ 'name' => $this->name, - 'description' => $this->description, ]; + if ($this->type === Command::CHAT_INPUT) { + $arrCommand['description'] = $this->description; + } + $optionals = [ 'type', 'name_localizations', diff --git a/src/Discord/DiscordCommandClient.php b/src/Discord/DiscordCommandClient.php index d67943b92..880d4cdef 100644 --- a/src/Discord/DiscordCommandClient.php +++ b/src/Discord/DiscordCommandClient.php @@ -447,9 +447,9 @@ protected function resolveCommandClientOptions(array $options): array if (is_string($reason) || $reason instanceof \Stringable) { $this->getLogger()->error($reason); } else { - $this->getLogger()->warning('Unhandled internal rejected promise, $reason is not a Throwable, ' . gettype($reason) . ' given.'); + $this->getLogger()->warning('Unhandled internal rejected promise, $reason is not a Throwable, '.gettype($reason).' given.'); } - } + }, ]); $options = $resolver->resolve($options); diff --git a/src/Discord/Helpers/LegacyCacheWrapper.php b/src/Discord/Helpers/LegacyCacheWrapper.php index 69b1b91ed..c6ac89b2b 100644 --- a/src/Discord/Helpers/LegacyCacheWrapper.php +++ b/src/Discord/Helpers/LegacyCacheWrapper.php @@ -18,7 +18,7 @@ use function React\Promise\resolve; /** - * Legacy v7.x in memory cache behavior + * Legacy v7.x in memory cache behavior. * * @since 10.0.0 * @internal @@ -89,7 +89,7 @@ public function set($key, $value, $ttl = null) */ public function delete($key) { - if (!array_key_exists($key, $this->items)) { + if (! array_key_exists($key, $this->items)) { return resolve(false); } @@ -197,7 +197,7 @@ public function unserializer($value) } $part = $this->discord->getFactory()->part($this->class, $value->attributes, $value->created); foreach ($value as $name => $var) { - if (!in_array($name, ['created', 'attributes'])) { + if (! in_array($name, ['created', 'attributes'])) { $part->{$name} = $var; } } diff --git a/src/Discord/Helpers/Multipart.php b/src/Discord/Helpers/Multipart.php index 9bd860d4d..9e6094b3d 100644 --- a/src/Discord/Helpers/Multipart.php +++ b/src/Discord/Helpers/Multipart.php @@ -10,6 +10,7 @@ */ namespace Discord\Helpers; + use Stringable; /** @@ -43,7 +44,7 @@ class Multipart implements Stringable /** * Multipart constructor. * - * @param array $fields + * @param array $fields * @param string $boundary Defaults to DiscordPHPSendFileBoundary */ public function __construct(array $fields = [], string $boundary = self::BOUNDARY) diff --git a/src/Discord/Parts/Embed/Embed.php b/src/Discord/Parts/Embed/Embed.php index 811635a39..aa0f6b0e4 100644 --- a/src/Discord/Parts/Embed/Embed.php +++ b/src/Discord/Parts/Embed/Embed.php @@ -501,11 +501,9 @@ public function setURL(string $url): self * Ensures a URL is valid for use in embeds. * * @param ?string $url - * @param array $allowed Allowed URL scheme + * @param array $allowed Allowed URL scheme * * @throws \DomainException - * - * @return void */ protected function ensureValidUrl(?string $url = null, array $allowed = ['http', 'https', 'attachment']): void { diff --git a/src/Discord/Parts/Interactions/Interaction.php b/src/Discord/Parts/Interactions/Interaction.php index e6cb818cb..dd24b92f2 100644 --- a/src/Discord/Parts/Interactions/Interaction.php +++ b/src/Discord/Parts/Interactions/Interaction.php @@ -87,20 +87,20 @@ class Interaction extends Part */ protected $responded = false; - const TYPE_PING = 1; - const TYPE_APPLICATION_COMMAND = 2; - const TYPE_MESSAGE_COMPONENT = 3; - const TYPE_APPLICATION_COMMAND_AUTOCOMPLETE = 4; - const TYPE_MODAL_SUBMIT = 5; - - const RESPONSE_TYPE_PONG = 1; - const RESPONSE_TYPE_CHANNEL_MESSAGE_WITH_SOURCE = 4; - const RESPONSE_TYPE_DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5; - const RESPONSE_TYPE_DEFERRED_UPDATE_MESSAGE = 6; - const RESPONSE_TYPE_UPDATE_MESSAGE = 7; - const RESPONSE_TYPE_APPLICATION_COMMAND_AUTOCOMPLETE_RESULT = 8; - const RESPONSE_TYPE_MODAL = 9; - const RESPONSE_TYPE_PREMIUM_REQUIRED = 10; + public const TYPE_PING = 1; + public const TYPE_APPLICATION_COMMAND = 2; + public const TYPE_MESSAGE_COMPONENT = 3; + public const TYPE_APPLICATION_COMMAND_AUTOCOMPLETE = 4; + public const TYPE_MODAL_SUBMIT = 5; + + public const RESPONSE_TYPE_PONG = 1; + public const RESPONSE_TYPE_CHANNEL_MESSAGE_WITH_SOURCE = 4; + public const RESPONSE_TYPE_DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5; + public const RESPONSE_TYPE_DEFERRED_UPDATE_MESSAGE = 6; + public const RESPONSE_TYPE_UPDATE_MESSAGE = 7; + public const RESPONSE_TYPE_APPLICATION_COMMAND_AUTOCOMPLETE_RESULT = 8; + public const RESPONSE_TYPE_MODAL = 9; + public const RESPONSE_TYPE_PREMIUM_REQUIRED = 10; /** * Returns true if this interaction has been internally responded. diff --git a/src/Discord/Parts/Thread/Thread.php b/src/Discord/Parts/Thread/Thread.php index a81c7fcb3..ed63eea0b 100644 --- a/src/Discord/Parts/Thread/Thread.php +++ b/src/Discord/Parts/Thread/Thread.php @@ -387,6 +387,50 @@ public function rename(string $name, ?string $reason = null): ExtendedPromiseInt }); } + /** + * Lock the thread. + * + * @param string|null $reason + * + * @return ExtendedPromiseInterface + */ + public function lock(?string $reason = null): ExtendedPromiseInterface + { + $headers = []; + if (isset($reason)) { + $headers['X-Audit-Log-Reason'] = $reason; + } + + return $this->http->patch(Endpoint::bind(Endpoint::THREAD, $this->id), ['locked' => true], $headers) + ->then(function ($response) { + $this->locked = $response->thread_metadata->locked; + + return $this; + }); + } + + /** + * Unlock the thread. + * + * @param string|null $reason + * + * @return ExtendedPromiseInterface + */ + public function unlock(?string $reason = null): ExtendedPromiseInterface + { + $headers = []; + if (isset($reason)) { + $headers['X-Audit-Log-Reason'] = $reason; + } + + return $this->http->patch(Endpoint::bind(Endpoint::THREAD, $this->id), ['locked' => false], $headers) + ->then(function ($response) { + $this->locked = $response->thread_metadata->locked; + + return $this; + }); + } + /** * Archive the thread. * diff --git a/src/Discord/Parts/User/Activity.php b/src/Discord/Parts/User/Activity.php index ad9022379..60799f071 100644 --- a/src/Discord/Parts/User/Activity.php +++ b/src/Discord/Parts/User/Activity.php @@ -137,12 +137,12 @@ protected function getEmojiAttribute(): ?Emoji public function __toString(): string { return match ($this->type) { - self::TYPE_GAME => 'Playing ' . $this->name, - self::TYPE_STREAMING => 'Streaming ' . $this->details, - self::TYPE_LISTENING => 'Listening to ' . $this->name, - self::TYPE_WATCHING => 'Watching ' . $this->name, + self::TYPE_GAME => 'Playing '.$this->name, + self::TYPE_STREAMING => 'Streaming '.$this->details, + self::TYPE_LISTENING => 'Listening to '.$this->name, + self::TYPE_WATCHING => 'Watching '.$this->name, self::TYPE_CUSTOM => "{$this->emoji} {$this->state}", - self::TYPE_COMPETING => 'Competing in ' . $this->name, + self::TYPE_COMPETING => 'Competing in '.$this->name, default => $this->name, }; } diff --git a/src/Discord/Repository/AbstractRepository.php b/src/Discord/Repository/AbstractRepository.php index 39aa8cfc9..12ea3941f 100755 --- a/src/Discord/Repository/AbstractRepository.php +++ b/src/Discord/Repository/AbstractRepository.php @@ -215,9 +215,11 @@ public function save(Part $part, ?string $reason = null): ExtendedPromiseInterfa case 'patch': // Update old part $part->created = true; $part->fill((array) $response); + return $this->cache->set($part->{$this->discrim}, $part)->then(fn ($success) => $part); default: // Create new part $newPart = $this->factory->create($this->class, (array) $response, true); + return $this->cache->set($newPart->{$this->discrim}, $this->factory->create($this->class, (array) $response, true))->then(fn ($success) => $newPart); } });