Skip to content

Commit

Permalink
Updated presence update part fields
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcole1340 committed Aug 30, 2021
1 parent cdecade commit ff404ef
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test*.php
.idea
.phplint-cache
dump.html
.vscode

# phive
/tools
Expand Down
14 changes: 0 additions & 14 deletions .vscode/DiscordUnitTests.code-snippets

This file was deleted.

40 changes: 0 additions & 40 deletions .vscode/launch.json

This file was deleted.

13 changes: 0 additions & 13 deletions .vscode/settings.json

This file was deleted.

16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
78 changes: 46 additions & 32 deletions src/Discord/Parts/WebSockets/PresenceUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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;
Expand All @@ -75,33 +83,23 @@ 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();
}

/**
* Gets the guild attribute.
*
* @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);
}

/**
* Gets the game attribute.
*
* @return ?Activity The game attribute.
* @return Activity|null The game attribute.
*/
protected function getGameAttribute(): ?Part
{
Expand All @@ -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;
}
}
8 changes: 4 additions & 4 deletions src/Discord/Parts/WebSockets/VoiceServerUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ff404ef

Please sign in to comment.