diff --git a/.gitignore b/.gitignore index d00d5e166..e198e89d5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ test*.php .idea .phplint-cache dump.html +.vscode # phive /tools diff --git a/.vscode/DiscordUnitTests.code-snippets b/.vscode/DiscordUnitTests.code-snippets deleted file mode 100644 index 740c22560..000000000 --- a/.vscode/DiscordUnitTests.code-snippets +++ /dev/null @@ -1,14 +0,0 @@ -{ - "Unit Test": { - "scope": "php", - "prefix": "unit", - "body": [ - "public function $1()", - "{", - " return wait(function (Discord \\$discord, \\$resolve) {", - " $0", - " });", - "}" - ] - } -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index fd9726ae2..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Listen for XDebug", - "type": "php", - "request": "launch", - "port": 9000 - }, - { - "name": "Launch with XDebug", - "type": "php", - "request": "launch", - "program": "${workspaceFolder}/test.php", - "args": [ - "-d xdebug.mode=debug", - "-d xdebug.start_with_request=yes", - "-d xdebug.client_port=9000" - ], - "cwd": "${workspaceFolder}", - "port": 9000 - }, - { - "name": "Launch phpunit", - "type": "php", - "request": "launch", - "program": "${workspaceRoot}/vendor/bin/phpunit", - "args": [ - "-d xdebug.mode=debug", - "-d xdebug.start_with_request=yes", - "-d xdebug.client_port=9000" - ], - "cwd": "${workspaceRoot}", - "port": 9000 - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index d1cda0cda..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "php-cs-fixer.config": ".php_cs", - "php-cs-fixer.executablePath": "${workspaceFolder}/vendor/friendsofphp/php-cs-fixer/php-cs-fixer", - "files.exclude": { - "**/.git": true, - "**/.svn": true, - "**/.hg": true, - "**/CVS": true, - "**/.DS_Store": true, - "**/.phpdoc": true - }, - "php-docblocker.returnVoid": false -} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e5fc0cba5..bef01bfd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## Version 7.0.0 + +This release contains breaking changes regarding messages. + +- Read the [conversion guide](V7_CONVERSION.md) for a guide on how to upgrade from v6.x to v7. + - If you are coming from v5.x, also read the [v6.x conversion guide](V6_CONVERSION.md). + +- Upgraded to Discord API v9. +- Added `MessagBuilder`. + - See the conversion guide for more information - most functions that send messages now take message builders instead of seperate parameters. +- Added support for [Discord Threads](https://discord.com/developers/docs/topics/threads). + - `$message->channel` will now return a `Channel` or `Thread` object. +- Added [guild feature flags](https://github.com/discord-php/DiscordPHP/blob/28d741c47e81f9957a3b0d92c2f187d81d26c9c8/src/Discord/Parts/Guild/Guild.php#L75-L95). +- Removed `premium_since` attribute from the `PresenceUpdate` object. + - This would have been null since v6 anyway. + ## Version 6.0.2 - Added `link` attribute to `Message` - [#526] diff --git a/src/Discord/Parts/WebSockets/PresenceUpdate.php b/src/Discord/Parts/WebSockets/PresenceUpdate.php index 516cc8549..a1882d9ac 100644 --- a/src/Discord/Parts/WebSockets/PresenceUpdate.php +++ b/src/Discord/Parts/WebSockets/PresenceUpdate.php @@ -11,7 +11,6 @@ namespace Discord\Parts\WebSockets; -use Carbon\Carbon; use Discord\Helpers\Collection; use Discord\Parts\Guild\Guild; use Discord\Parts\Guild\Role; @@ -24,13 +23,18 @@ * A PresenceUpdate part is used when the `PRESENCE_UPDATE` event is fired on the WebSocket. It contains * information about the users presence such as their status (online/away) and their current game. * - * @property Member $member The member that the presence update affects. - * @property User $user The user that the presence update affects. - * @property Guild $guild The guild that the presence update affects. - * @property string $guild_id The unique identifier of the guild that the presence update affects. - * @property string $status The updated status of the user. - * @property Collection|Activity[] $activities Activitires of the user. - * @property Activity $game The updated game of the user. + * @property Member $member The member that the presence update affects. + * @property User $user The user that the presence update affects. + * @property Guild $guild The guild that the presence update affects. + * @property string $guild_id The unique identifier of the guild that the presence update affects. + * @property string $status The updated status of the user. + * @property Activity $game The updated game of the user. + * @property Collection|Activity[] $activities The activities of the user. + * @property Collection|Role[] $roles Roles that the user has in the guild. + * @property object $client_status Status of the client. + * @property string|null $desktop_status Status of the user on their desktop client. Null if they are not active on desktop. + * @property string|null $mobile_status Status of the user on their mobile client. Null if they are not active on mobile. + * @property string|null $web_status Status of the user on their web client. Null if they are not active on web. */ class PresenceUpdate extends Part { @@ -39,10 +43,15 @@ class PresenceUpdate extends Part */ protected $fillable = ['user', 'guild_id', 'status', 'activities', 'client_status']; + /** + * @inheritDoc + */ + protected $visible = ['member', 'roles', 'guild', 'game', 'desktop_status', 'mobile_status', 'web_status']; + /** * Gets the member attribute. * - * @return Member + * @return Member|null */ protected function getMemberAttribute(): ?Member { @@ -56,10 +65,9 @@ protected function getMemberAttribute(): ?Member /** * Gets the user attribute. * - * @return User The user that had their presence updated. - * @throws \Exception + * @return User The user that had their presence updated. */ - protected function getUserAttribute(): ?User + protected function getUserAttribute(): User { if ($user = $this->discord->users->get('id', $this->attributes['user']->id)) { return $user; @@ -75,17 +83,7 @@ protected function getUserAttribute(): ?User */ protected function getRolesAttribute(): Collection { - $roles = new Collection(); - - if (! $this->guild) { - $roles->fill($this->attributes['roles']); - } else { - foreach ($this->attributes['roles'] as $role) { - $roles->push($this->guild->roles->get('id', $role)); - } - } - - return $roles; + return $this->member->roles ?? new Collection(); } /** @@ -93,7 +91,7 @@ protected function getRolesAttribute(): Collection * * @return Guild The guild that the user was in. */ - protected function getGuildAttribute(): ?Guild + protected function getGuildAttribute(): Guild { return $this->discord->guilds->get('id', $this->guild_id); } @@ -101,7 +99,7 @@ protected function getGuildAttribute(): ?Guild /** * Gets the game attribute. * - * @return ?Activity The game attribute. + * @return Activity|null The game attribute. */ protected function getGameAttribute(): ?Part { @@ -125,16 +123,32 @@ protected function getActivitiesAttribute() } /** - * Gets the premium since timestamp. + * Gets the status of the user on their desktop client. * - * @return Carbon|null + * @return string|null */ - protected function getPremiumSinceAttribute(): ?Carbon + protected function getDesktopStatusAttribute(): ?string { - if (! isset($this->attributes['premium_since'])) { - return null; - } + return $this->client_status->desktop ?? null; + } - return Carbon::parse($this->attributes['premium_since']); + /** + * Gets the status of the user on their mobile client. + * + * @return string|null + */ + protected function getMobileStatusAttribute(): ?string + { + return $this->client_status->mobile ?? null; + } + + /** + * Gets the status of the user on their web client. + * + * @return string|null + */ + protected function getWebStatusAttribute(): ?string + { + return $this->client_status->web ?? null; } } diff --git a/src/Discord/Parts/WebSockets/VoiceServerUpdate.php b/src/Discord/Parts/WebSockets/VoiceServerUpdate.php index c17146ca4..bb0f813e3 100644 --- a/src/Discord/Parts/WebSockets/VoiceServerUpdate.php +++ b/src/Discord/Parts/WebSockets/VoiceServerUpdate.php @@ -17,10 +17,10 @@ /** * Tells the client that the voice channel's server has changed. * - * @property string $token The new client voice token. - * @property \Discord\Parts\Guild\Guild $guild The guild affected by the change. - * @property string $guild_id The unique identifier of the guild that was affected by the change. - * @property string $endpoint The new voice server endpoint. + * @property string $token The new client voice token. + * @property Guild $guild The guild affected by the change. + * @property string $guild_id The unique identifier of the guild that was affected by the change. + * @property string $endpoint The new voice server endpoint. */ class VoiceServerUpdate extends Part {