From fb7e33c0ec4fe1517623efd3f1dba612322627eb Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Thu, 24 Aug 2023 21:06:28 +0200 Subject: [PATCH 1/2] Change `UserMeta` to `ChorusUser` --- src/api/auth/login.rs | 8 ++++---- src/api/auth/register.rs | 10 +++++----- src/api/channels/channels.rs | 16 ++++++++-------- src/api/channels/messages.rs | 34 ++++++++++++++++----------------- src/api/channels/permissions.rs | 6 +++--- src/api/channels/reactions.rs | 14 +++++++------- src/api/guilds/guilds.rs | 18 ++++++++--------- src/api/guilds/member.rs | 8 ++++---- src/api/guilds/messages.rs | 4 ++-- src/api/guilds/roles.rs | 12 ++++++------ src/api/invites/mod.rs | 4 ++-- src/api/users/channels.rs | 4 ++-- src/api/users/guilds.rs | 4 ++-- src/api/users/relationships.rs | 4 ++-- src/api/users/users.rs | 10 +++++----- src/instance.rs | 12 ++++++------ src/ratelimiter.rs | 12 ++++++------ tests/common/mod.rs | 10 +++++----- 18 files changed, 95 insertions(+), 95 deletions(-) diff --git a/src/api/auth/login.rs b/src/api/auth/login.rs index 34a873b..d5d96e6 100644 --- a/src/api/auth/login.rs +++ b/src/api/auth/login.rs @@ -8,7 +8,7 @@ use serde_json::to_string; use crate::api::LimitType; use crate::errors::ChorusResult; use crate::gateway::Gateway; -use crate::instance::{Instance, UserMeta}; +use crate::instance::{ChorusUser, Instance}; use crate::ratelimiter::ChorusRequest; use crate::types::{GatewayIdentifyPayload, LoginResult, LoginSchema}; @@ -17,7 +17,7 @@ impl Instance { /// /// # Reference /// See - pub async fn login_account(&mut self, login_schema: &LoginSchema) -> ChorusResult { + pub async fn login_account(&mut self, login_schema: &LoginSchema) -> ChorusResult { let endpoint_url = self.urls.api.clone() + "/auth/login"; let chorus_request = ChorusRequest { request: Client::new() @@ -30,7 +30,7 @@ impl Instance { // request (since login is an instance wide limit), which is why we are just cloning the // instances' limits to pass them on as user_rate_limits later. let mut shell = - UserMeta::shell(Rc::new(RefCell::new(self.clone())), "None".to_string()).await; + ChorusUser::shell(Rc::new(RefCell::new(self.clone())), "None".to_string()).await; let login_result = chorus_request .deserialize_response::(&mut shell) .await?; @@ -42,7 +42,7 @@ impl Instance { let gateway = Gateway::new(self.urls.wss.clone()).await.unwrap(); identify.token = login_result.token.clone(); gateway.send_identify(identify).await; - let user = UserMeta::new( + let user = ChorusUser::new( Rc::new(RefCell::new(self.clone())), login_result.token, self.clone_limits_if_some(), diff --git a/src/api/auth/register.rs b/src/api/auth/register.rs index b4350d2..43292d9 100644 --- a/src/api/auth/register.rs +++ b/src/api/auth/register.rs @@ -9,7 +9,7 @@ use crate::types::GatewayIdentifyPayload; use crate::{ api::policies::instance::LimitType, errors::ChorusResult, - instance::{Instance, Token, UserMeta}, + instance::{ChorusUser, Instance, Token}, ratelimiter::ChorusRequest, types::RegisterSchema, }; @@ -22,7 +22,7 @@ impl Instance { pub async fn register_account( &mut self, register_schema: &RegisterSchema, - ) -> ChorusResult { + ) -> ChorusResult { let endpoint_url = self.urls.api.clone() + "/auth/register"; let chorus_request = ChorusRequest { request: Client::new() @@ -35,7 +35,7 @@ impl Instance { // request (since register is an instance wide limit), which is why we are just cloning // the instances' limits to pass them on as user_rate_limits later. let mut shell = - UserMeta::shell(Rc::new(RefCell::new(self.clone())), "None".to_string()).await; + ChorusUser::shell(Rc::new(RefCell::new(self.clone())), "None".to_string()).await; let token = chorus_request .deserialize_response::(&mut shell) .await? @@ -44,12 +44,12 @@ impl Instance { self.limits_information.as_mut().unwrap().ratelimits = shell.limits.unwrap(); } let user_object = self.get_user(token.clone(), None).await.unwrap(); - let settings = UserMeta::get_settings(&token, &self.urls.api.clone(), self).await?; + let settings = ChorusUser::get_settings(&token, &self.urls.api.clone(), self).await?; let mut identify = GatewayIdentifyPayload::common(); let gateway = Gateway::new(self.urls.wss.clone()).await.unwrap(); identify.token = token.clone(); gateway.send_identify(identify).await; - let user = UserMeta::new( + let user = ChorusUser::new( Rc::new(RefCell::new(self.clone())), token.clone(), self.clone_limits_if_some(), diff --git a/src/api/channels/channels.rs b/src/api/channels/channels.rs index 518de59..6fd0d79 100644 --- a/src/api/channels/channels.rs +++ b/src/api/channels/channels.rs @@ -5,7 +5,7 @@ use crate::types::{AddChannelRecipientSchema, ModifyChannelPositionsSchema}; use crate::{ api::LimitType, errors::{ChorusError, ChorusResult}, - instance::UserMeta, + instance::ChorusUser, ratelimiter::ChorusRequest, types::{Channel, ChannelModifySchema, GetChannelMessagesSchema, Message, Snowflake}, }; @@ -15,7 +15,7 @@ impl Channel { /// /// # Reference /// See - pub async fn get(user: &mut UserMeta, channel_id: Snowflake) -> ChorusResult { + pub async fn get(user: &mut ChorusUser, channel_id: Snowflake) -> ChorusResult { let url = user.belongs_to.borrow().urls.api.clone(); let chorus_request = ChorusRequest { request: Client::new() @@ -33,7 +33,7 @@ impl Channel { /// /// # Reference /// See - pub async fn delete(self, user: &mut UserMeta) -> ChorusResult<()> { + pub async fn delete(self, user: &mut ChorusUser) -> ChorusResult<()> { let chorus_request = ChorusRequest { request: Client::new() .delete(format!( @@ -64,7 +64,7 @@ impl Channel { pub async fn modify( &self, modify_data: ChannelModifySchema, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult { let channel_id = self.id; let chorus_request = ChorusRequest { @@ -94,7 +94,7 @@ impl Channel { pub async fn messages( range: GetChannelMessagesSchema, channel_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> Result, ChorusError> { let chorus_request = ChorusRequest { request: Client::new() @@ -120,7 +120,7 @@ impl Channel { pub async fn add_channel_recipient( &self, recipient_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, add_channel_recipient_schema: Option, ) -> ChorusResult<()> { let mut request = Client::new() @@ -150,7 +150,7 @@ impl Channel { pub async fn remove_channel_recipient( &self, recipient_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { let request = Client::new() .delete(format!( @@ -176,7 +176,7 @@ impl Channel { pub async fn modify_positions( schema: Vec, guild_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { let request = Client::new() .patch(format!( diff --git a/src/api/channels/messages.rs b/src/api/channels/messages.rs index 053ee75..2011c40 100644 --- a/src/api/channels/messages.rs +++ b/src/api/channels/messages.rs @@ -5,7 +5,7 @@ use serde_json::{from_value, to_string, Value}; use crate::api::LimitType; use crate::errors::{ChorusError, ChorusResult}; -use crate::instance::UserMeta; +use crate::instance::ChorusUser; use crate::ratelimiter::ChorusRequest; use crate::types::{ Channel, CreateGreetMessage, Message, MessageAck, MessageModifySchema, MessageSearchEndpoint, @@ -19,7 +19,7 @@ impl Message { /// # Reference /// See pub async fn send( - user: &mut UserMeta, + user: &mut ChorusUser, channel_id: Snowflake, mut message: MessageSendSchema, ) -> ChorusResult { @@ -87,7 +87,7 @@ impl Message { pub(crate) async fn search( endpoint: MessageSearchEndpoint, query: MessageSearchQuery, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult> { let limit_type = match &endpoint { MessageSearchEndpoint::Channel(id) => LimitType::Channel(*id), @@ -136,7 +136,7 @@ impl Message { /// See: pub async fn get_sticky( channel_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult> { let chorus_request = ChorusRequest { request: Client::new() @@ -162,7 +162,7 @@ impl Message { pub async fn sticky( channel_id: Snowflake, message_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { let chorus_request = ChorusRequest { request: Client::new() @@ -185,7 +185,7 @@ impl Message { pub async fn unsticky( channel_id: Snowflake, message_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { let chorus_request = ChorusRequest { request: Client::new() @@ -209,7 +209,7 @@ impl Message { pub async fn get( channel_id: Snowflake, message_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult { let chorus_request = ChorusRequest { request: Client::new() @@ -232,7 +232,7 @@ impl Message { pub async fn create_greet( channel_id: Snowflake, schema: CreateGreetMessage, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult { let chorus_request = ChorusRequest { request: Client::new() @@ -263,7 +263,7 @@ impl Message { channel_id: Snowflake, message_id: Snowflake, schema: MessageAck, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult> { let chorus_request = ChorusRequest { request: Client::new() @@ -292,7 +292,7 @@ impl Message { pub async fn crosspost( channel_id: Snowflake, message_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult { let chorus_request = ChorusRequest { request: Client::new() @@ -316,7 +316,7 @@ impl Message { pub async fn hide_from_guild_feed( channel_id: Snowflake, message_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { let chorus_request = ChorusRequest { request: Client::new() @@ -347,7 +347,7 @@ impl Message { channel_id: Snowflake, message_id: Snowflake, schema: MessageModifySchema, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult { let chorus_request = ChorusRequest { request: Client::new() @@ -370,7 +370,7 @@ impl Message { pub async fn delete( channel_id: Snowflake, message_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { let chorus_request = ChorusRequest { request: Client::new() @@ -399,7 +399,7 @@ impl Message { pub async fn bulk_delete( channel_id: Snowflake, messages: Vec, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { if messages.len() < 2 { return Err(ChorusError::InvalidArguments { @@ -427,7 +427,7 @@ impl Message { /// See: pub async fn acknowledge_pinned( channel_id: Snowflake, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { let chorus_request = ChorusRequest { request: Client::new() @@ -453,7 +453,7 @@ fn search_error(result_text: String) -> ChorusError { } } -impl UserMeta { +impl ChorusUser { /// Sends a message in the channel with the provided channel_id. /// Returns the sent message. /// @@ -485,7 +485,7 @@ impl Channel { pub async fn search_messages( channel_id: Snowflake, query: MessageSearchQuery, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult> { Message::search(MessageSearchEndpoint::Channel(channel_id), query, user).await } diff --git a/src/api/channels/permissions.rs b/src/api/channels/permissions.rs index 8a6316f..13da01d 100644 --- a/src/api/channels/permissions.rs +++ b/src/api/channels/permissions.rs @@ -4,7 +4,7 @@ use serde_json::to_string; use crate::{ api::LimitType, errors::{ChorusError, ChorusResult}, - instance::UserMeta, + instance::ChorusUser, ratelimiter::ChorusRequest, types::{self, PermissionOverwrite, Snowflake}, }; @@ -21,7 +21,7 @@ impl types::Channel { /// # Reference /// See pub async fn edit_permissions( - user: &mut UserMeta, + user: &mut ChorusUser, channel_id: Snowflake, overwrite: PermissionOverwrite, ) -> ChorusResult<()> { @@ -59,7 +59,7 @@ impl types::Channel { /// # Reference /// See pub async fn delete_permission( - user: &mut UserMeta, + user: &mut ChorusUser, channel_id: Snowflake, overwrite_id: Snowflake, ) -> ChorusResult<()> { diff --git a/src/api/channels/reactions.rs b/src/api/channels/reactions.rs index 519da12..f3b51a3 100644 --- a/src/api/channels/reactions.rs +++ b/src/api/channels/reactions.rs @@ -3,7 +3,7 @@ use reqwest::Client; use crate::{ api::LimitType, errors::ChorusResult, - instance::UserMeta, + instance::ChorusUser, ratelimiter::ChorusRequest, types::{self, PublicUser, Snowflake}, }; @@ -21,7 +21,7 @@ impl ReactionMeta { /// /// # Reference /// See - pub async fn delete_all(&self, user: &mut UserMeta) -> ChorusResult<()> { + pub async fn delete_all(&self, user: &mut ChorusUser) -> ChorusResult<()> { let url = format!( "{}/channels/{}/messages/{}/reactions", user.belongs_to.borrow().urls.api, @@ -44,7 +44,7 @@ impl ReactionMeta { /// /// # Reference /// See - pub async fn get(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult> { + pub async fn get(&self, emoji: &str, user: &mut ChorusUser) -> ChorusResult> { let url = format!( "{}/channels/{}/messages/{}/reactions/{}", user.belongs_to.borrow().urls.api, @@ -70,7 +70,7 @@ impl ReactionMeta { /// /// # Reference /// See - pub async fn delete_emoji(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> { + pub async fn delete_emoji(&self, emoji: &str, user: &mut ChorusUser) -> ChorusResult<()> { let url = format!( "{}/channels/{}/messages/{}/reactions/{}", user.belongs_to.borrow().urls.api, @@ -99,7 +99,7 @@ impl ReactionMeta { /// /// # Reference /// See - pub async fn create(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> { + pub async fn create(&self, emoji: &str, user: &mut ChorusUser) -> ChorusResult<()> { let url = format!( "{}/channels/{}/messages/{}/reactions/{}/@me", user.belongs_to.borrow().urls.api, @@ -124,7 +124,7 @@ impl ReactionMeta { /// /// # Reference /// See - pub async fn remove(&self, emoji: &str, user: &mut UserMeta) -> ChorusResult<()> { + pub async fn remove(&self, emoji: &str, user: &mut ChorusUser) -> ChorusResult<()> { let url = format!( "{}/channels/{}/messages/{}/reactions/{}/@me", user.belongs_to.borrow().urls.api, @@ -154,7 +154,7 @@ impl ReactionMeta { &self, user_id: Snowflake, emoji: &str, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult<()> { let url = format!( "{}/channels/{}/messages/{}/reactions/{}/{}", diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index 85a18b7..a56b4c4 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -5,7 +5,7 @@ use serde_json::to_string; use crate::api::LimitType; use crate::errors::ChorusError; use crate::errors::ChorusResult; -use crate::instance::UserMeta; +use crate::instance::ChorusUser; use crate::ratelimiter::ChorusRequest; use crate::types::{ Channel, ChannelCreateSchema, Guild, GuildBanCreateSchema, GuildCreateSchema, GuildModifySchema, @@ -18,7 +18,7 @@ impl Guild { /// # Reference /// See pub async fn create( - user: &mut UserMeta, + user: &mut ChorusUser, guild_create_schema: GuildCreateSchema, ) -> ChorusResult { let url = format!("{}/guilds", user.belongs_to.borrow().urls.api); @@ -52,7 +52,7 @@ impl Guild { /// /// # Reference /// See - pub async fn delete(user: &mut UserMeta, guild_id: Snowflake) -> ChorusResult<()> { + pub async fn delete(user: &mut ChorusUser, guild_id: Snowflake) -> ChorusResult<()> { let url = format!( "{}/guilds/{}/delete", user.belongs_to.borrow().urls.api, @@ -79,7 +79,7 @@ impl Guild { /// See pub async fn create_channel( &self, - user: &mut UserMeta, + user: &mut ChorusUser, schema: ChannelCreateSchema, ) -> ChorusResult { Channel::create(user, self.id, schema).await @@ -91,7 +91,7 @@ impl Guild { /// /// # Reference /// See - pub async fn channels(&self, user: &mut UserMeta) -> ChorusResult> { + pub async fn channels(&self, user: &mut ChorusUser) -> ChorusResult> { let chorus_request = ChorusRequest { request: Client::new() .get(format!( @@ -125,7 +125,7 @@ impl Guild { /// /// # Reference /// See - pub async fn get(guild_id: Snowflake, user: &mut UserMeta) -> ChorusResult { + pub async fn get(guild_id: Snowflake, user: &mut ChorusUser) -> ChorusResult { let chorus_request = ChorusRequest { request: Client::new() .get(format!( @@ -144,7 +144,7 @@ impl Guild { guild_id: Snowflake, user_id: Snowflake, schema: GuildBanCreateSchema, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult { let chorus_request = ChorusRequest { request: Client::new() @@ -169,7 +169,7 @@ impl Guild { pub async fn modify( guild_id: Snowflake, schema: GuildModifySchema, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult { let chorus_request = ChorusRequest { request: Client::new() @@ -195,7 +195,7 @@ impl Channel { /// # Reference /// See pub async fn create( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, schema: ChannelCreateSchema, ) -> ChorusResult { diff --git a/src/api/guilds/member.rs b/src/api/guilds/member.rs index f9f02dc..ca81ea1 100644 --- a/src/api/guilds/member.rs +++ b/src/api/guilds/member.rs @@ -3,7 +3,7 @@ use reqwest::Client; use crate::{ api::LimitType, errors::ChorusResult, - instance::UserMeta, + instance::ChorusUser, ratelimiter::ChorusRequest, types::{self, GuildMember, Snowflake}, }; @@ -14,7 +14,7 @@ impl types::GuildMember { /// # Reference /// See pub async fn get( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, member_id: Snowflake, ) -> ChorusResult { @@ -40,7 +40,7 @@ impl types::GuildMember { /// # Reference /// See pub async fn add_role( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, member_id: Snowflake, role_id: Snowflake, @@ -69,7 +69,7 @@ impl types::GuildMember { /// # Reference /// See pub async fn remove_role( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, member_id: Snowflake, role_id: Snowflake, diff --git a/src/api/guilds/messages.rs b/src/api/guilds/messages.rs index 72d886c..60fd4e3 100644 --- a/src/api/guilds/messages.rs +++ b/src/api/guilds/messages.rs @@ -1,5 +1,5 @@ use crate::errors::ChorusResult; -use crate::instance::UserMeta; +use crate::instance::ChorusUser; use crate::types::{Guild, Message, MessageSearchQuery, Snowflake}; impl Guild { @@ -16,7 +16,7 @@ impl Guild { pub async fn search_messages( guild_id: Snowflake, query: MessageSearchQuery, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult> { Message::search( crate::types::MessageSearchEndpoint::GuildChannel(guild_id), diff --git a/src/api/guilds/roles.rs b/src/api/guilds/roles.rs index 678450c..eb837c9 100644 --- a/src/api/guilds/roles.rs +++ b/src/api/guilds/roles.rs @@ -4,7 +4,7 @@ use serde_json::to_string; use crate::{ api::LimitType, errors::{ChorusError, ChorusResult}, - instance::UserMeta, + instance::ChorusUser, ratelimiter::ChorusRequest, types::{self, RoleCreateModifySchema, RoleObject, RolePositionUpdateSchema, Snowflake}, }; @@ -15,7 +15,7 @@ impl types::RoleObject { /// # Reference /// See pub async fn get_all( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, ) -> ChorusResult> { let url = format!( @@ -39,7 +39,7 @@ impl types::RoleObject { /// # Reference /// See pub async fn get( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, role_id: Snowflake, ) -> ChorusResult { @@ -65,7 +65,7 @@ impl types::RoleObject { /// # Reference /// See pub async fn create( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, role_create_schema: RoleCreateModifySchema, ) -> ChorusResult { @@ -99,7 +99,7 @@ impl types::RoleObject { /// # Reference /// See pub async fn position_update( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, role_position_update_schema: RolePositionUpdateSchema, ) -> ChorusResult { @@ -132,7 +132,7 @@ impl types::RoleObject { /// # Reference /// See pub async fn modify( - user: &mut UserMeta, + user: &mut ChorusUser, guild_id: Snowflake, role_id: Snowflake, role_create_schema: RoleCreateModifySchema, diff --git a/src/api/invites/mod.rs b/src/api/invites/mod.rs index 8742c3f..88a5705 100644 --- a/src/api/invites/mod.rs +++ b/src/api/invites/mod.rs @@ -2,11 +2,11 @@ use reqwest::Client; use serde_json::to_string; use crate::errors::ChorusResult; -use crate::instance::UserMeta; +use crate::instance::ChorusUser; use crate::ratelimiter::ChorusRequest; use crate::types::{CreateChannelInviteSchema, GuildInvite, Invite, Snowflake}; -impl UserMeta { +impl ChorusUser { /// Accepts an invite to a guild, group DM, or DM. /// /// Note that the session ID is required for guest invites. diff --git a/src/api/users/channels.rs b/src/api/users/channels.rs index 5a33c6c..993894f 100644 --- a/src/api/users/channels.rs +++ b/src/api/users/channels.rs @@ -4,12 +4,12 @@ use serde_json::to_string; use crate::{ api::LimitType, errors::ChorusResult, - instance::UserMeta, + instance::ChorusUser, ratelimiter::ChorusRequest, types::{Channel, PrivateChannelCreateSchema}, }; -impl UserMeta { +impl ChorusUser { /// Creates a DM channel or group DM channel. /// /// One recipient creates or returns an existing DM channel, diff --git a/src/api/users/guilds.rs b/src/api/users/guilds.rs index 355f38c..7e0a6c2 100644 --- a/src/api/users/guilds.rs +++ b/src/api/users/guilds.rs @@ -2,11 +2,11 @@ use reqwest::Client; use serde_json::to_string; use crate::errors::ChorusResult; -use crate::instance::UserMeta; +use crate::instance::ChorusUser; use crate::ratelimiter::ChorusRequest; use crate::types::Snowflake; -impl UserMeta { +impl ChorusUser { /// Leaves a given guild. /// /// # Reference: diff --git a/src/api/users/relationships.rs b/src/api/users/relationships.rs index e08f414..ae4ee27 100644 --- a/src/api/users/relationships.rs +++ b/src/api/users/relationships.rs @@ -4,14 +4,14 @@ use serde_json::to_string; use crate::{ api::LimitType, errors::ChorusResult, - instance::UserMeta, + instance::ChorusUser, ratelimiter::ChorusRequest, types::{ self, CreateUserRelationshipSchema, FriendRequestSendSchema, RelationshipType, Snowflake, }, }; -impl UserMeta { +impl ChorusUser { /// Retrieves a list of mutual friends between the authenticated user and a given user. /// /// # Reference diff --git a/src/api/users/users.rs b/src/api/users/users.rs index 41af054..d80700e 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -6,12 +6,12 @@ use serde_json::to_string; use crate::{ api::LimitType, errors::{ChorusError, ChorusResult}, - instance::{Instance, UserMeta}, + instance::{ChorusUser, Instance}, ratelimiter::ChorusRequest, types::{User, UserModifySchema, UserSettings}, }; -impl UserMeta { +impl ChorusUser { /// Gets a user by id, or if the id is None, gets the current user. /// /// # Notes @@ -85,7 +85,7 @@ impl User { /// # Reference /// See and /// - pub async fn get(user: &mut UserMeta, id: Option<&String>) -> ChorusResult { + pub async fn get(user: &mut ChorusUser, id: Option<&String>) -> ChorusResult { let url_api = user.belongs_to.borrow().urls.api.clone(); let url = if id.is_none() { format!("{}/users/@me", url_api) @@ -121,7 +121,7 @@ impl User { .get(format!("{}/users/@me/settings", url_api)) .header("Authorization", token); let mut user = - UserMeta::shell(Rc::new(RefCell::new(instance.clone())), token.clone()).await; + ChorusUser::shell(Rc::new(RefCell::new(instance.clone())), token.clone()).await; let chorus_request = ChorusRequest { request, limit_type: LimitType::Global, @@ -148,7 +148,7 @@ impl Instance { /// See and /// pub async fn get_user(&mut self, token: String, id: Option<&String>) -> ChorusResult { - let mut user = UserMeta::shell(Rc::new(RefCell::new(self.clone())), token).await; + let mut user = ChorusUser::shell(Rc::new(RefCell::new(self.clone())), token).await; let result = User::get(&mut user, id).await; if self.limits_information.is_some() { self.limits_information.as_mut().unwrap().ratelimits = diff --git a/src/instance.rs b/src/instance.rs index 4ed0f60..ba67abc 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -87,7 +87,7 @@ impl fmt::Display for Token { /// A UserMeta is a representation of an authenticated user on an [Instance]. /// It is used for most authenticated actions on a Spacebar server. /// It also has its own [Gateway] connection. -pub struct UserMeta { +pub struct ChorusUser { pub belongs_to: Rc>, pub token: String, pub limits: Option>, @@ -96,7 +96,7 @@ pub struct UserMeta { pub gateway: GatewayHandle, } -impl UserMeta { +impl ChorusUser { pub fn token(&self) -> String { self.token.clone() } @@ -117,8 +117,8 @@ impl UserMeta { settings: Arc>, object: Arc>, gateway: GatewayHandle, - ) -> UserMeta { - UserMeta { + ) -> ChorusUser { + ChorusUser { belongs_to, token, limits, @@ -133,13 +133,13 @@ impl UserMeta { /// registering or logging in to the Instance, where you do not yet have a User object, but still /// need to make a RateLimited request. To use the [`GatewayHandle`], you will have to identify /// first. - pub(crate) async fn shell(instance: Rc>, token: String) -> UserMeta { + pub(crate) async fn shell(instance: Rc>, token: String) -> ChorusUser { let settings = Arc::new(RwLock::new(UserSettings::default())); let object = Arc::new(RwLock::new(User::default())); let wss_url = instance.borrow().urls.wss.clone(); // Dummy gateway object let gateway = Gateway::new(wss_url).await.unwrap(); - UserMeta { + ChorusUser { token, belongs_to: instance.clone(), limits: instance diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index 2c1ecd0..7e9d7fc 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -8,7 +8,7 @@ use serde_json::from_str; use crate::{ api::{Limit, LimitType}, errors::{ChorusError, ChorusResult}, - instance::UserMeta, + instance::ChorusUser, types::{types::subconfigs::limits::rates::RateLimits, LimitsConfiguration}, }; @@ -24,7 +24,7 @@ impl ChorusRequest { /// If the user is not rate limited and the instance has rate limits enabled, it will update the /// rate limits. #[allow(clippy::await_holding_refcell_ref)] - pub(crate) async fn send_request(self, user: &mut UserMeta) -> ChorusResult { + pub(crate) async fn send_request(self, user: &mut ChorusUser) -> ChorusResult { if !ChorusRequest::can_send_request(user, &self.limit_type) { log::info!("Rate limit hit. Bucket: {:?}", self.limit_type); return Err(ChorusError::RateLimited { @@ -73,7 +73,7 @@ impl ChorusRequest { Ok(result) } - fn can_send_request(user: &mut UserMeta, limit_type: &LimitType) -> bool { + fn can_send_request(user: &mut ChorusUser, limit_type: &LimitType) -> bool { log::trace!("Checking if user or instance is rate-limited..."); let mut belongs_to = user.belongs_to.borrow_mut(); if belongs_to.limits_information.is_none() { @@ -236,7 +236,7 @@ impl ChorusRequest { /// set to the current unix timestamp + the rate limit window. The remaining rate limit is /// reset to the rate limit limit. /// 2. The remaining rate limit is decreased by 1. - fn update_rate_limits(user: &mut UserMeta, limit_type: &LimitType, response_was_err: bool) { + fn update_rate_limits(user: &mut ChorusUser, limit_type: &LimitType, response_was_err: bool) { if user.belongs_to.borrow().limits_information.is_none() { return; } @@ -429,7 +429,7 @@ impl ChorusRequest { /// Sends a [`ChorusRequest`] and returns a [`ChorusResult`] that contains nothing if the request /// was successful, or a [`ChorusError`] if the request failed. - pub(crate) async fn handle_request_as_result(self, user: &mut UserMeta) -> ChorusResult<()> { + pub(crate) async fn handle_request_as_result(self, user: &mut ChorusUser) -> ChorusResult<()> { match self.send_request(user).await { Ok(_) => Ok(()), Err(e) => Err(e), @@ -440,7 +440,7 @@ impl ChorusRequest { /// was successful, or a [`ChorusError`] if the request failed. pub(crate) async fn deserialize_response Deserialize<'a>>( self, - user: &mut UserMeta, + user: &mut ChorusUser, ) -> ChorusResult { let response = self.send_request(user).await?; debug!("Got response: {:?}", response); diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 2dc0718..b1f9639 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock}; use chorus::gateway::Gateway; use chorus::{ - instance::{Instance, UserMeta}, + instance::{ChorusUser, Instance}, types::{ Channel, ChannelCreateSchema, Guild, GuildCreateSchema, RegisterSchema, RoleCreateModifySchema, RoleObject, @@ -14,7 +14,7 @@ use chorus::{ #[derive(Debug)] pub(crate) struct TestBundle { pub urls: UrlBundle, - pub user: UserMeta, + pub user: ChorusUser, pub instance: Instance, pub guild: Arc>, pub role: Arc>, @@ -23,7 +23,7 @@ pub(crate) struct TestBundle { #[allow(unused)] impl TestBundle { - pub(crate) async fn create_user(&mut self, username: &str) -> UserMeta { + pub(crate) async fn create_user(&mut self, username: &str) -> ChorusUser { let register_schema = RegisterSchema { username: username.to_string(), consent: true, @@ -35,8 +35,8 @@ impl TestBundle { .await .unwrap() } - pub(crate) async fn clone_user_without_gateway(&self) -> UserMeta { - UserMeta { + pub(crate) async fn clone_user_without_gateway(&self) -> ChorusUser { + ChorusUser { belongs_to: self.user.belongs_to.clone(), token: self.user.token.clone(), limits: self.user.limits.clone(), From 64ba6a657a03facc9a52f73554b2dae374aa4bd2 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Thu, 24 Aug 2023 21:09:23 +0200 Subject: [PATCH 2/2] Change `UserMeta` to `ChorusUser` --- src/instance.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index ba67abc..7219c03 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -84,7 +84,7 @@ impl fmt::Display for Token { } #[derive(Debug)] -/// A UserMeta is a representation of an authenticated user on an [Instance]. +/// A ChorusUser is a representation of an authenticated user on an [Instance]. /// It is used for most authenticated actions on a Spacebar server. /// It also has its own [Gateway] connection. pub struct ChorusUser { @@ -105,10 +105,10 @@ impl ChorusUser { self.token = token; } - /// Creates a new [UserMeta] from existing data. + /// Creates a new [ChorusUser] from existing data. /// /// # Notes - /// This isn't the prefered way to create a UserMeta. + /// This isn't the prefered way to create a ChorusUser. /// See [Instance::login_account] and [Instance::register_account] instead. pub fn new( belongs_to: Rc>, @@ -129,7 +129,7 @@ impl ChorusUser { } /// Creates a new 'shell' of a user. The user does not exist as an object, and exists so that you have - /// a UserMeta object to make Rate Limited requests with. This is useful in scenarios like + /// a ChorusUser object to make Rate Limited requests with. This is useful in scenarios like /// registering or logging in to the Instance, where you do not yet have a User object, but still /// need to make a RateLimited request. To use the [`GatewayHandle`], you will have to identify /// first.