From 0dfd6226619aa63fc328077b54ea6df42b29a325 Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Wed, 30 Aug 2023 13:26:19 +0000 Subject: [PATCH] Fix failing build w/o client and move ratelimits (#426) * Fix failing build without client feature * Feature lock Updateable and Composite --- src/api/auth/login.rs | 3 +-- src/api/auth/register.rs | 2 +- src/api/channels/channels.rs | 5 ++-- src/api/channels/messages.rs | 5 ++-- src/api/channels/permissions.rs | 3 +-- src/api/channels/reactions.rs | 3 +-- src/api/guilds/guilds.rs | 3 +-- src/api/guilds/member.rs | 3 +-- src/api/guilds/roles.rs | 5 ++-- src/api/invites/mod.rs | 8 +++--- src/api/mod.rs | 1 - src/api/policies/instance/mod.rs | 2 -- src/api/policies/mod.rs | 2 -- src/api/users/channels.rs | 3 +-- src/api/users/guilds.rs | 5 ++-- src/api/users/relationships.rs | 4 +-- src/api/users/users.rs | 3 +-- src/instance.rs | 3 +-- src/ratelimiter.rs | 3 +-- .../config/types/subconfigs/limits/rates.rs | 8 +++--- src/types/entities/auto_moderation.rs | 7 +++++- src/types/entities/channel.rs | 24 +++++++++++------- src/types/entities/emoji.rs | 16 +++++++++--- src/types/entities/guild.rs | 25 ++++++++++++------- src/types/entities/mod.rs | 10 ++++++++ .../instance => types/entities}/ratelimits.rs | 0 src/types/entities/role.rs | 16 +++++++++--- src/types/entities/user.rs | 13 +++++++--- src/types/entities/user_settings.rs | 6 +++-- src/types/entities/voice_state.rs | 13 +++++++--- src/types/entities/webhook.rs | 13 +++++++--- src/types/events/auto_moderation.rs | 2 ++ src/types/events/channel.rs | 13 +++++++--- src/types/events/guild.rs | 11 +++++--- src/types/events/mod.rs | 25 +++++++++++++------ src/types/events/thread.rs | 2 ++ 36 files changed, 173 insertions(+), 97 deletions(-) rename src/{api/policies/instance => types/entities}/ratelimits.rs (100%) diff --git a/src/api/auth/login.rs b/src/api/auth/login.rs index a95c3ca..1564bfb 100644 --- a/src/api/auth/login.rs +++ b/src/api/auth/login.rs @@ -3,12 +3,11 @@ use std::sync::{Arc, RwLock}; use reqwest::Client; use serde_json::to_string; -use crate::api::LimitType; use crate::errors::ChorusResult; use crate::gateway::Gateway; use crate::instance::{ChorusUser, Instance}; use crate::ratelimiter::ChorusRequest; -use crate::types::{GatewayIdentifyPayload, LoginResult, LoginSchema}; +use crate::types::{GatewayIdentifyPayload, LimitType, LoginResult, LoginSchema}; impl Instance { /// Logs into an existing account on the spacebar server. diff --git a/src/api/auth/register.rs b/src/api/auth/register.rs index 1a95d3d..d278a50 100644 --- a/src/api/auth/register.rs +++ b/src/api/auth/register.rs @@ -6,10 +6,10 @@ use serde_json::to_string; use crate::gateway::Gateway; use crate::types::GatewayIdentifyPayload; use crate::{ - api::policies::instance::LimitType, errors::ChorusResult, instance::{ChorusUser, Instance, Token}, ratelimiter::ChorusRequest, + types::LimitType, types::RegisterSchema, }; diff --git a/src/api/channels/channels.rs b/src/api/channels/channels.rs index 7250b0e..9560d74 100644 --- a/src/api/channels/channels.rs +++ b/src/api/channels/channels.rs @@ -3,11 +3,12 @@ use serde_json::to_string; use crate::types::{AddChannelRecipientSchema, ModifyChannelPositionsSchema}; use crate::{ - api::LimitType, errors::{ChorusError, ChorusResult}, instance::ChorusUser, ratelimiter::ChorusRequest, - types::{Channel, ChannelModifySchema, GetChannelMessagesSchema, Message, Snowflake}, + types::{ + Channel, ChannelModifySchema, GetChannelMessagesSchema, LimitType, Message, Snowflake, + }, }; impl Channel { diff --git a/src/api/channels/messages.rs b/src/api/channels/messages.rs index 960e492..6dfdfbf 100644 --- a/src/api/channels/messages.rs +++ b/src/api/channels/messages.rs @@ -3,13 +3,12 @@ use http::HeaderMap; use reqwest::{multipart, Client}; use serde_json::{from_value, to_string, Value}; -use crate::api::LimitType; use crate::errors::{ChorusError, ChorusResult}; use crate::instance::ChorusUser; use crate::ratelimiter::ChorusRequest; use crate::types::{ - Channel, CreateGreetMessage, Message, MessageAck, MessageModifySchema, MessageSearchEndpoint, - MessageSearchQuery, MessageSendSchema, Snowflake, + Channel, CreateGreetMessage, LimitType, Message, MessageAck, MessageModifySchema, + MessageSearchEndpoint, MessageSearchQuery, MessageSendSchema, Snowflake, }; impl Message { diff --git a/src/api/channels/permissions.rs b/src/api/channels/permissions.rs index 7fa8edd..5360890 100644 --- a/src/api/channels/permissions.rs +++ b/src/api/channels/permissions.rs @@ -2,11 +2,10 @@ use reqwest::Client; use serde_json::to_string; use crate::{ - api::LimitType, errors::{ChorusError, ChorusResult}, instance::ChorusUser, ratelimiter::ChorusRequest, - types::{self, PermissionOverwrite, Snowflake}, + types::{self, LimitType, PermissionOverwrite, Snowflake}, }; impl types::Channel { diff --git a/src/api/channels/reactions.rs b/src/api/channels/reactions.rs index 81c0366..94d3087 100644 --- a/src/api/channels/reactions.rs +++ b/src/api/channels/reactions.rs @@ -1,9 +1,8 @@ use crate::{ - api::LimitType, errors::ChorusResult, instance::ChorusUser, ratelimiter::ChorusRequest, - types::{self, PublicUser, Snowflake}, + types::{self, LimitType, PublicUser, Snowflake}, }; /// Useful metadata for working with [`types::Reaction`], bundled together nicely. diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index 8d5f0d6..b433c84 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -2,14 +2,13 @@ use reqwest::Client; use serde_json::from_str; use serde_json::to_string; -use crate::api::LimitType; use crate::errors::ChorusError; use crate::errors::ChorusResult; use crate::instance::ChorusUser; use crate::ratelimiter::ChorusRequest; use crate::types::{ Channel, ChannelCreateSchema, Guild, GuildBanCreateSchema, GuildBansQuery, GuildCreateSchema, - GuildMember, GuildMemberSearchSchema, GuildModifySchema, GuildPreview, + GuildMember, GuildMemberSearchSchema, GuildModifySchema, GuildPreview, LimitType, ModifyGuildMemberProfileSchema, ModifyGuildMemberSchema, UserProfileMetadata, }; use crate::types::{GuildBan, Snowflake}; diff --git a/src/api/guilds/member.rs b/src/api/guilds/member.rs index 01294bd..885ddf9 100644 --- a/src/api/guilds/member.rs +++ b/src/api/guilds/member.rs @@ -1,11 +1,10 @@ use reqwest::Client; use crate::{ - api::LimitType, errors::ChorusResult, instance::ChorusUser, ratelimiter::ChorusRequest, - types::{self, GuildMember, Snowflake}, + types::{self, GuildMember, LimitType, Snowflake}, }; impl types::GuildMember { diff --git a/src/api/guilds/roles.rs b/src/api/guilds/roles.rs index 17d6f7b..f131367 100644 --- a/src/api/guilds/roles.rs +++ b/src/api/guilds/roles.rs @@ -2,11 +2,12 @@ use reqwest::Client; use serde_json::to_string; use crate::{ - api::LimitType, errors::{ChorusError, ChorusResult}, instance::ChorusUser, ratelimiter::ChorusRequest, - types::{self, RoleCreateModifySchema, RoleObject, RolePositionUpdateSchema, Snowflake}, + types::{ + self, LimitType, RoleCreateModifySchema, RoleObject, RolePositionUpdateSchema, Snowflake, + }, }; impl types::RoleObject { diff --git a/src/api/invites/mod.rs b/src/api/invites/mod.rs index 658fb22..332570b 100644 --- a/src/api/invites/mod.rs +++ b/src/api/invites/mod.rs @@ -4,7 +4,7 @@ use serde_json::to_string; use crate::errors::ChorusResult; use crate::instance::ChorusUser; use crate::ratelimiter::ChorusRequest; -use crate::types::{CreateChannelInviteSchema, GuildInvite, Invite, Snowflake}; +use crate::types::{CreateChannelInviteSchema, GuildInvite, Invite, LimitType, Snowflake}; impl ChorusUser { /// Accepts an invite to a guild, group DM, or DM. @@ -26,7 +26,7 @@ impl ChorusUser { invite_code )) .header("Authorization", self.token()), - limit_type: super::LimitType::Global, + limit_type: LimitType::Global, }; if session_id.is_some() { request.request = request @@ -53,7 +53,7 @@ impl ChorusUser { .body(to_string(&code).unwrap()) .header("Authorization", self.token()) .header("Content-Type", "application/json"), - limit_type: super::LimitType::Global, + limit_type: LimitType::Global, } .deserialize_response::(self) .await @@ -81,7 +81,7 @@ impl ChorusUser { .header("Authorization", self.token()) .header("Content-Type", "application/json") .body(to_string(&create_channel_invite_schema).unwrap()), - limit_type: super::LimitType::Channel(channel_id), + limit_type: LimitType::Channel(channel_id), } .deserialize_response::(self) .await diff --git a/src/api/mod.rs b/src/api/mod.rs index 7329c50..ab3f9b9 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -3,7 +3,6 @@ pub use channels::messages::*; pub use guilds::*; pub use invites::*; pub use policies::instance::instance::*; -pub use policies::instance::ratelimits::*; pub use users::*; pub mod auth; diff --git a/src/api/policies/instance/mod.rs b/src/api/policies/instance/mod.rs index 0a1f245..b3a9148 100644 --- a/src/api/policies/instance/mod.rs +++ b/src/api/policies/instance/mod.rs @@ -1,5 +1,3 @@ pub use instance::*; -pub use ratelimits::*; pub mod instance; -pub mod ratelimits; diff --git a/src/api/policies/mod.rs b/src/api/policies/mod.rs index d0c29f1..1d5ea99 100644 --- a/src/api/policies/mod.rs +++ b/src/api/policies/mod.rs @@ -1,3 +1 @@ -pub use instance::ratelimits::*; - pub mod instance; diff --git a/src/api/users/channels.rs b/src/api/users/channels.rs index 8d5f063..330b3e3 100644 --- a/src/api/users/channels.rs +++ b/src/api/users/channels.rs @@ -2,11 +2,10 @@ use reqwest::Client; use serde_json::to_string; use crate::{ - api::LimitType, errors::ChorusResult, instance::ChorusUser, ratelimiter::ChorusRequest, - types::{Channel, PrivateChannelCreateSchema}, + types::{Channel, LimitType, PrivateChannelCreateSchema}, }; impl ChorusUser { diff --git a/src/api/users/guilds.rs b/src/api/users/guilds.rs index d2d5b9e..6ffcdfc 100644 --- a/src/api/users/guilds.rs +++ b/src/api/users/guilds.rs @@ -1,11 +1,10 @@ use reqwest::Client; use serde_json::to_string; -use crate::api::LimitType; use crate::errors::ChorusResult; use crate::instance::ChorusUser; use crate::ratelimiter::ChorusRequest; -use crate::types::{GetUserGuildSchema, Guild, Snowflake}; +use crate::types::{GetUserGuildSchema, Guild, LimitType, Snowflake}; impl ChorusUser { /// Leaves a given guild. @@ -26,7 +25,7 @@ impl ChorusUser { .header("Authorization", self.token()) .header("Content-Type", "application/json") .body(to_string(&lurking).unwrap()), - limit_type: crate::api::LimitType::Guild(*guild_id), + limit_type: LimitType::Guild(*guild_id), } .handle_request_as_result(self) .await diff --git a/src/api/users/relationships.rs b/src/api/users/relationships.rs index 8988871..4f9602c 100644 --- a/src/api/users/relationships.rs +++ b/src/api/users/relationships.rs @@ -2,12 +2,12 @@ use reqwest::Client; use serde_json::to_string; use crate::{ - api::LimitType, errors::ChorusResult, instance::ChorusUser, ratelimiter::ChorusRequest, types::{ - self, CreateUserRelationshipSchema, FriendRequestSendSchema, RelationshipType, Snowflake, + self, CreateUserRelationshipSchema, FriendRequestSendSchema, LimitType, RelationshipType, + Snowflake, }, }; diff --git a/src/api/users/users.rs b/src/api/users/users.rs index 25ac6cd..0f31d6f 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -4,11 +4,10 @@ use reqwest::Client; use serde_json::to_string; use crate::{ - api::LimitType, errors::{ChorusError, ChorusResult}, instance::{ChorusUser, Instance}, ratelimiter::ChorusRequest, - types::{User, UserModifySchema, UserSettings}, + types::{LimitType, User, UserModifySchema, UserSettings}, }; impl ChorusUser { diff --git a/src/instance.rs b/src/instance.rs index 8ced86a..aa5d4d1 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -8,12 +8,11 @@ use std::sync::{Arc, RwLock}; use reqwest::Client; use serde::{Deserialize, Serialize}; -use crate::api::{Limit, LimitType}; use crate::errors::ChorusResult; use crate::gateway::{Gateway, GatewayHandle}; use crate::ratelimiter::ChorusRequest; use crate::types::types::subconfigs::limits::rates::RateLimits; -use crate::types::{GeneralConfiguration, User, UserSettings}; +use crate::types::{GeneralConfiguration, Limit, LimitType, User, UserSettings}; use crate::UrlBundle; #[derive(Debug, Clone)] diff --git a/src/ratelimiter.rs b/src/ratelimiter.rs index 84bd641..d20e28a 100644 --- a/src/ratelimiter.rs +++ b/src/ratelimiter.rs @@ -8,10 +8,9 @@ use serde::Deserialize; use serde_json::from_str; use crate::{ - api::{Limit, LimitType}, errors::{ChorusError, ChorusResult}, instance::ChorusUser, - types::{types::subconfigs::limits::rates::RateLimits, LimitsConfiguration}, + types::{types::subconfigs::limits::rates::RateLimits, Limit, LimitType, LimitsConfiguration}, }; /// Chorus' request struct. This struct is used to send rate-limited requests to the Spacebar server. diff --git a/src/types/config/types/subconfigs/limits/rates.rs b/src/types/config/types/subconfigs/limits/rates.rs index ce1ea60..8fdd183 100644 --- a/src/types/config/types/subconfigs/limits/rates.rs +++ b/src/types/config/types/subconfigs/limits/rates.rs @@ -2,11 +2,9 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; -use crate::{ - api::LimitType, - types::config::types::subconfigs::limits::ratelimits::{ - route::RouteRateLimit, RateLimitOptions, - }, +use crate::types::{ + config::types::subconfigs::limits::ratelimits::{route::RouteRateLimit, RateLimitOptions}, + LimitType, }; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/src/types/entities/auto_moderation.rs b/src/types/entities/auto_moderation.rs index eaec2b0..a8910b1 100644 --- a/src/types/entities/auto_moderation.rs +++ b/src/types/entities/auto_moderation.rs @@ -1,13 +1,18 @@ use std::sync::{Arc, RwLock}; +#[cfg(feature = "client")] use crate::gateway::Updateable; + +#[cfg(feature = "client")] use chorus_macros::Updateable; + use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; use crate::types::utils::Snowflake; -#[derive(Serialize, Deserialize, Debug, Default, Clone, Updateable)] +#[cfg_attr(feature = "client", derive(Updateable))] +#[derive(Serialize, Deserialize, Debug, Default, Clone)] /// See pub struct AutoModerationRule { pub id: Snowflake, diff --git a/src/types/entities/channel.rs b/src/types/entities/channel.rs index 84530c9..280401c 100644 --- a/src/types/entities/channel.rs +++ b/src/types/entities/channel.rs @@ -1,21 +1,28 @@ use std::sync::{Arc, RwLock}; -use chorus_macros::{observe_option_vec, Composite, Updateable}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_aux::prelude::deserialize_string_from_number; use serde_repr::{Deserialize_repr, Serialize_repr}; use std::fmt::Debug; -use crate::gateway::{GatewayHandle, Updateable}; use crate::types::{ entities::{GuildMember, User}, utils::Snowflake, - Composite, }; -#[derive(Default, Debug, Serialize, Deserialize, Clone, Updateable, Composite)] +#[cfg(feature = "client")] +use crate::types::Composite; + +#[cfg(feature = "client")] +use crate::gateway::{GatewayHandle, Updateable}; + +#[cfg(feature = "client")] +use chorus_macros::{observe_option_vec, Composite, Updateable}; + +#[derive(Default, Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] +#[cfg_attr(feature = "client", derive(Updateable, Composite))] /// Represents a guild or private channel /// /// # Reference @@ -60,13 +67,13 @@ pub struct Channel { #[cfg(feature = "sqlx")] pub permission_overwrites: Option>>, #[cfg(not(feature = "sqlx"))] - #[observe_option_vec] + #[cfg_attr(feature = "client", observe_option_vec)] pub permission_overwrites: Option>>>, pub permissions: Option, pub position: Option, pub rate_limit_per_user: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] - #[observe_option_vec] + #[cfg_attr(feature = "client", observe_option_vec)] pub recipients: Option>>>, pub rtc_region: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] @@ -126,9 +133,8 @@ pub struct Tag { pub emoji_name: Option, } -#[derive( - Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Updateable, Composite, -)] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd)] +#[cfg_attr(feature = "client", derive(Updateable, Composite))] pub struct PermissionOverwrite { pub id: Snowflake, #[serde(rename = "type")] diff --git a/src/types/entities/emoji.rs b/src/types/entities/emoji.rs index d80e487..51f78fb 100644 --- a/src/types/entities/emoji.rs +++ b/src/types/entities/emoji.rs @@ -1,14 +1,22 @@ use std::fmt::Debug; use std::sync::{Arc, RwLock}; -use chorus_macros::{Composite, Updateable}; use serde::{Deserialize, Serialize}; -use crate::gateway::{GatewayHandle, Updateable}; use crate::types::entities::User; -use crate::types::{Composite, Snowflake}; +use crate::types::Snowflake; -#[derive(Debug, Clone, Deserialize, Serialize, Default, Updateable, Composite)] +#[cfg(feature = "client")] +use crate::types::Composite; + +#[cfg(feature = "client")] +use crate::gateway::{GatewayHandle, Updateable}; + +#[cfg(feature = "client")] +use chorus_macros::{Composite, Updateable}; + +#[derive(Debug, Clone, Deserialize, Serialize, Default)] +#[cfg_attr(feature = "client", derive(Updateable, Composite))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] /// # Reference /// See diff --git a/src/types/entities/guild.rs b/src/types/entities/guild.rs index 93b13fc..d810aea 100644 --- a/src/types/entities/guild.rs +++ b/src/types/entities/guild.rs @@ -1,25 +1,32 @@ use std::fmt::Debug; use std::sync::{Arc, RwLock}; -use chorus_macros::{observe_option_vec, observe_vec, Composite, Updateable}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; -use crate::gateway::{GatewayHandle, Updateable}; use crate::types::types::guild_configuration::GuildFeaturesList; use crate::types::{ entities::{Channel, Emoji, RoleObject, Sticker, User, VoiceState, Webhook}, interfaces::WelcomeScreenObject, utils::Snowflake, - Composite, }; use bitflags::bitflags; use super::PublicUser; +#[cfg(feature = "client")] +use crate::gateway::{GatewayHandle, Updateable}; + +#[cfg(feature = "client")] +use chorus_macros::{observe_option_vec, observe_vec, Composite, Updateable}; + +#[cfg(feature = "client")] +use crate::types::Composite; + /// See -#[derive(Serialize, Deserialize, Debug, Default, Clone, Updateable, Composite)] +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +#[cfg_attr(feature = "client", derive(Updateable, Composite))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] pub struct Guild { pub afk_channel_id: Option, @@ -34,14 +41,14 @@ pub struct Guild { #[cfg_attr(feature = "sqlx", sqlx(skip))] pub bans: Option>, #[cfg_attr(feature = "sqlx", sqlx(skip))] - #[observe_option_vec] + #[cfg_attr(feature = "client", observe_option_vec)] pub channels: Option>>>, pub default_message_notifications: Option, pub description: Option, pub discovery_splash: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] + #[cfg_attr(feature = "client", observe_vec)] #[serde(default)] - #[observe_vec] pub emojis: Vec>>, pub explicit_content_filter: Option, //#[cfg_attr(feature = "sqlx", sqlx(try_from = "String"))] @@ -77,7 +84,7 @@ pub struct Guild { pub public_updates_channel_id: Option, pub region: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] - #[observe_option_vec] + #[cfg_attr(feature = "client", observe_option_vec)] pub roles: Option>>>, #[cfg_attr(feature = "sqlx", sqlx(skip))] pub rules_channel: Option, @@ -91,10 +98,10 @@ pub struct Guild { pub vanity_url_code: Option, pub verification_level: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] - #[observe_option_vec] + #[cfg_attr(feature = "client", observe_option_vec)] pub voice_states: Option>>>, #[cfg_attr(feature = "sqlx", sqlx(skip))] - #[observe_option_vec] + #[cfg_attr(feature = "client", observe_option_vec)] pub webhooks: Option>>>, #[cfg(feature = "sqlx")] pub welcome_screen: Option>, diff --git a/src/types/entities/mod.rs b/src/types/entities/mod.rs index abdf976..a14ef2c 100644 --- a/src/types/entities/mod.rs +++ b/src/types/entities/mod.rs @@ -10,6 +10,7 @@ pub use guild_member::*; pub use integration::*; pub use invite::*; pub use message::*; +pub use ratelimits::*; pub use relationship::*; pub use role::*; pub use security_key::*; @@ -22,9 +23,16 @@ pub use user_settings::*; pub use voice_state::*; pub use webhook::*; +#[cfg(feature = "client")] use crate::gateway::{GatewayHandle, Updateable}; + +#[cfg(feature = "client")] use async_trait::async_trait; + +#[cfg(feature = "client")] use std::fmt::Debug; + +#[cfg(feature = "client")] use std::sync::{Arc, RwLock}; mod application; @@ -39,6 +47,7 @@ mod guild_member; mod integration; mod invite; mod message; +mod ratelimits; mod relationship; mod role; mod security_key; @@ -51,6 +60,7 @@ mod user_settings; mod voice_state; mod webhook; +#[cfg(feature = "client")] #[async_trait(?Send)] pub trait Composite { async fn watch_whole(self, gateway: &GatewayHandle) -> Self; diff --git a/src/api/policies/instance/ratelimits.rs b/src/types/entities/ratelimits.rs similarity index 100% rename from src/api/policies/instance/ratelimits.rs rename to src/types/entities/ratelimits.rs diff --git a/src/types/entities/role.rs b/src/types/entities/role.rs index 22dceff..087a775 100644 --- a/src/types/entities/role.rs +++ b/src/types/entities/role.rs @@ -1,13 +1,21 @@ use bitflags::bitflags; -use chorus_macros::{Composite, Updateable}; use serde::{Deserialize, Serialize}; use serde_aux::prelude::{deserialize_option_number_from_string, deserialize_string_from_number}; use std::fmt::Debug; -use crate::gateway::{GatewayHandle, Updateable}; -use crate::types::{utils::Snowflake, Composite}; +use crate::types::utils::Snowflake; -#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Updateable, Composite)] +#[cfg(feature = "client")] +use chorus_macros::{Composite, Updateable}; + +#[cfg(feature = "client")] +use crate::gateway::{GatewayHandle, Updateable}; + +#[cfg(feature = "client")] +use crate::types::Composite; + +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] +#[cfg_attr(feature = "client", derive(Updateable, Composite))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] /// See pub struct RoleObject { diff --git a/src/types/entities/user.rs b/src/types/entities/user.rs index 64334ff..81d737a 100644 --- a/src/types/entities/user.rs +++ b/src/types/entities/user.rs @@ -1,11 +1,17 @@ -use chorus_macros::{Composite, Updateable}; +use crate::types::utils::Snowflake; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_aux::prelude::deserialize_option_number_from_string; use std::fmt::Debug; +#[cfg(feature = "client")] use crate::gateway::{GatewayHandle, Updateable}; -use crate::types::{utils::Snowflake, Composite}; + +#[cfg(feature = "client")] +use crate::types::Composite; + +#[cfg(feature = "client")] +use chorus_macros::{Composite, Updateable}; use super::Emoji; @@ -21,7 +27,8 @@ impl User { PublicUser::from(self) } } -#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, Updateable, Composite)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "client", derive(Updateable, Composite))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] pub struct User { pub id: Snowflake, diff --git a/src/types/entities/user_settings.rs b/src/types/entities/user_settings.rs index 1be2c0a..e6db7e7 100644 --- a/src/types/entities/user_settings.rs +++ b/src/types/entities/user_settings.rs @@ -53,15 +53,17 @@ pub struct UserSettings { pub friend_source_flags: sqlx::types::Json, #[cfg(not(feature = "sqlx"))] pub friend_source_flags: FriendSourceFlags, - pub gateway_connected: bool, + pub gateway_connected: Option, pub gif_auto_play: bool, #[cfg(feature = "sqlx")] pub guild_folders: sqlx::types::Json>, #[cfg(not(feature = "sqlx"))] pub guild_folders: Vec, #[cfg(feature = "sqlx")] + #[serde(default)] pub guild_positions: sqlx::types::Json>, #[cfg(not(feature = "sqlx"))] + #[serde(default)] pub guild_positions: Vec, pub inline_attachment_media: bool, pub inline_embed_media: bool, @@ -98,7 +100,7 @@ impl Default for UserSettings { enable_tts_command: false, explicit_content_filter: 0, friend_source_flags: Default::default(), - gateway_connected: false, + gateway_connected: Some(false), gif_auto_play: false, guild_folders: Default::default(), guild_positions: Default::default(), diff --git a/src/types/entities/voice_state.rs b/src/types/entities/voice_state.rs index c879c8e..e764296 100644 --- a/src/types/entities/voice_state.rs +++ b/src/types/entities/voice_state.rs @@ -1,20 +1,27 @@ use std::sync::{Arc, RwLock}; +#[cfg(feature = "client")] use chorus_macros::{Composite, Updateable}; + +#[cfg(feature = "client")] +use crate::types::Composite; + +#[cfg(feature = "client")] +use crate::gateway::{GatewayHandle, Updateable}; + use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::fmt::Debug; -use crate::gateway::{GatewayHandle, Updateable}; use crate::types::{ entities::{Guild, GuildMember}, utils::Snowflake, - Composite, }; /// See -#[derive(Serialize, Deserialize, Debug, Default, Clone, Updateable, Composite)] +#[derive(Serialize, Deserialize, Debug, Default, Clone)] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] +#[cfg_attr(feature = "client", derive(Updateable, Composite))] pub struct VoiceState { pub guild_id: Option, pub guild: Option, diff --git a/src/types/entities/webhook.rs b/src/types/entities/webhook.rs index 7771dbf..b544ec9 100644 --- a/src/types/entities/webhook.rs +++ b/src/types/entities/webhook.rs @@ -1,18 +1,25 @@ use std::fmt::Debug; use std::sync::{Arc, RwLock}; -use chorus_macros::{Composite, Updateable}; use serde::{Deserialize, Serialize}; +#[cfg(feature = "client")] use crate::gateway::{GatewayHandle, Updateable}; + +#[cfg(feature = "client")] +use chorus_macros::{Composite, Updateable}; + +#[cfg(feature = "client")] +use crate::types::Composite; + use crate::types::{ entities::{Guild, User}, utils::Snowflake, - Composite, }; /// See -#[derive(Serialize, Deserialize, Debug, Default, Clone, Updateable, Composite)] +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +#[cfg_attr(feature = "client", derive(Updateable, Composite))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] pub struct Webhook { pub id: Snowflake, diff --git a/src/types/events/auto_moderation.rs b/src/types/events/auto_moderation.rs index 376e523..2764ebf 100644 --- a/src/types/events/auto_moderation.rs +++ b/src/types/events/auto_moderation.rs @@ -7,6 +7,7 @@ use crate::types::{ WebSocketEvent, }; +#[cfg(feature = "client")] use super::UpdateMessage; #[derive(Debug, Deserialize, Serialize, Default, Clone)] @@ -27,6 +28,7 @@ pub struct AutoModerationRuleUpdate { pub json: String, } +#[cfg(feature = "client")] impl UpdateMessage for AutoModerationRuleUpdate { fn id(&self) -> Option { Some(self.rule.id) diff --git a/src/types/events/channel.rs b/src/types/events/channel.rs index ae84b79..6156c33 100644 --- a/src/types/events/channel.rs +++ b/src/types/events/channel.rs @@ -1,14 +1,18 @@ -use std::sync::{Arc, RwLock}; - use crate::types::events::WebSocketEvent; -use crate::types::Guild; use crate::types::{entities::Channel, JsonField, Snowflake}; use chorus_macros::JsonField; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; +#[cfg(feature = "client")] use super::UpdateMessage; +#[cfg(feature = "client")] +use std::sync::{Arc, RwLock}; + +#[cfg(feature = "client")] +use crate::types::Guild; + #[derive(Debug, Default, Deserialize, Serialize)] /// See pub struct ChannelPinsUpdate { @@ -30,6 +34,7 @@ pub struct ChannelCreate { impl WebSocketEvent for ChannelCreate {} +#[cfg(feature = "client")] impl UpdateMessage for ChannelCreate { fn id(&self) -> Option { self.channel.guild_id @@ -57,6 +62,7 @@ pub struct ChannelUpdate { impl WebSocketEvent for ChannelUpdate {} +#[cfg(feature = "client")] impl UpdateMessage for ChannelUpdate { fn update(&mut self, object_to_update: Arc>) { let mut write = object_to_update.write().unwrap(); @@ -96,6 +102,7 @@ pub struct ChannelDelete { pub json: String, } +#[cfg(feature = "client")] impl UpdateMessage for ChannelDelete { fn id(&self) -> Option { self.channel.guild_id diff --git a/src/types/events/guild.rs b/src/types/events/guild.rs index 0afa9d6..8225961 100644 --- a/src/types/events/guild.rs +++ b/src/types/events/guild.rs @@ -1,5 +1,3 @@ -use std::sync::{Arc, RwLock}; - use chorus_macros::JsonField; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; @@ -11,7 +9,12 @@ use crate::types::{ Sticker, }; -use super::{PresenceUpdate, UpdateMessage}; +use super::PresenceUpdate; + +#[cfg(feature = "client")] +use super::UpdateMessage; +#[cfg(feature = "client")] +use std::sync::{Arc, RwLock}; #[derive(Debug, Deserialize, Serialize, Default, Clone)] /// See ; @@ -179,6 +182,7 @@ pub struct GuildRoleCreate { impl WebSocketEvent for GuildRoleCreate {} +#[cfg(feature = "client")] impl UpdateMessage for GuildRoleCreate { fn id(&self) -> Option { Some(self.guild_id) @@ -209,6 +213,7 @@ pub struct GuildRoleUpdate { impl WebSocketEvent for GuildRoleUpdate {} +#[cfg(feature = "client")] impl UpdateMessage for GuildRoleUpdate { fn id(&self) -> Option { Some(self.role.id) diff --git a/src/types/events/mod.rs b/src/types/events/mod.rs index e440c05..4e213a1 100644 --- a/src/types/events/mod.rs +++ b/src/types/events/mod.rs @@ -1,12 +1,5 @@ -use std::sync::{Arc, RwLock}; - -use std::collections::HashMap; - -use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; -use serde_json::{from_str, from_value, to_value, Value}; - pub use application::*; pub use auto_moderation::*; pub use call::*; @@ -34,9 +27,23 @@ pub use voice::*; pub use webhooks::*; pub use webrtc::*; +#[cfg(feature = "client")] +use super::Snowflake; + +#[cfg(feature = "client")] use crate::gateway::Updateable; -use super::Snowflake; +#[cfg(feature = "client")] +use serde_json::{from_str, from_value, to_value, Value}; + +#[cfg(feature = "client")] +use std::collections::HashMap; + +#[cfg(feature = "client")] +use std::sync::{Arc, RwLock}; + +#[cfg(feature = "client")] +use serde::de::DeserializeOwned; mod application; mod auto_moderation; @@ -107,6 +114,7 @@ pub struct GatewayReceivePayload<'a> { impl<'a> WebSocketEvent for GatewayReceivePayload<'a> {} +#[cfg(feature = "client")] /// An [`UpdateMessage`] represents a received Gateway Message which contains updated /// information for an [`Updateable`] of Type T. /// # Example: @@ -134,6 +142,7 @@ pub(crate) trait JsonField: Clone { fn get_json(&self) -> String; } +#[cfg(feature = "client")] /// Only applicable for events where the Update struct is the same as the Entity struct pub(crate) fn update_object( value: String, diff --git a/src/types/events/thread.rs b/src/types/events/thread.rs index 19f1cde..5995c19 100644 --- a/src/types/events/thread.rs +++ b/src/types/events/thread.rs @@ -5,6 +5,7 @@ use crate::types::entities::{Channel, ThreadMember}; use crate::types::events::WebSocketEvent; use crate::types::{JsonField, Snowflake}; +#[cfg(feature = "client")] use super::UpdateMessage; #[derive(Debug, Default, Deserialize, Serialize, Clone)] @@ -27,6 +28,7 @@ pub struct ThreadUpdate { impl WebSocketEvent for ThreadUpdate {} +#[cfg(feature = "client")] impl UpdateMessage for ThreadUpdate { fn id(&self) -> Option { Some(self.thread.id)