diff --git a/src/lib.rs b/src/lib.rs index 7767480..bfa6bd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,6 +139,27 @@ pub mod types; ))] pub mod voice; +#[cfg(not(feature = "sqlx"))] +pub type UInt128 = u128; +#[cfg(feature = "sqlx")] +pub type UInt128 = sqlx_pg_uint::PgU128; +#[cfg(not(feature = "sqlx"))] +pub type UInt64 = u64; +#[cfg(feature = "sqlx")] +pub type UInt64 = sqlx_pg_uint::PgU64; +#[cfg(not(feature = "sqlx"))] +pub type UInt32 = u32; +#[cfg(feature = "sqlx")] +pub type UInt32 = sqlx_pg_uint::PgU32; +#[cfg(not(feature = "sqlx"))] +pub type UInt16 = u16; +#[cfg(feature = "sqlx")] +pub type UInt16 = sqlx_pg_uint::PgU16; +#[cfg(not(feature = "sqlx"))] +pub type UInt8 = u8; +#[cfg(feature = "sqlx")] +pub type UInt8 = sqlx_pg_uint::PgU8; + #[derive(Clone, Default, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] /// A URLBundle bundles together the API-, Gateway- and CDN-URLs of a Spacebar instance. /// diff --git a/src/types/entities/attachment.rs b/src/types/entities/attachment.rs index 6ca17b6..acd0d62 100644 --- a/src/types/entities/attachment.rs +++ b/src/types/entities/attachment.rs @@ -3,10 +3,9 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use serde::{Deserialize, Serialize}; -#[cfg(feature = "sqlx")] -use sqlx_pg_uint::PgU64; use crate::types::utils::Snowflake; +use crate::UInt64; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, PartialOrd)] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] @@ -18,20 +17,11 @@ pub struct Attachment { /// Max 1024 characters pub description: Option, pub content_type: Option, - #[cfg(not(feature = "sqlx"))] - pub size: u64, - #[cfg(feature = "sqlx")] - pub size: PgU64, + pub size: UInt64, pub url: String, pub proxy_url: String, - #[cfg(not(feature = "sqlx"))] - pub height: Option, - #[cfg(feature = "sqlx")] - pub height: Option, - #[cfg(not(feature = "sqlx"))] - pub width: Option, - #[cfg(feature = "sqlx")] - pub width: Option, + pub height: Option, + pub width: Option, pub ephemeral: Option, /// The duration of the audio file (only for voice messages) pub duration_secs: Option, @@ -48,18 +38,12 @@ pub struct Attachment { #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct PartialDiscordFileAttachment { - #[cfg(not(feature = "sqlx"))] - pub id: Option, - #[cfg(feature = "sqlx")] - pub id: Option, + pub id: Option, pub filename: String, /// Max 1024 characters pub description: Option, pub content_type: Option, - #[cfg(not(feature = "sqlx"))] - pub size: Option, - #[cfg(feature = "sqlx")] - pub size: Option, + pub size: Option, pub url: Option, pub proxy_url: Option, pub height: Option, diff --git a/src/types/entities/audit_log.rs b/src/types/entities/audit_log.rs index 4d8f7bb..97676d3 100644 --- a/src/types/entities/audit_log.rs +++ b/src/types/entities/audit_log.rs @@ -7,13 +7,12 @@ use super::option_vec_arc_rwlock_ptr_eq; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; -#[cfg(feature = "sqlx")] -use sqlx_pg_uint::PgU64; use crate::types::utils::Snowflake; use crate::types::{ AutoModerationRuleTriggerType, IntegrationType, PermissionOverwriteType, Shared, }; +use crate::UInt64; #[derive(Serialize, Deserialize, Debug, Default, Clone)] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] @@ -254,28 +253,16 @@ pub struct AuditEntryInfo { pub auto_moderation_rule_trigger_type: Option, pub channel_id: Option, // #[serde(option_string)] - #[cfg(not(feature = "sqlx"))] - pub count: Option, - #[cfg(feature = "sqlx")] - pub count: Option, + pub count: Option, // #[serde(option_string)] - #[cfg(not(feature = "sqlx"))] - pub delete_member_days: Option, - #[cfg(feature = "sqlx")] - pub delete_member_days: Option, + pub delete_member_days: Option, /// The ID of the overwritten entity pub id: Option, pub integration_type: Option, // #[serde(option_string)] - #[cfg(not(feature = "sqlx"))] - pub members_removed: Option, - #[cfg(feature = "sqlx")] - pub members_removed: Option, + pub members_removed: Option, // #[serde(option_string)] - #[cfg(not(feature = "sqlx"))] - pub message_id: Option, - #[cfg(feature = "sqlx")] - pub message_id: Option, + pub message_id: Option, pub role_name: Option, #[serde(rename = "type")] pub overwrite_type: Option, diff --git a/src/types/entities/auto_moderation.rs b/src/types/entities/auto_moderation.rs index 5606e33..748edbe 100644 --- a/src/types/entities/auto_moderation.rs +++ b/src/types/entities/auto_moderation.rs @@ -5,6 +5,7 @@ #[cfg(feature = "client")] use crate::gateway::Updateable; use crate::types::Shared; +use crate::UInt8; #[cfg(feature = "client")] use chorus_macros::Updateable; @@ -86,10 +87,7 @@ pub struct AutoModerationRuleTriggerMetadataForKeywordPreset { /// See pub struct AutoModerationRuleTriggerMetadataForMentionSpam { /// Max 50 - #[cfg(not(feature = "sqlx"))] - pub mention_total_limit: u8, - #[cfg(feature = "sqlx")] - pub mention_total_limit: sqlx_pg_uint::PgU8, + pub mention_total_limit: UInt8, pub mention_raid_protection_enabled: bool, } diff --git a/src/types/entities/channel.rs b/src/types/entities/channel.rs index b2cfde1..df30153 100644 --- a/src/types/entities/channel.rs +++ b/src/types/entities/channel.rs @@ -22,6 +22,7 @@ use crate::gateway::GatewayHandle; #[cfg(feature = "client")] use crate::gateway::Updateable; +use crate::UInt64; #[cfg(feature = "client")] use chorus_macros::{observe_option_vec, Composite, Updateable}; @@ -296,10 +297,7 @@ pub struct ThreadMember { pub id: Option, pub user_id: Option, pub join_timestamp: Option>, - #[cfg(not(feature = "sqlx"))] - pub flags: Option, - #[cfg(feature = "sqlx")] - pub flags: Option, + pub flags: Option, pub member: Option>, } diff --git a/src/types/entities/guild.rs b/src/types/entities/guild.rs index c958c55..423339a 100644 --- a/src/types/entities/guild.rs +++ b/src/types/entities/guild.rs @@ -17,6 +17,7 @@ use crate::types::{ interfaces::WelcomeScreenObject, utils::Snowflake, }; +use crate::UInt64; use super::{option_arc_rwlock_ptr_eq, vec_arc_rwlock_ptr_eq, PublicUser}; @@ -273,10 +274,7 @@ pub struct GuildScheduledEvent { pub entity_id: Option, pub entity_metadata: Option, pub creator: Option>, - #[cfg(not(feature = "sqlx"))] - pub user_count: Option, - #[cfg(feature = "sqlx")] - pub user_count: Option, + pub user_count: Option, pub image: Option, } diff --git a/src/types/entities/integration.rs b/src/types/entities/integration.rs index 96527fc..50a8281 100644 --- a/src/types/entities/integration.rs +++ b/src/types/entities/integration.rs @@ -10,6 +10,7 @@ use crate::types::{ utils::Snowflake, Shared, }; +use crate::{UInt16, UInt8}; #[derive(Default, Debug, Deserialize, Serialize, Clone)] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] @@ -23,14 +24,8 @@ pub struct Integration { pub syncing: Option, pub role_id: Option, pub enabled_emoticons: Option, - #[cfg(not(feature = "sqlx"))] - pub expire_behaviour: Option, - #[cfg(feature = "sqlx")] - pub expire_behaviour: Option, - #[cfg(not(feature = "sqlx"))] - pub expire_grace_period: Option, - #[cfg(feature = "sqlx")] - pub expire_grace_period: Option, + pub expire_behaviour: Option, + pub expire_grace_period: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] pub user: Option>, #[cfg_attr(feature = "sqlx", sqlx(skip))] diff --git a/src/types/entities/invite.rs b/src/types/entities/invite.rs index 52180d8..40f5e72 100644 --- a/src/types/entities/invite.rs +++ b/src/types/entities/invite.rs @@ -10,6 +10,7 @@ use crate::types::{ Guild, InviteFlags, InviteTargetType, InviteType, Shared, Snowflake, VerificationLevel, WelcomeScreenObject, }; +use crate::{UInt32, UInt8}; use super::guild::GuildScheduledEvent; use super::{Application, Channel, GuildMember, NSFWLevel, User}; @@ -39,14 +40,8 @@ pub struct Invite { pub invite_type: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] pub inviter: Option, - #[cfg(not(feature = "sqlx"))] - pub max_age: Option, - #[cfg(feature = "sqlx")] - pub max_age: Option, - #[cfg(not(feature = "sqlx"))] - pub max_uses: Option, - #[cfg(feature = "sqlx")] - pub max_uses: Option, + pub max_age: Option, + pub max_uses: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] pub stage_instance: Option, #[cfg_attr(feature = "sqlx", sqlx(skip))] @@ -56,10 +51,7 @@ pub struct Invite { #[cfg_attr(feature = "sqlx", sqlx(skip))] pub target_user: Option, pub temporary: Option, - #[cfg(not(feature = "sqlx"))] - pub uses: Option, - #[cfg(feature = "sqlx")] - pub uses: Option, + pub uses: Option, } /// The guild an invite is for. diff --git a/src/types/entities/message.rs b/src/types/entities/message.rs index eea9288..b63eb3b 100644 --- a/src/types/entities/message.rs +++ b/src/types/entities/message.rs @@ -15,6 +15,7 @@ use crate::types::{ utils::Snowflake, Shared, }; +use crate::{UInt32, UInt8}; use super::option_arc_rwlock_ptr_eq; @@ -150,10 +151,7 @@ pub enum MessageReferenceType { pub struct MessageInteraction { pub id: Snowflake, #[serde(rename = "type")] - #[cfg(not(feature = "sqlx"))] - pub interaction_type: u8, - #[cfg(feature = "sqlx")] - pub interaction_type: sqlx_pg_uint::PgU8, + pub interaction_type: UInt8, pub name: String, pub user: User, pub member: Option>, @@ -285,14 +283,8 @@ pub struct EmbedField { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct Reaction { - #[cfg(not(feature = "sqlx"))] - pub count: u32, - #[cfg(feature = "sqlx")] - pub count: sqlx_pg_uint::PgU32, - #[cfg(not(feature = "sqlx"))] - pub burst_count: u32, - #[cfg(feature = "sqlx")] - pub burst_count: sqlx_pg_uint::PgU32, + pub count: UInt32, + pub burst_count: UInt32, #[serde(default)] pub me: bool, #[serde(default)] diff --git a/src/types/entities/role.rs b/src/types/entities/role.rs index a19a966..8c2322c 100644 --- a/src/types/entities/role.rs +++ b/src/types/entities/role.rs @@ -8,6 +8,7 @@ use serde_aux::prelude::deserialize_option_number_from_string; use std::fmt::Debug; use crate::types::utils::Snowflake; +use crate::{UInt16, UInt32}; #[cfg(feature = "client")] use chorus_macros::{Composite, Updateable}; @@ -32,10 +33,7 @@ pub struct RoleObject { pub hoist: bool, pub icon: Option, pub unicode_emoji: Option, - #[cfg(not(feature = "sqlx"))] - pub position: u16, - #[cfg(feature = "sqlx")] - pub position: sqlx_pg_uint::PgU16, + pub position: UInt16, #[serde(default)] pub permissions: PermissionFlags, pub managed: bool, @@ -50,10 +48,7 @@ pub struct RoleObject { pub struct RoleSubscriptionData { pub role_subscription_listing_id: Snowflake, pub tier_name: String, - #[cfg(not(feature = "sqlx"))] - pub total_months_subscribed: u32, - #[cfg(feature = "sqlx")] - pub total_months_subscribed: sqlx_pg_uint::PgU32, + pub total_months_subscribed: UInt32, pub is_renewal: bool, } diff --git a/src/types/entities/security_key.rs b/src/types/entities/security_key.rs index 3af45d1..412c202 100644 --- a/src/types/entities/security_key.rs +++ b/src/types/entities/security_key.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::types::utils::Snowflake; +use crate::UInt64; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] @@ -13,10 +14,7 @@ pub struct SecurityKey { pub user_id: String, pub key_id: String, pub public_key: String, - #[cfg(not(feature = "sqlx"))] - pub counter: u64, - #[cfg(feature = "sqlx")] - pub counter: sqlx_pg_uint::PgU64, + pub counter: UInt64, pub name: String, } @@ -27,10 +25,7 @@ impl Default for SecurityKey { user_id: String::new(), key_id: String::new(), public_key: String::new(), - #[cfg(not(feature = "sqlx"))] - counter: 0, - #[cfg(feature = "sqlx")] - counter: sqlx_pg_uint::PgU64::from(0), + counter: 0.into(), name: String::new(), } } diff --git a/src/types/entities/team.rs b/src/types/entities/team.rs index a6cfd95..8c36e0e 100644 --- a/src/types/entities/team.rs +++ b/src/types/entities/team.rs @@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize}; use crate::types::entities::User; use crate::types::Shared; use crate::types::Snowflake; +use crate::UInt8; use super::arc_rwlock_ptr_eq; @@ -34,10 +35,7 @@ impl PartialEq for Team { #[derive(Debug, Deserialize, Serialize, Clone)] pub struct TeamMember { - #[cfg(not(feature = "sqlx"))] - pub membership_state: u8, - #[cfg(feature = "sqlx")] - pub membership_state: sqlx_pg_uint::PgU8, + pub membership_state: UInt8, pub permissions: Vec, pub team_id: Snowflake, pub user: Shared, diff --git a/src/types/entities/template.rs b/src/types/entities/template.rs index dca74b2..29e5368 100644 --- a/src/types/entities/template.rs +++ b/src/types/entities/template.rs @@ -10,6 +10,7 @@ use crate::types::{ utils::Snowflake, Shared, }; +use crate::UInt64; /// See #[derive(Serialize, Deserialize, Debug, Default, Clone)] @@ -18,10 +19,7 @@ pub struct GuildTemplate { pub code: String, pub name: String, pub description: Option, - #[cfg(not(feature = "sqlx"))] - pub usage_count: Option, - #[cfg(feature = "sqlx")] - pub usage_count: Option, + pub usage_count: Option, pub creator_id: Snowflake, #[cfg_attr(feature = "sqlx", sqlx(skip))] pub creator: Shared, diff --git a/src/types/entities/user.rs b/src/types/entities/user.rs index f2a5bfa..866d66c 100644 --- a/src/types/entities/user.rs +++ b/src/types/entities/user.rs @@ -4,6 +4,7 @@ use crate::errors::ChorusError; use crate::types::utils::Snowflake; +use crate::{UInt32, UInt8}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_aux::prelude::deserialize_option_number_from_string; @@ -47,10 +48,7 @@ pub struct User { pub bot: Option, pub system: Option, pub mfa_enabled: Option, - #[cfg(not(feature = "sqlx"))] - pub accent_color: Option, - #[cfg(feature = "sqlx")] - pub accent_color: Option, + pub accent_color: Option, #[cfg_attr(feature = "sqlx", sqlx(default))] pub locale: Option, pub verified: Option, @@ -61,10 +59,7 @@ pub struct User { #[serde(deserialize_with = "deserialize_option_number_from_string")] pub flags: Option, pub premium_since: Option>, - #[cfg(not(feature = "sqlx"))] - pub premium_type: Option, - #[cfg(feature = "sqlx")] - pub premium_type: Option, + pub premium_type: Option, pub pronouns: Option, pub public_flags: Option, pub banner: Option, @@ -150,19 +145,13 @@ pub struct PublicUser { pub username: Option, pub discriminator: Option, pub avatar: Option, - #[cfg(not(feature = "sqlx"))] - pub accent_color: Option, - #[cfg(feature = "sqlx")] - pub accent_color: Option, + pub accent_color: Option, pub banner: Option, pub theme_colors: Option, pub pronouns: Option, pub bot: Option, pub bio: Option, - #[cfg(not(feature = "sqlx"))] - pub premium_type: Option, - #[cfg(feature = "sqlx")] - pub premium_type: Option, + pub premium_type: Option, pub premium_since: Option>, pub public_flags: Option, } diff --git a/src/types/entities/user_settings.rs b/src/types/entities/user_settings.rs index 244e361..523075f 100644 --- a/src/types/entities/user_settings.rs +++ b/src/types/entities/user_settings.rs @@ -6,6 +6,7 @@ use chrono::{serde::ts_milliseconds_option, Utc}; use serde::{Deserialize, Serialize}; use crate::types::Shared; +use crate::{UInt16, UInt32, UInt8}; use serde_aux::field_attributes::deserialize_option_number_from_string; #[derive( @@ -42,16 +43,10 @@ pub enum UserTheme { #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] pub struct UserSettings { - #[cfg(not(feature = "sqlx"))] - pub afk_timeout: Option, - #[cfg(feature = "sqlx")] - pub afk_timeout: Option, + pub afk_timeout: Option, pub allow_accessibility_detection: bool, pub animate_emoji: bool, - #[cfg(not(feature = "sqlx"))] - pub animate_stickers: u8, - #[cfg(feature = "sqlx")] - pub animate_stickers: sqlx_pg_uint::PgU8, + pub animate_stickers: UInt8, pub contact_sync_enabled: bool, pub convert_emoticons: bool, pub custom_status: Option, @@ -60,10 +55,7 @@ pub struct UserSettings { pub developer_mode: bool, pub disable_games_tab: bool, pub enable_tts_command: bool, - #[cfg(not(feature = "sqlx"))] - pub explicit_content_filter: u8, - #[cfg(feature = "sqlx")] - pub explicit_content_filter: sqlx_pg_uint::PgU8, + pub explicit_content_filter: UInt8, pub friend_source_flags: FriendSourceFlags, pub gateway_connected: Option, pub gif_auto_play: bool, @@ -156,10 +148,7 @@ impl Default for FriendSourceFlags { #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow, sqlx::Type))] #[cfg_attr(feature = "sqlx", sqlx(type_name = "interface_type"))] pub struct GuildFolder { - #[cfg(not(feature = "sqlx"))] - pub color: Option, - #[cfg(feature = "sqlx")] - pub color: Option, + pub color: Option, pub guild_ids: Vec, // FIXME: What is this thing? // It's not a snowflake, and it's sometimes a string and sometimes an integer.