diff --git a/src/api/users/users.rs b/src/api/users/users.rs index ec53ba3..1a7c655 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -15,7 +15,7 @@ use crate::{ instance::{ChorusUser, Instance}, ratelimiter::ChorusRequest, types::{ - AuthorizeConnectionSchema, ConnectionType, CreateUserHarvestSchema, + AuthorizeConnectionSchema, BurstCreditsInfo, ConnectionType, CreateUserHarvestSchema, DeleteDisableUserSchema, GetPomeloEligibilityReturn, GetPomeloSuggestionsReturn, GetRecentMentionsSchema, GetUserProfileSchema, GuildAffinities, Harvest, HarvestBackendType, LimitType, ModifyUserNoteSchema, PremiumUsage, PublicUser, Snowflake, @@ -618,10 +618,10 @@ impl ChorusUser { /// Fetches the current user's usage of various premium perks ([PremiumUsage] object). /// /// The local user must have premium (nitro), otherwise the request will fail - /// with a 404 NotFound error and the message {"message": "Premium usage not available", "code": 10084}. - /// - /// # Notes - /// As of 2024/08/16, Spacebar does not yet implement this endpoint. + /// with a 404 NotFound error and the message {"message": "Premium usage not available", "code": 10084}. + /// + /// # Notes + /// As of 2024/08/16, Spacebar does not yet implement this endpoint. /// /// # Reference /// See @@ -640,6 +640,29 @@ impl ChorusUser { chorus_request.deserialize_response(self).await } + + /// Fetches info about the current user's burst credits + /// (how many are remaining, when they will replenish). + /// + /// Burst credits are used to create burst reactions. + /// + /// # Notes + /// As of 2024/08/18, Spacebar does not yet implement this endpoint. + pub async fn get_burst_credits(&mut self) -> ChorusResult { + let request = Client::new() + .get(format!( + "{}/users/@me/burst-credits", + self.belongs_to.read().unwrap().urls.api, + )) + .header("Authorization", self.token()); + + let chorus_request = ChorusRequest { + request, + limit_type: LimitType::default(), + }; + + chorus_request.deserialize_response(self).await + } } impl User { diff --git a/src/types/schema/user.rs b/src/types/schema/user.rs index 3df0e0f..c8f9d9a 100644 --- a/src/types/schema/user.rs +++ b/src/types/schema/user.rs @@ -4,11 +4,12 @@ use std::collections::HashMap; -use chrono::NaiveDate; +use chrono::{DateTime, NaiveDate, Utc}; use serde::{Deserialize, Serialize}; use crate::types::{ - Connection, GuildAffinity, HarvestBackendType, Snowflake, ThemeColors, TwoWayLinkType, UserAffinity + Connection, GuildAffinity, HarvestBackendType, Snowflake, ThemeColors, TwoWayLinkType, + UserAffinity, }; #[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)] @@ -377,7 +378,7 @@ pub(crate) struct GetConnectionAccessTokenReturn { pub access_token: String, } -#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] +#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, PartialOrd)] /// Return type for the [crate::instance::ChorusUser::get_user_affinities] endpoint. /// /// See @@ -388,7 +389,7 @@ pub struct UserAffinities { pub inverse_user_affinities: Vec, } -#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] +#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, PartialOrd)] /// Return type for the [crate::instance::ChorusUser::get_guild_affinities] endpoint. /// /// See @@ -396,7 +397,7 @@ pub struct GuildAffinities { pub guild_affinities: Vec, } -#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] +#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord)] /// Return type for the error in the [crate::instance::ChorusUser::create_domain_connection] endpoint. /// /// This allows us to retrieve the needed proof for actually verifying the connection. @@ -404,8 +405,8 @@ pub struct GuildAffinities { /// See pub(crate) struct CreateDomainConnectionError { pub message: String, - pub code: u16, - pub proof: String, + pub code: u16, + pub proof: String, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -413,25 +414,44 @@ pub(crate) struct CreateDomainConnectionError { /// /// See pub enum CreateDomainConnectionReturn { - /// Additional proof is needed to verify domain ownership. - /// - /// The inner object is a proof string (e.g. - /// `dh=dceaca792e3c40fcf356a9297949940af5cfe538`) - /// - /// To verify ownership, either: - /// - /// - add the proof string as a TXT DNS record to the domain, - /// with the name of the record being `_discord.{domain}` - /// - /// or - /// - /// - serve the proof string as a file at `https://{domain}/.well-known/discord` - /// - /// After either of these proofs are added, the request should be retried. - /// - ProofNeeded(String), - /// The domain connection was successfully created, no further action is needed. - /// - /// The inner object is the new connection. - Ok(Connection) + /// Additional proof is needed to verify domain ownership. + /// + /// The inner object is a proof string (e.g. + /// `dh=dceaca792e3c40fcf356a9297949940af5cfe538`) + /// + /// To verify ownership, either: + /// + /// - add the proof string as a TXT DNS record to the domain, + /// with the name of the record being `_discord.{domain}` + /// + /// or + /// + /// - serve the proof string as a file at `https://{domain}/.well-known/discord` + /// + /// After either of these proofs are added, the request should be retried. + /// + ProofNeeded(String), + /// The domain connection was successfully created, no further action is needed. + /// + /// The inner object is the new connection. + Ok(Connection), +} + +#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +/// Return type for the [crate::instance::ChorusUser::get_burst_credits] endpoint. +/// +/// # Reference +/// ```json +/// { +/// "amount": 2, +/// "replenished_today": false, +/// "next_replenish_at": "2024-08-18T23:53:17+00:00" +/// } +/// ``` +pub struct BurstCreditsInfo { + /// Amount of remaining burst credits the local user has + pub amount: u16, + pub replenished_today: bool, + /// When the user's burst credits will automatically replenish again + pub next_replenish_at: DateTime, }