Skip to content

Commit

Permalink
add GatewayIdentifyPresenceUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Oct 24, 2024
1 parent 7460d3f commit f65b9c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/types/events/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use crate::types::events::{PresenceUpdate, WebSocketEvent};
use crate::types::events::WebSocketEvent;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;

use super::GatewayIdentifyPresenceUpdate;

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, WebSocketEvent)]
pub struct GatewayIdentifyPayload {
pub token: String,
Expand All @@ -18,7 +20,7 @@ pub struct GatewayIdentifyPayload {
#[serde(skip_serializing_if = "Option::is_none")]
pub shard: Option<Vec<(i32, i32)>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub presence: Option<PresenceUpdate>,
pub presence: Option<GatewayIdentifyPresenceUpdate>,
// What is the difference between these two?
// Intents is documented, capabilities is used in users
// I wonder if these are interchangeable...
Expand Down
34 changes: 26 additions & 8 deletions src/types/events/presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use serde::{Deserialize, Serialize};
/// Sent by the client to update its status and presence;
/// See <https://discord.com/developers/docs/topics/gateway-events#update-presence>
pub struct UpdatePresence {
/// Unix time of when the client went idle, or none if client is not idle.
/// Unix time of when the client went idle, or n
/// one if client is not idle.
pub since: Option<u128>,
/// the client's status (online, invisible, offline, dnd, idle..)
pub status: UserStatus,
Expand All @@ -19,20 +20,37 @@ pub struct UpdatePresence {
}

#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, WebSocketEvent)]
/// Received to tell the client that a user updated their presence / status
/// Received to tell the client that a user updated their presence / status. If you are looking for
/// the PresenceUpdate used in the IDENTIFY gateway event, see
///
/// See <https://discord.com/developers/docs/topics/gateway-events#presence-update-presence-update-event-fields>
/// (Same structure as <https://docs.discord.sex/resources/presence#presence-object>)
pub struct PresenceUpdate {
// BUG: `user` should always be present, but the spacebar client does not send it. Temporary fix:
// make `user` optional.
pub user: Option<PublicUser>,
pub user: PublicUser,
#[serde(default)]
pub guild_id: Option<Snowflake>,
pub status: UserStatus,
#[serde(default)]
pub activities: Vec<Activity>,
// BUG: `client_status` should always be present, but the spacebar client does not send it. Temporary fix:
// make `client_status` optional.
pub client_status: Option<ClientStatusObject>,
pub client_status: ClientStatusObject,
}

#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, WebSocketEvent)]
/// Sent to the gateway as part of [GatewayIdentifyPayload](crate::types::GatewayIdentifyPayload)
pub struct GatewayIdentifyPresenceUpdate {
#[serde(default)]
pub guild_id: Option<Snowflake>,
pub status: UserStatus,
#[serde(default)]
pub activities: Vec<Activity>,
}

impl From<PresenceUpdate> for GatewayIdentifyPresenceUpdate {
fn from(value: PresenceUpdate) -> Self {
Self {
guild_id: value.guild_id,
status: value.status,
activities: value.activities,
}
}
}

0 comments on commit f65b9c1

Please sign in to comment.