From a2333996a2bcd82709be395a17664830d3ea6485 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sat, 28 Nov 2020 22:36:33 -0800 Subject: [PATCH] Gateway: Presence to contain user and guild fields This commit changes the gateway.Presence struct to be similar to commits prior to the last refactor, that is, the struct would have the User and GuildID fields. This is done so it's easier to store them. --- gateway/events.go | 18 +++++++++--------- gateway/ready.go | 8 ++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/gateway/events.go b/gateway/events.go index 3b245a1..0b5a57f 100644 --- a/gateway/events.go +++ b/gateway/events.go @@ -58,7 +58,7 @@ type ( VoiceStates []discord.VoiceState `json:"voice_states,omitempty"` Members []discord.Member `json:"members,omitempty"` Channels []discord.Channel `json:"channels,omitempty"` - Presences []Presence `json:"presences,omitempty"` + Presences []Presence `json:"presences,omitempty"` } GuildUpdateEvent struct { discord.Guild @@ -115,7 +115,7 @@ type ( // Only filled if requested Presences []Presence `json:"presences,omitempty"` - Nonce string `json:"nonce,omitempty"` + Nonce string `json:"nonce,omitempty"` } // GuildMemberListUpdate is an undocumented event. It's received when the @@ -158,7 +158,7 @@ type ( Group *GuildMemberListGroup `json:"group,omitempty"` Member *struct { discord.Member - HoistedRole string `json:"hoisted_role"` + HoistedRole string `json:"hoisted_role"` Presence Presence `json:"presence"` } `json:"member,omitempty"` } @@ -279,6 +279,11 @@ type ( // easily embedded. It does not contain any ID to identify who it belongs // to. For more information, refer to the PresenceUpdateEvent struct. Presence struct { + // User is the user presence is being updated for. Only the ID field is + // guaranteed to be valid per Discord documentation. + User discord.User `json:"user"` + // GuildID is the id of the guild + GuildID discord.GuildID `json:"guild_id"` // Status is either "idle", "dnd", "online", or "offline". Status Status `json:"status"` // Activities are the user's current activities. @@ -303,15 +308,10 @@ type ( } // PresenceUpdateEvent represents the structure of the Presence Update Event - // object. This event may be sent on itself or within other events. + // object. // // https://discord.com/developers/docs/topics/gateway#presence-update-presence-update-event-fields PresenceUpdateEvent struct { - // User is the user presence is being updated for. - User discord.User `json:"user"` - // GuildID is the id of the guild - GuildID discord.GuildID `json:"guild_id"` - // Presence contains the rest of the update struct. Presence } diff --git a/gateway/ready.go b/gateway/ready.go index 095686f..daf91e6 100644 --- a/gateway/ready.go +++ b/gateway/ready.go @@ -232,8 +232,12 @@ type ( SupplementalPresence struct { UserID discord.UserID `json:"user_id"` - // Presence contains the rest of this struct. - Presence + // Status is either "idle", "dnd", "online", or "offline". + Status Status `json:"status"` + // Activities are the user's current activities. + Activities []discord.Activity `json:"activities"` + // ClientStaus is the user's platform-dependent status. + ClientStatus ClientStatus `json:"client_status"` // LastModified is only present in Friends. LastModified discord.UnixMsTimestamp `json:"last_modified,omitempty"`