From 3e5e79929c4e6e6027d3c694839faad68b24a23a Mon Sep 17 00:00:00 2001 From: Quaternion Date: Sat, 27 May 2023 13:45:56 -0400 Subject: [PATCH 1/2] Add custom Default impl to Application --- src/types/entities/application.rs | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/types/entities/application.rs b/src/types/entities/application.rs index 9844e6d..5a85cf5 100644 --- a/src/types/entities/application.rs +++ b/src/types/entities/application.rs @@ -50,6 +50,40 @@ pub struct Application { pub team: Option, } +impl Default for Application { + fn default() -> Self { + Self { + id: Default::default(), + name: "".to_string(), + icon: None, + description: None, + summary: None, + r#type: None, + hook: true, + bot_public: true, + bot_require_code_grant: false, + verify_key: "".to_string(), + owner: Default::default(), + flags: 0, + redirect_uris: None, + rpc_application_state: 0, + store_application_state: 1, + verification_state: 1, + interactions_endpoint_url: None, + integration_public: true, + integration_require_code_grant: false, + discoverability_state: 1, + discovery_eligibility_flags: 2240, + tags: None, + cover_image: None, + install_params: None, + terms_of_service_url: None, + privacy_policy_url: None, + team: None, + } + } +} + impl Application { pub fn flags(&self) -> ApplicationFlags { ApplicationFlags::from_bits(self.flags.to_owned()).unwrap() From 1c55b90f0646fbd2099f16f513f0a100d263982b Mon Sep 17 00:00:00 2001 From: Quaternion Date: Sat, 27 May 2023 13:46:37 -0400 Subject: [PATCH 2/2] Hijack this to clean up ApplicationCommandOptionType with serde_repr --- src/types/entities/application.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/types/entities/application.rs b/src/types/entities/application.rs index 5a85cf5..615b8ee 100644 --- a/src/types/entities/application.rs +++ b/src/types/entities/application.rs @@ -3,6 +3,7 @@ use crate::types::{Team, User}; use bitflags::{bitflags, Flags}; use serde::{Deserialize, Serialize}; use serde_json::Value; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] @@ -137,23 +138,17 @@ pub struct ApplicationCommandOptionChoice { pub value: Value, } -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Serialize_repr, Deserialize_repr)] +#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] +#[repr(i32)] pub enum ApplicationCommandOptionType { - #[serde(rename = "SUB_COMMAND")] SubCommand = 1, - #[serde(rename = "SUB_COMMAND_GROUP")] SubCommandGroup = 2, - #[serde(rename = "STRING")] String = 3, - #[serde(rename = "INTEGER")] Integer = 4, - #[serde(rename = "BOOLEAN")] Boolean = 5, - #[serde(rename = "USER")] User = 6, - #[serde(rename = "CHANNEL")] Channel = 7, - #[serde(rename = "ROLE")] Role = 8, }