fix: update / fix PATCH /users/@me
This commit is contained in:
parent
5154d04d4a
commit
15dc484952
|
@ -32,7 +32,7 @@ impl ChorusUser {
|
|||
/// # Notes
|
||||
/// This function is a wrapper around [`User::get_settings`].
|
||||
pub async fn get_settings(&mut self) -> ChorusResult<UserSettings> {
|
||||
User::get_settings(self).await
|
||||
User::get_settings(self).await
|
||||
}
|
||||
|
||||
/// Modifies the current user's representation. (See [`User`])
|
||||
|
@ -40,12 +40,18 @@ impl ChorusUser {
|
|||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/user#modify-current-user>
|
||||
pub async fn modify(&mut self, modify_schema: UserModifySchema) -> ChorusResult<User> {
|
||||
if modify_schema.new_password.is_some()
|
||||
|
||||
// See <https://docs.discord.sex/resources/user#json-params>, note 1
|
||||
let requires_current_password = modify_schema.username.is_some()
|
||||
|| modify_schema.discriminator.is_some()
|
||||
|| modify_schema.email.is_some()
|
||||
|| modify_schema.code.is_some()
|
||||
{
|
||||
|| modify_schema.date_of_birth.is_some()
|
||||
|| modify_schema.new_password.is_some();
|
||||
|
||||
if requires_current_password && modify_schema.current_password.is_none() {
|
||||
return Err(ChorusError::PasswordRequired);
|
||||
}
|
||||
|
||||
let request = Client::new()
|
||||
.patch(format!(
|
||||
"{}/users/@me",
|
||||
|
@ -132,4 +138,3 @@ impl User {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,24 +4,91 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::Snowflake;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
/// A schema used to modify a user.
|
||||
///
|
||||
/// See <https://docs.discord.sex/resources/user#json-params>
|
||||
pub struct UserModifySchema {
|
||||
/// The user's new username (2-32 characters)
|
||||
///
|
||||
/// Requires that `current_password` is set.
|
||||
pub username: Option<String>,
|
||||
// TODO: Maybe add a special discriminator type?
|
||||
/// Requires that `current_password` is set.
|
||||
pub discriminator: Option<String>,
|
||||
/// The user's display name (1-32 characters)
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This is not yet implemented on Spacebar
|
||||
pub global_name: Option<String>,
|
||||
// TODO: Add a CDN data type
|
||||
pub avatar: Option<String>,
|
||||
pub bio: Option<String>,
|
||||
pub accent_color: Option<u64>,
|
||||
pub banner: Option<String>,
|
||||
pub current_password: Option<String>,
|
||||
pub new_password: Option<String>,
|
||||
pub code: Option<String>,
|
||||
/// Note: This is not yet implemented on Spacebar
|
||||
pub avatar_decoration_id: Option<Snowflake>,
|
||||
/// Note: This is not yet implemented on Spacebar
|
||||
pub avatar_decoration_sku_id: Option<Snowflake>,
|
||||
/// The user's email address; if changing from a verified email, email_token must be provided
|
||||
///
|
||||
/// Requires that `current_password` is set.
|
||||
// TODO: Is ^ up to date? One would think this may not be the case, since email_token exists
|
||||
pub email: Option<String>,
|
||||
pub discriminator: Option<i16>,
|
||||
/// The user's email token from their previous email, required if a new email is set.
|
||||
///
|
||||
/// See <https://docs.discord.sex/resources/user#modify-user-email> and <https://docs.discord.sex/resources/user#verify-user-email-change>
|
||||
/// for changing the user's email.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This is not yet implemented on Spacebar
|
||||
pub email_token: Option<String>,
|
||||
/// The user's pronouns (max 40 characters)
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This is not yet implemented on Spacebar
|
||||
pub pronouns: Option<String>,
|
||||
/// The user's banner.
|
||||
///
|
||||
/// Can only be changed for premium users
|
||||
pub banner: Option<String>,
|
||||
/// The user's bio (max 190 characters)
|
||||
pub bio: Option<String>,
|
||||
/// The user's accent color, as a hex integer
|
||||
pub accent_color: Option<u64>,
|
||||
/// The user's [UserFlags].
|
||||
///
|
||||
/// Only [UserFlags::PREMIUM_PROMO_DISMISSED], [UserFlags::HAS_UNREAD_URGENT_MESSAGES]
|
||||
/// and DISABLE_PREMIUM can be set.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This is not yet implemented on Spacebar
|
||||
pub flags: Option<u64>,
|
||||
/// The user's date of birth, can only be set once
|
||||
///
|
||||
/// Requires that `current_password` is set.
|
||||
pub date_of_birth: Option<NaiveDate>,
|
||||
/// The user's current password (if the account does not have a password, this sets it)
|
||||
///
|
||||
/// Required for updating `username`, `discriminator`, `email`, `date_of_birth` and
|
||||
/// `new_password`
|
||||
#[serde(rename = "password")]
|
||||
pub current_password: Option<String>,
|
||||
/// The user's new password (8-72 characters)
|
||||
///
|
||||
/// Requires that `current_password` is set.
|
||||
///
|
||||
/// Regenerates the user's token
|
||||
pub new_password: Option<String>,
|
||||
/// Spacebar only field, potentially same as `email_token`
|
||||
pub code: Option<String>,
|
||||
}
|
||||
|
||||
/// A schema used to create a private channel.
|
||||
|
@ -33,7 +100,7 @@ pub struct UserModifySchema {
|
|||
///
|
||||
/// # Reference:
|
||||
/// Read: <https://discord-userdoccers.vercel.app/resources/channel#json-params>
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
pub struct PrivateChannelCreateSchema {
|
||||
pub recipients: Option<Vec<Snowflake>>,
|
||||
pub access_tokens: Option<Vec<String>>,
|
||||
|
|
Loading…
Reference in New Issue