diff --git a/Cargo.toml b/Cargo.toml index 175e3e6..b441eb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,6 @@ reqwest = "0.11.16" url = "2.3.1" chrono = "0.4.24" regex = "1.7.3" -custom_error = "1.9.2" \ No newline at end of file +custom_error = "1.9.2" +native-tls = "0.2.11" +tokio-tungstenite = {version = "0.18.0", features = ["native-tls"]} \ No newline at end of file diff --git a/src/api/policies/instance/instance.rs b/src/api/policies/instance/instance.rs index f96325f..7c1a48a 100644 --- a/src/api/policies/instance/instance.rs +++ b/src/api/policies/instance/instance.rs @@ -56,6 +56,6 @@ mod instance_policies_schema_test { .unwrap(); let schema = test_instance.instance_policies_schema().await.unwrap(); - println!("{}", schema); + println!("{:?}", schema); } } diff --git a/src/api/types.rs b/src/api/types.rs index d4c8309..c50520f 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -1,3 +1,9 @@ +/* +To learn more about the types implemented here, please visit +https://discord.com/developers/docs . +I do not feel like re-documenting all of this, as everything is already perfectly explained there. + */ + use std::fmt; use serde::{Deserialize, Serialize}; @@ -101,23 +107,6 @@ impl InstancePolicies { } } -impl fmt::Display for InstancePolicies { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "InstancePoliciesSchema {{ instance_name: {}, instance_description: {}, front_page: {}, tos_page: {}, correspondence_email: {}, correspondence_user_id: {}, image: {}, instance_id: {} }}", - self.instance_name, - self.instance_description.clone().unwrap_or("None".to_string()), - self.front_page.clone().unwrap_or("None".to_string()), - self.tos_page.clone().unwrap_or("None".to_string()), - self.correspondence_email.clone().unwrap_or("None".to_string()), - self.correspondence_user_id.clone().unwrap_or("None".to_string()), - self.image.clone().unwrap_or("None".to_string()), - self.instance_id.clone().unwrap_or("None".to_string()), - ) - } -} - #[derive(Serialize, Deserialize, Debug)] pub struct ErrorResponse { pub code: i32, @@ -211,3 +200,578 @@ impl User { } } } + +#[derive(Debug, Serialize, Deserialize)] +struct Message { + id: String, + channel_id: String, + author: UserObject, + content: String, + timestamp: String, + edited_timestamp: Option, + tts: bool, + mention_everyone: bool, + mentions: Vec, + mention_roles: Vec, + mention_channels: Option>, + attachments: Vec, + embeds: Vec, + reactions: Option>, + nonce: Option, + pinned: bool, + webhook_id: Option, + #[serde(rename = "type")] + message_type: i32, + activity: Option, + application: Option, + application_id: Option, + message_reference: Option, + flags: Option, + referenced_message: Option>, + interaction: Option, + thread: Option, + components: Option>, + sticker_items: Option>, + stickers: Option>, + position: Option, + role_subscription_data: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageCreate { + #[serde(flatten)] + message: Message, + guild_id: Option, + member: Option, + mentions: Vec<(UserObject, GuildMember)>, // Not sure if this is correct: https://discord.com/developers/docs/topics/gateway-events#message-create +} + +#[derive(Debug, Serialize, Deserialize)] +struct PartialMessage { + id: Option, + channel_id: Option, + author: Option, + content: Option, + timestamp: Option, + edited_timestamp: Option, + tts: Option, + mention_everyone: Option, + mentions: Option>, + mention_roles: Option>, + mention_channels: Option>, + attachments: Option>, + embeds: Option>, + reactions: Option>, + nonce: Option, + pinned: Option, + webhook_id: Option, + #[serde(rename = "type")] + message_type: Option, + activity: Option, + application: Option, + application_id: Option, + message_reference: Option, + flags: Option, + referenced_message: Option>, + interaction: Option, + thread: Option, + components: Option>, + sticker_items: Option>, + stickers: Option>, + position: Option, + role_subscription_data: Option, + guild_id: Option, + member: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageUpdate { + #[serde(flatten)] + message: PartialMessage, + guild_id: Option, + member: Option, + mentions: Vec<(UserObject, GuildMember)>, // Not sure if this is correct: https://discord.com/developers/docs/topics/gateway-events#message-create +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageDelete { + id: String, + channel_id: String, + guild_id: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageDeleteBulk { + ids: Vec, + channel_id: String, + guild_id: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageReactionAdd { + user_id: String, + channel_id: String, + message_id: String, + guild_id: Option, + member: Option, + emoji: Emoji, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageReactionRemove { + user_id: String, + channel_id: String, + message_id: String, + guild_id: Option, + emoji: Emoji, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageReactionRemoveAll { + channel_id: String, + message_id: String, + guild_id: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageReactionRemoveEmoji { + channel_id: String, + message_id: String, + guild_id: Option, + emoji: Emoji, +} + +#[derive(Debug, Serialize, Deserialize)] +struct ChannelMention { + id: String, + guild_id: String, + #[serde(rename = "type")] + channel_type: i32, + name: String, +} + +#[derive(Debug, Serialize, Deserialize)] +struct Attachment { + id: String, + filename: String, + description: Option, + content_type: Option, + size: i64, + url: String, + proxy_url: String, + height: Option, + width: Option, + ephemeral: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +/** +Represents an Embed. [See the Discord Documentation](https://discord.com/developers/docs/resources/channel#embed-object). + */ +struct Embed { + title: Option, + #[serde(rename = "type")] + embed_type: Option, + description: Option, + url: Option, + timestamp: Option, + color: Option, + footer: Option, + image: Option, + thumbnail: Option, + video: Option, + provider: Option, + author: Option, + fields: Option>, +} + +#[derive(Debug, Serialize, Deserialize)] +struct EmbedFooter { + text: String, + icon_url: Option, + proxy_icon_url: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct EmbedImage { + url: String, + proxy_url: String, + height: Option, + width: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct EmbedThumbnail { + url: String, + proxy_url: Option, + height: Option, + width: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct EmbedVideo { + url: Option, + proxy_url: Option, + height: Option, + width: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct EmbedProvider { + name: Option, + url: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct EmbedAuthor { + name: String, + url: Option, + icon_url: Option, + proxy_icon_url: Option, +} + +#[derive(Debug, Serialize, Deserialize)] + +struct EmbedField { + name: String, + value: String, + inline: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct Reaction { + count: i32, + me: bool, + emoji: Emoji, +} + +#[derive(Debug, Deserialize, Serialize)] +struct Emoji { + id: Option, + name: Option, + roles: Option>, + user: Option, + require_colons: Option, + managed: Option, + animated: Option, + available: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageActivity { + #[serde(rename = "type")] + activity_type: i64, + party_id: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct Application { + id: String, + name: String, + icon: Option, + description: String, + rpc_origins: Option>, + bot_public: bool, + bot_require_code_grant: bool, + terms_of_service_url: Option, + privacy_policy_url: Option, + owner: Option, + summary: String, + verify_key: String, + team: Option, + guild_id: Option, + primary_sku_id: Option, + slug: Option, + cover_image: Option, + flags: Option, + tags: Option>, + install_params: Option, + custom_install_url: Option, + role_connections_verification_url: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct Team { + icon: Option, + id: u64, + members: Vec, + name: String, + owner_user_id: u64, +} + +#[derive(Debug, Deserialize, Serialize)] +struct TeamMember { + membership_state: u8, + permissions: Vec, + team_id: u64, + user: UserObject, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +enum MembershipState { + Invited = 1, + Accepted = 2, +} + +#[derive(Debug, Serialize, Deserialize)] +struct InstallParams { + scopes: Vec, + permissions: String, +} + +#[derive(Debug, Serialize, Deserialize)] +struct MessageReference { + message_id: Option, + channel_id: Option, + guild_id: Option, + fail_if_not_exists: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct MessageInteraction { + id: u64, + #[serde(rename = "type")] + interaction_type: u8, + name: String, + user: UserObject, + member: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct GuildMember { + user: Option, + nick: Option, + avatar: Option, + roles: Vec, + joined_at: String, + premium_since: Option, + deaf: bool, + mute: bool, + flags: i32, + pending: Option, + permissions: Option, + communication_disabled_until: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct Channel { + id: String, + #[serde(rename = "type")] + channel_type: i32, + guild_id: Option, + position: Option, + permission_overwrites: Option>, + name: Option, + topic: Option, + nsfw: Option, + last_message_id: Option, + bitrate: Option, + user_limit: Option, + rate_limit_per_user: Option, + recipients: Option>, + icon: Option, + owner_id: Option, + application_id: Option, + parent_id: Option, + last_pin_timestamp: Option, + rtc_region: Option, + video_quality_mode: Option, + message_count: Option, + member_count: Option, + thread_metadata: Option, + member: Option, + default_auto_archive_duration: Option, + permissions: Option, + flags: Option, + total_message_sent: Option, + available_tags: Option>, + applied_tags: Option>, + default_reaction_emoji: Option, + default_thread_rate_limit_per_user: Option, + default_sort_order: Option, + default_forum_layout: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct Tag { + id: u64, + name: String, + moderated: bool, + emoji_id: Option, + emoji_name: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct PermissionOverwrite { + id: String, + #[serde(rename = "type")] + overwrite_type: u8, + allow: String, + deny: String, +} + +#[derive(Debug, Deserialize, Serialize)] +struct ThreadMetadata { + archived: bool, + auto_archive_duration: i32, + archive_timestamp: String, + locked: bool, + invitable: Option, + create_timestamp: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct ThreadMember { + id: Option, + user_id: Option, + join_timestamp: Option, + flags: Option, + member: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct DefaultReaction { + emoji_id: Option, + emoji_name: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +enum Component { + ActionRow = 1, + Button = 2, + StringSelect = 3, + TextInput = 4, + UserSelect = 5, + RoleSelect = 6, + MentionableSelect = 7, + ChannelSelect = 8, +} + +#[derive(Debug, Serialize, Deserialize)] +struct StickerItem { + id: u64, + name: String, + format_type: u8, +} + +#[derive(Debug, Serialize, Deserialize)] +struct Sticker { + id: u64, + pack_id: Option, + name: String, + description: Option, + tags: String, + asset: Option, + #[serde(rename = "type")] + sticker_type: u8, + format_type: u8, + available: Option, + guild_id: Option, + user: Option, + sort_value: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +struct RoleSubscriptionData { + role_subscription_listing_id: u64, + tier_name: String, + total_months_subscribed: u32, + is_renewal: bool, +} + +#[derive(Debug, Deserialize, Serialize)] +struct TypingStartEvent { + channel_id: String, + guild_id: Option, + user_id: String, + timestamp: i64, + member: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct GatewayIdentifyPayload { + token: String, + properties: GatewayIdentifyConnectionProps, + compress: Option, + large_threshold: Option, //default: 50 + shard: Option>, + presence: Option, + intents: i32, +} + +#[derive(Debug, Deserialize, Serialize)] +struct GatewayIdentifyConnectionProps { + os: String, + browser: String, + device: String, +} + +#[derive(Debug, Deserialize, Serialize)] +struct PresenceUpdate { + since: Option, + activities: Vec, + status: String, + afk: bool, +} + +#[derive(Debug, Deserialize, Serialize)] +struct Activity { + name: String, + #[serde(rename = "type")] + activity_type: i32, + url: Option, + created_at: i64, + timestamps: Option, + application_id: Option, + details: Option, + state: Option, + emoji: Option, + party: Option, + assets: Option, + secrets: Option, + instance: Option, + flags: Option, + buttons: Option>, +} + +#[derive(Debug, Deserialize, Serialize)] +struct ActivityTimestamps { + start: Option, + end: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct ActivityParty { + id: Option, + size: Option>, +} + +#[derive(Debug, Deserialize, Serialize)] +struct ActivityAssets { + large_image: Option, + large_text: Option, + small_image: Option, + small_text: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct ActivitySecrets { + join: Option, + spectate: Option, + #[serde(rename = "match")] + match_string: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +struct ActivityButton { + label: String, + url: String, +} + +#[derive(Debug, Deserialize, Serialize)] +struct GatewayResume { + token: String, + session_id: String, + seq: String, +} diff --git a/src/gateway.rs b/src/gateway.rs index e4ba3c9..d68be22 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -1,2 +1,4 @@ #[derive(Debug)] -pub struct Gateway {} +pub struct Gateway { + url: String, +}