Skip to main content

discordrs/model/
user.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use super::Snowflake;
6
7#[derive(Clone, Debug, Serialize, Deserialize, Default)]
8/// Data for a user's avatar decoration.
9pub struct AvatarDecorationData {
10    /// Decoration asset hash.
11    pub asset: String,
12    /// SKU that owns the decoration.
13    pub sku_id: Snowflake,
14}
15
16#[derive(Clone, Debug, Serialize, Deserialize, Default)]
17/// Data for a user's profile nameplate collectible.
18pub struct UserNameplate {
19    /// SKU that owns the nameplate.
20    pub sku_id: Snowflake,
21    /// Nameplate asset path.
22    pub asset: String,
23    /// Nameplate label.
24    pub label: String,
25    /// Nameplate palette name.
26    pub palette: String,
27}
28
29#[derive(Clone, Debug, Serialize, Deserialize, Default)]
30/// User collectibles exposed by Discord's user object.
31pub struct UserCollectibles {
32    /// Optional profile nameplate collectible.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub nameplate: Option<UserNameplate>,
35}
36
37#[derive(Clone, Debug, Serialize, Deserialize, Default)]
38/// Primary guild identity displayed on a user's profile.
39pub struct UserPrimaryGuild {
40    /// Guild ID for the displayed server identity.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub identity_guild_id: Option<Snowflake>,
43    /// Whether the identity is enabled.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub identity_enabled: Option<bool>,
46    /// Server tag text.
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub tag: Option<String>,
49    /// Server tag badge hash.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub badge: Option<String>,
52}
53
54#[derive(Clone, Debug, Serialize, Deserialize, Default)]
55/// Typed Discord API object for `User`.
56pub struct User {
57    pub id: Snowflake,
58    pub username: String,
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub global_name: Option<String>,
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub discriminator: Option<String>,
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub avatar: Option<String>,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub bot: Option<bool>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub system: Option<bool>,
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub mfa_enabled: Option<bool>,
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub banner: Option<String>,
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub accent_color: Option<u64>,
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub locale: Option<String>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub verified: Option<bool>,
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub email: Option<String>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub flags: Option<u64>,
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub premium_type: Option<u8>,
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub public_flags: Option<u64>,
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub avatar_decoration_data: Option<AvatarDecorationData>,
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub collectibles: Option<UserCollectibles>,
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub primary_guild: Option<UserPrimaryGuild>,
93}
94
95#[derive(Clone, Debug, Serialize, Deserialize, Default)]
96/// Request body for modifying the current bot user.
97pub struct ModifyCurrentUser {
98    /// New username.
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub username: Option<String>,
101    /// New avatar image data, or `None` when omitted.
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub avatar: Option<String>,
104    /// New banner image data, or `None` when omitted.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub banner: Option<String>,
107}
108
109#[derive(Clone, Debug, Serialize, Deserialize, Default)]
110/// OAuth2 connection attached to the current user.
111pub struct UserConnection {
112    /// Provider account ID.
113    pub id: String,
114    /// Provider account display name.
115    pub name: String,
116    /// Discord connection service type.
117    #[serde(rename = "type")]
118    pub kind: String,
119    /// Whether the connection has been revoked.
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub revoked: Option<bool>,
122    /// Partial integration objects associated with the connection.
123    #[serde(default)]
124    pub integrations: Vec<serde_json::Value>,
125    /// Whether the connection is verified.
126    #[serde(default)]
127    pub verified: bool,
128    /// Whether friend sync is enabled.
129    #[serde(default)]
130    pub friend_sync: bool,
131    /// Whether activities from this connection appear in presence.
132    #[serde(default)]
133    pub show_activity: bool,
134    /// Whether the connection has a matching third-party OAuth2 token.
135    #[serde(default)]
136    pub two_way_link: bool,
137    /// Discord visibility setting for the connection.
138    #[serde(default)]
139    pub visibility: u8,
140}
141
142#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq, Eq)]
143/// Application role connection attached to the current user.
144pub struct UserApplicationRoleConnection {
145    /// Vanity platform name shown in linked-role UI.
146    #[serde(skip_serializing_if = "Option::is_none")]
147    pub platform_name: Option<String>,
148    /// Platform username shown in linked-role UI.
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub platform_username: Option<String>,
151    /// Metadata values keyed by application role connection metadata key.
152    #[serde(default)]
153    pub metadata: HashMap<String, String>,
154}
155
156#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq, Eq)]
157/// Request body for updating the current user's application role connection.
158pub struct UpdateUserApplicationRoleConnection {
159    /// Vanity platform name shown in linked-role UI.
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub platform_name: Option<String>,
162    /// Platform username shown in linked-role UI.
163    #[serde(skip_serializing_if = "Option::is_none")]
164    pub platform_username: Option<String>,
165    /// Metadata values keyed by application role connection metadata key.
166    #[serde(skip_serializing_if = "Option::is_none")]
167    pub metadata: Option<HashMap<String, String>>,
168}
169
170impl UpdateUserApplicationRoleConnection {
171    /// Creates an empty update body.
172    pub fn new() -> Self {
173        Self::default()
174    }
175
176    /// Sets the platform name.
177    pub fn platform_name(mut self, platform_name: impl Into<String>) -> Self {
178        self.platform_name = Some(platform_name.into());
179        self
180    }
181
182    /// Sets the platform username.
183    pub fn platform_username(mut self, platform_username: impl Into<String>) -> Self {
184        self.platform_username = Some(platform_username.into());
185        self
186    }
187
188    /// Sets the metadata map.
189    pub fn metadata<I, K, V>(mut self, metadata: I) -> Self
190    where
191        I: IntoIterator<Item = (K, V)>,
192        K: Into<String>,
193        V: Into<String>,
194    {
195        self.metadata = Some(
196            metadata
197                .into_iter()
198                .map(|(key, value)| (key.into(), value.into()))
199                .collect(),
200        );
201        self
202    }
203}