Skip to content

Commit 2e85c43

Browse files
authored
Implement UpdatePresence Part (#1484)
1 parent 3d6427c commit 2e85c43

3 files changed

Lines changed: 87 additions & 25 deletions

File tree

src/Discord/Discord.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Discord\Parts\Gateway\GetGatewayBot;
2929
use Discord\Parts\Gateway\Identify;
3030
use Discord\Parts\Gateway\SessionStartLimit;
31+
use Discord\Parts\Gateway\UpdatePresence;
3132
use Discord\Parts\Guild\Guild;
3233
use Discord\Parts\OAuth\Application;
3334
use Discord\Parts\Part;
@@ -117,7 +118,7 @@ class Discord
117118
*
118119
* @var string Version.
119120
*/
120-
public const VERSION = 'v10.55.1';
121+
public const VERSION = 'v10.55.2';
121122

122123
public const REFERRER = 'https://github.com/discord-php/DiscordPHP';
123124

@@ -1588,14 +1589,17 @@ public function updatePresence(?Activity $activity = null, bool $idle = false, s
15881589
$status = 'online';
15891590
}
15901591

1592+
/** @var UpdatePresence $update_presence */
1593+
$update_presence = $this->factory->part(UpdatePresence::class, [
1594+
'since' => $idle,
1595+
'activities' => isset($activity) ? [$activity] : [],
1596+
'status' => $status,
1597+
'afk' => $afk,
1598+
]);
1599+
15911600
$payload = Payload::new(
15921601
Op::OP_UPDATE_PRESENCE,
1593-
[
1594-
'since' => $idle,
1595-
'activities' => [$activity],
1596-
'status' => $status,
1597-
'afk' => $afk,
1598-
],
1602+
$update_presence->jsonSerialize(),
15991603
);
16001604

16011605
$this->send($payload);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is a part of the DiscordPHP project.
7+
*
8+
* Copyright (c) 2015-2022 David Cole <[email protected]>
9+
* Copyright (c) 2020-present Valithor Obsidion <[email protected]>
10+
*
11+
* This file is subject to the MIT license that is bundled
12+
* with this source code in the LICENSE.md file.
13+
*/
14+
15+
namespace Discord\Parts\Gateway;
16+
17+
use Discord\Parts\Part;
18+
use Discord\Parts\User\Activity;
19+
20+
/**
21+
* Sent by the client to indicate a presence or status update.
22+
*
23+
* @link https://docs.discord.com/developers/events/gateway-events#update-presence
24+
*
25+
* @since 10.55.2
26+
*
27+
* @property int|null $since Unix time (in milliseconds) of when the client went idle, or null if the client is not idle.
28+
* @property Activity[] $activities User's activities.
29+
* @property string $status User's new status.
30+
* @property bool $afk Whether or not the client is afk.
31+
*/
32+
class UpdatePresence extends Part
33+
{
34+
/**
35+
* @inheritDoc
36+
*/
37+
protected $fillable = [
38+
'since',
39+
'activities',
40+
'status',
41+
'afk',
42+
];
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
public function jsonSerialize(): array
48+
{
49+
$data = [
50+
'since' => $this->since ?? null,
51+
'status' => $this->status,
52+
'afk' => $this->afk,
53+
'activities' => $this->activities ?? [],
54+
];
55+
56+
return $data;
57+
}
58+
}

src/Discord/Parts/User/Activity.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@
2828
* @since 5.0.0 Renamed from Game to Activity
2929
* @since 3.2.2
3030
*
31-
* @property string $name The activity's name.
32-
* @property int $type Activity type.
33-
* @property ?string|null $url Stream url, is validated when type is 1.
34-
* @property Carbon|null $created_at Timestamp of when the activity was added to the user's session.
35-
* @property Timestamps|null $timestamps Unix timestamps for start and/or end of the game.
36-
* @property string|null $application_id Application id for the game.
37-
* @property ?int|null $status_display_type Status display type; controls which field is displayed in the user's status text in the member list.
38-
* @property ?string|null $details What the player is currently doing.
39-
* @property ?string|null $details_url URL that is linked when clicking on the details text
40-
* @property ?string|null $state The user's current party status, or text used for a custom status.
41-
* @property ?string|null $state_url URL that is linked when clicking on the state text.
42-
* @property Emoji|null $emoji The emoji used for a custom status.
43-
* @property Party|null $party Information for the current party of the player.
44-
* @property Assets|null $assets Images for the presence and their hover texts.
45-
* @property Secrets|null $secrets Secrets for Rich Presence joining and spectating.
46-
* @property bool|null $instance Whether or not the activity is an instanced game session.
47-
* @property int|null $flags Activity flags `OR`d together, describes what the payload includes.
48-
* @property ExCollectionInterface<Button>|Button[]|null $buttons The custom buttons shown in the Rich Presence (max 2).
31+
* @property string $name The activity's name.
32+
* @property int $type Activity type.
33+
* @property ?string|null $url Stream url, is validated when type is 1.
34+
* @property Carbon|null $created_at Timestamp of when the activity was added to the user's session.
35+
* @property ?Timestamps|null $timestamps Unix timestamps for start and/or end of the game.
36+
* @property ?string|null $application_id Application id for the game.
37+
* @property ?int|null $status_display_type Status display type; controls which field is displayed in the user's status text in the member list.
38+
* @property ?string|null $details What the player is currently doing.
39+
* @property ?string|null $details_url URL that is linked when clicking on the details text
40+
* @property ?string|null $state The user's current party status, or text used for a custom status.
41+
* @property ?string|null $state_url URL that is linked when clicking on the state text.
42+
* @property ?Emoji|null $emoji The emoji used for a custom status.
43+
* @property ?Party|null $party Information for the current party of the player.
44+
* @property ?Assets|null $assets Images for the presence and their hover texts.
45+
* @property ?Secrets|null $secrets Secrets for Rich Presence joining and spectating.
46+
* @property ?bool|null $instance Whether or not the activity is an instanced game session.
47+
* @property ?int|null $flags Activity flags `OR`d together, describes what the payload includes.
48+
* @property ?ExCollectionInterface<Button>|Button[]|null $buttons The custom buttons shown in the Rich Presence (max 2).
4949
*/
5050
class Activity extends Part implements Stringable
5151
{

0 commit comments

Comments
 (0)