essence/http/
user.rs

1use crate::{
2    models::{Bot, Permissions},
3    Maybe,
4};
5use serde::{Deserialize, Serialize};
6#[cfg(feature = "utoipa")]
7use utoipa::ToSchema;
8
9/// Payload sent to create a new user.
10#[derive(Clone, Debug, Deserialize)]
11#[cfg_attr(feature = "client", derive(Serialize))]
12#[cfg_attr(feature = "utoipa", derive(ToSchema))]
13pub struct CreateUserPayload {
14    /// The unique username of the user. Must between 2 and 32 characters and only contain
15    /// alphanumeric characters, periods (.), hyphens (-), and underscores (_).
16    pub username: String,
17    /// The global display name of the user. Must be between 2 and 32 characters.
18    pub display_name: Option<String>,
19    /// The email of the user. Must be a valid email address.
20    #[cfg_attr(feature = "utoipa", schema(format = "email"))]
21    pub email: String,
22    /// The password of the user. Must be between 8 and 32 characters.
23    #[cfg_attr(feature = "utoipa", schema(format = "password"))]
24    pub password: String,
25    /// Turnstile CAPTCHA response from Cloudflare.
26    pub captcha_token: String,
27}
28
29/// Data returned when creating a new user.
30#[derive(Clone, Debug, Serialize)]
31#[cfg_attr(feature = "client", derive(Deserialize))]
32#[cfg_attr(feature = "utoipa", derive(ToSchema))]
33pub struct CreateUserResponse {
34    /// The ID of the user.
35    pub id: u64,
36    /// The token to use for authentication.
37    pub token: String,
38}
39
40/// Payload sent when deleting a user.
41#[derive(Clone, Debug, Deserialize)]
42#[cfg_attr(feature = "client", derive(Serialize))]
43#[cfg_attr(feature = "utoipa", derive(ToSchema))]
44pub struct DeleteUserPayload {
45    /// The password of the user.
46    #[cfg_attr(feature = "utoipa", schema(format = "password"))]
47    pub password: String,
48}
49
50/// Payload sent when changing a user's password.
51#[derive(Clone, Debug, Deserialize)]
52#[cfg_attr(feature = "client", derive(Serialize))]
53#[cfg_attr(feature = "utoipa", derive(ToSchema))]
54pub struct ChangePasswordPayload {
55    /// The current password of the user.
56    pub current_password: String,
57    /// The new password of the user.
58    pub new_password: String,
59}
60
61/// Payload sent when changing a user's email.
62#[derive(Clone, Debug, Deserialize)]
63#[cfg_attr(feature = "client", derive(Serialize))]
64#[cfg_attr(feature = "utoipa", derive(ToSchema))]
65pub struct ChangeEmailPayload {
66    /// The current password of the user.
67    pub password: String,
68    /// The new email of the user.
69    pub new_email: String,
70}
71
72/// Payload sent when editing a user.
73#[derive(Clone, Debug, Deserialize)]
74#[cfg_attr(feature = "client", derive(Serialize))]
75#[cfg_attr(feature = "utoipa", derive(ToSchema))]
76pub struct EditUserPayload {
77    /// The new username of the user. Leave empty to keep the current username.
78    pub username: Option<String>,
79    /// The new display name of the user. Leave empty to keep the current display name, and set to
80    /// `null` to remove the display name.
81    #[serde(default)]
82    #[cfg_attr(feature = "client", serde(skip_serializing_if = "Maybe::is_absent"))]
83    #[cfg_attr(feature = "utoipa", schema(nullable, value_type = Option<String>))]
84    pub display_name: Maybe<String>,
85    /// The new avatar of the user. Leave empty to keep the current avatar, and set to `null` to
86    /// remove the avatar. If provided, the avatar should be represented as a
87    /// [Data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme).
88    #[serde(default)]
89    #[cfg_attr(feature = "client", serde(skip_serializing_if = "Maybe::is_absent"))]
90    #[cfg_attr(feature = "utoipa", schema(nullable, value_type = Option<String>, format = Byte))]
91    pub avatar: Maybe<String>,
92    /// The new banner URL of the user. Leave empty to keep the current banner, and set to `null` to
93    /// remove the banner.
94    #[serde(default)]
95    #[cfg_attr(feature = "client", serde(skip_serializing_if = "Maybe::is_absent"))]
96    #[cfg_attr(feature = "utoipa", schema(nullable, value_type = Option<String>))]
97    pub banner: Maybe<String>,
98    /// The new bio of the user. Leave empty to keep the current bio, and set to `null` to remove
99    /// the bio.
100    #[serde(default)]
101    #[cfg_attr(feature = "client", serde(skip_serializing_if = "Maybe::is_absent"))]
102    #[cfg_attr(feature = "utoipa", schema(nullable, value_type = Option<String>))]
103    pub bio: Maybe<String>,
104}
105
106/// Payload sent when requesting to add a user as a friend.
107#[derive(Clone, Debug, Deserialize)]
108#[cfg_attr(feature = "client", derive(Serialize))]
109#[cfg_attr(feature = "utoipa", derive(ToSchema))]
110pub struct SendFriendRequestPayload {
111    /// The username of the user to add as a friend.
112    pub username: String,
113}
114
115/// Payload sent when creating a new bot account.
116#[derive(Clone, Debug, Deserialize)]
117#[cfg_attr(feature = "client", derive(Serialize))]
118#[cfg_attr(feature = "utoipa", derive(ToSchema))]
119pub struct CreateBotPayload {
120    /// The unique username of the bot. Must between 2 and 32 characters and only contain
121    /// alphanumeric characters, periods (.), hyphens (-), and underscores (_).
122    ///
123    /// Note that unlike usernames, bot usernames are only unique to you. The full username of the
124    /// bot will be ``owner_username/given_username``, for example ``user123/MyBot``.
125    pub username: String,
126    /// The global display name of the bot. Must be between 2 and 32 characters.
127    pub display_name: Option<String>,
128    /// Whether the bot is public. Public bots can be added by anyone, while private bots can only
129    /// be added by the owner.
130    #[serde(default)]
131    pub public: bool,
132}
133
134/// Data sent when creating a new bot account.
135#[derive(Clone, Debug, Serialize)]
136#[cfg_attr(feature = "client", derive(Deserialize))]
137#[cfg_attr(feature = "utoipa", derive(ToSchema))]
138pub struct CreateBotResponse {
139    /// The bot that was created.
140    #[serde(flatten)]
141    pub bot: Bot,
142    /// The token to use for authentication.
143    pub token: String,
144}
145
146/// Payload sent to edit details of a bot account.
147#[derive(Clone, Debug, Deserialize)]
148#[cfg_attr(feature = "client", derive(Serialize))]
149#[cfg_attr(feature = "utoipa", derive(ToSchema))]
150pub struct EditBotPayload {
151    /// The inner user payload to edit account details about the bot.
152    #[serde(flatten)]
153    pub user_payload: EditUserPayload,
154    /// Whether the bot should be public. Leave empty to keep the current setting.
155    pub public: Option<bool>,
156    /// The new default permissions the bot should request for when being added to guilds.
157    /// Leave empty to keep the current permissions.
158    pub default_permissions: Option<Permissions>,
159    /// Whether the bot should support being added to guilds.
160    pub guild_enabled: Option<bool>,
161    /// Whether the bot should support being added to group DMs.
162    pub group_dm_enabled: Option<bool>,
163    /// Whether the bot should support global access.
164    pub global_enabled: Option<bool>,
165}
166
167/// Payload sent when deleting a bot.
168#[derive(Clone, Debug, Deserialize)]
169#[cfg_attr(feature = "client", derive(Serialize))]
170#[cfg_attr(feature = "utoipa", derive(ToSchema))]
171pub struct DeleteBotPayload {
172    /// The password of the bot owner.
173    #[cfg_attr(feature = "utoipa", schema(format = "password"))]
174    pub password: String,
175}
176
177/// Payload sent when regenerating a bot's token.
178#[derive(Clone, Debug, Deserialize)]
179#[cfg_attr(feature = "client", derive(Serialize))]
180#[cfg_attr(feature = "utoipa", derive(ToSchema))]
181pub struct RegenerateBotTokenPayload {
182    /// The password of the bot owner.
183    #[cfg_attr(feature = "utoipa", schema(format = "password"))]
184    pub password: String,
185}