From 7c0c95690d87c19dd280857e56f4bae58229048e Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 14 May 2023 12:40:31 +0200 Subject: [PATCH] Add full Guild type --- src/api/types.rs | 177 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 151 insertions(+), 26 deletions(-) diff --git a/src/api/types.rs b/src/api/types.rs index b3f7081..ae3a8e7 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -137,7 +137,7 @@ pub struct Error { #[derive(Serialize, Deserialize, Debug, Default)] pub struct UnavailableGuild { id: String, - unavailable: bool + unavailable: bool, } /// See https://discord.com/developers/docs/resources/guild @@ -149,41 +149,71 @@ pub struct Guild { pub icon_hash: Option, pub splash: Option, pub discovery_splash: Option, - pub owner: Option, - pub owner_id: String, + pub owner: Option, + pub owner_id: Option, pub permissions: Option, pub afk_channel_id: Option, - pub afk_timeout: u8, + pub afk_timeout: Option, pub widget_enabled: Option, pub widget_channel_id: Option, - pub verification_level: u8, - pub default_message_notifications: u8, - pub explicit_content_filter: u8, + pub widget_channel: Option, + pub verification_level: Option, + pub default_message_notifications: Option, + pub explicit_content_filter: Option, pub roles: Vec, pub emojis: Vec, pub features: Vec, - pub mfa_level: u8, pub application_id: Option, pub system_channel_id: Option, - pub system_channel_flags: u8, + pub system_channel_flags: Option, pub rules_channel_id: Option, + pub rules_channel: Option, pub max_presences: Option, pub max_members: Option, pub vanity_url_code: Option, pub description: Option, pub banner: Option, - pub premium_tier: u8, + pub premium_tier: Option, pub premium_subscription_count: Option, - pub preferred_locale: String, + pub preferred_locale: Option, pub public_updates_channel_id: Option, + pub public_updates_channel: Option, pub max_video_channel_users: Option, pub max_stage_video_channel_users: Option, pub approximate_member_count: Option, pub approximate_presence_count: Option, + pub member_count: Option, + pub presence_count: Option, pub welcome_screen: Option, pub nsfw_level: u8, + pub nsfw: bool, pub stickers: Option>, - pub premium_progress_bar_enabled: bool + pub premium_progress_bar_enabled: Option, + pub joined_at: String, + pub afk_channel: Option, + pub bans: Option>, + pub primary_category_id: Option, + pub large: Option, + pub channels: Option>, + pub template_id: Option, + pub template: Option, + pub invites: Option>, + pub voice_states: Option>, + pub webhooks: Option>, + pub mfa_level: Option, + pub region: Option, + pub unavailable: bool, + pub parent: Option, +} + +/// See https://docs.spacebar.chat/routes/#get-/guilds/-guild_id-/bans/-user- +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +pub struct GuildBan { + pub id: String, + pub user_id: String, + pub guild_id: String, + pub executor_id: String, + pub reason: Option, } /// See https://discord.com/developers/docs/topics/gateway-events#guild-create-guild-create-extra-fields @@ -259,7 +289,7 @@ impl GuildCreateGuild { #[derive(Serialize, Deserialize, Debug, Default, Clone)] pub struct WelcomeScreenObject { pub description: Option, - pub welcome_channels: Vec + pub welcome_channels: Vec, } #[derive(Serialize, Deserialize, Debug, Default, Clone)] @@ -267,7 +297,7 @@ pub struct WelcomeScreenChannel { pub channel_id: String, pub description: String, pub emoji_id: Option, - pub emoji_name: Option + pub emoji_name: Option, } #[derive(Serialize, Deserialize, Debug, Default, Clone)] @@ -805,14 +835,14 @@ pub struct Integration { pub subscriber_count: Option, pub revoked: Option, pub application: Option, - pub scopes: Option> + pub scopes: Option>, } #[derive(Default, Debug, Deserialize, Serialize, Clone)] /// See https://discord.com/developers/docs/resources/guild#integration-account-object-integration-account-structure pub struct IntegrationAccount { pub id: String, - pub name: String + pub name: String, } #[derive(Default, Debug, Deserialize, Serialize, Clone)] @@ -830,7 +860,7 @@ pub struct VoiceStateObject { pub self_stream: Option, pub self_video: bool, pub suppress: bool, - pub request_to_speak_timestamp: DateTime + pub request_to_speak_timestamp: DateTime, } #[derive(Default, Debug, Deserialize, Serialize, Clone)] @@ -842,7 +872,7 @@ pub struct StageInstance { pub topic: String, pub privacy_level: u8, pub discoverable_disabled: bool, - pub guild_scheduled_event_id: Option + pub guild_scheduled_event_id: Option, } #[derive(Debug, Deserialize, Serialize, Clone)] @@ -933,7 +963,7 @@ pub struct PresenceUpdate { pub guild_id: String, pub status: String, pub activities: Vec, - pub client_status: ClientStatusObject + pub client_status: ClientStatusObject, } #[derive(Debug, Deserialize, Serialize, Default, Clone)] @@ -941,7 +971,7 @@ pub struct PresenceUpdate { pub struct ClientStatusObject { pub desktop: Option, pub mobile: Option, - pub web: Option + pub web: Option, } impl WebSocketEvent for PresenceUpdate {} @@ -1080,7 +1110,7 @@ impl WebSocketEvent for GatewayHeartbeatAck {} pub struct ChannelPinsUpdate { pub guild_id: Option, pub channel_id: String, - pub last_pin_timestamp: Option> + pub last_pin_timestamp: Option>, } impl WebSocketEvent for ChannelPinsUpdate {} @@ -1172,7 +1202,7 @@ pub struct ThreadListSync { pub guild_id: String, pub channel_ids: Option>, pub threads: Vec, - pub members: Vec + pub members: Vec, } impl WebSocketEvent for ThreadListSync {} @@ -1193,7 +1223,13 @@ pub struct ThreadMemberUpdate { impl ThreadMemberUpdate { /// Convert self to a thread member, losing the added guild_id field pub fn to_thread_member(&self) -> ThreadMember { - ThreadMember { id: self.id, user_id: self.user_id, join_timestamp: self.join_timestamp.clone(), flags: self.flags, member: self.member.clone() } + ThreadMember { + id: self.id, + user_id: self.user_id, + join_timestamp: self.join_timestamp.clone(), + flags: self.flags, + member: self.member.clone(), + } } } @@ -1207,7 +1243,7 @@ pub struct ThreadMembersUpdate { /// Capped at 50 pub member_count: u8, pub added_members: Option>, - pub removed_members: Option> + pub removed_members: Option>, } impl WebSocketEvent for ThreadMembersUpdate {} @@ -1216,13 +1252,13 @@ impl WebSocketEvent for ThreadMembersUpdate {} /// See https://discord.com/developers/docs/topics/gateway-events#guild-create /// This one is particularly painful, it can be a Guild object with extra field or an unavailbile guild object pub struct GuildCreate { - pub d: GuildCreateDataOption + pub d: GuildCreateDataOption, } #[derive(Debug, Deserialize, Serialize)] pub enum GuildCreateDataOption { UnavailableGuild(UnavailableGuild), - Guild(Guild) + Guild(Guild), } impl Default for GuildCreateDataOption { @@ -1317,6 +1353,7 @@ impl PartialDiscordFileAttachment { proxy_url: self.proxy_url, height: self.height, width: self.width, + ephemeral: self.ephemeral, duration_secs: self.duration_secs, waveform: self.waveform, @@ -1370,3 +1407,91 @@ pub enum AllowedMentionType { pub struct Token { pub token: String, } + +/// See https://docs.spacebar.chat/routes/#cmp--schemas-template +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +pub struct GuildTemplate { + pub code: String, + pub name: String, + pub description: Option, + pub usage_count: Option, + pub creator_id: String, + pub creator: UserObject, + pub created_at: DateTime, + pub updated_at: DateTime, + pub source_guild_id: String, + pub source_guild: Vec, // Unsure how a {recursive: Guild} looks like, might be a Vec? + pub serialized_source_guild: Vec, + id: String, +} + +/// See https://docs.spacebar.chat/routes/#cmp--schemas-invite +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +pub struct GuildInvite { + pub code: String, + pub temporary: Option, + pub uses: Option, + pub max_uses: Option, + pub max_age: Option, + pub created_at: DateTime, + pub expires_at: Option>, + pub guild_id: String, + pub guild: Option, + pub channel_id: String, + pub channel: Option, + pub inviter_id: Option, + pub inviter: Option, + pub target_user_id: Option, + pub target_user: Option, + pub target_user_type: Option, + pub vanity_url: Option, +} + +/// See https://docs.spacebar.chat/routes/#cmp--schemas-voicestate +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +pub struct VoiceState { + pub guild_id: String, + pub guild: Option, + pub channel_id: String, + pub channel: Option, + pub user_id: String, + pub user: Option, + pub member: Option, + pub session_id: String, + pub token: String, + pub deaf: bool, + pub mute: bool, + pub self_deaf: bool, + pub self_mute: bool, + pub self_stream: Option, + pub self_video: bool, + pub suppress: bool, + pub request_to_speak_timestamp: Option>, + pub id: String, +} + +/// See https://docs.spacebar.chat/routes/#cmp--schemas-webhook +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +pub struct Webhook { + #[serde(rename = "type")] + pub webhook_type: i32, + pub name: String, + pub avatar: String, + pub token: String, + pub guild_id: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub guild: Option, + pub channel_id: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub channel: Option, + pub application_id: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub application: Option, + pub user_id: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub user: Option, + pub source_guild_id: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub source_guild: Option, + pub id: String, +}