From 7ddb5d3820c15ce4202e6f43057310a9fbb7178a Mon Sep 17 00:00:00 2001 From: Matthieu Date: Fri, 5 Nov 2021 19:04:58 +0400 Subject: use twilight for deserialization and gateway --- common/rust/src/discord_models/application.rs | 38 --- common/rust/src/discord_models/audit_log.rs | 214 ------------- common/rust/src/discord_models/channel.rs | 341 --------------------- common/rust/src/discord_models/emoji.rs | 15 - common/rust/src/discord_models/gateway.rs | 124 -------- common/rust/src/discord_models/guild.rs | 255 --------------- common/rust/src/discord_models/guild_template.rs | 18 -- common/rust/src/discord_models/invite.rs | 48 --- .../rust/src/discord_models/message_components.rs | 75 ----- common/rust/src/discord_models/mod.rs | 16 - common/rust/src/discord_models/permissions.rs | 21 -- common/rust/src/discord_models/slash_commands.rs | 104 ------- common/rust/src/discord_models/stage_instance.rs | 19 -- common/rust/src/discord_models/teams.rs | 28 -- common/rust/src/discord_models/user.rs | 73 ----- common/rust/src/discord_models/voice.rs | 30 -- common/rust/src/discord_models/webhook.rs | 29 -- common/rust/src/lib.rs | 2 +- common/rust/src/payloads.rs | 259 +--------------- common/rust/src/serializable_event.rs | 165 ++++++++++ 20 files changed, 172 insertions(+), 1702 deletions(-) delete mode 100644 common/rust/src/discord_models/application.rs delete mode 100644 common/rust/src/discord_models/audit_log.rs delete mode 100644 common/rust/src/discord_models/channel.rs delete mode 100644 common/rust/src/discord_models/emoji.rs delete mode 100644 common/rust/src/discord_models/gateway.rs delete mode 100644 common/rust/src/discord_models/guild.rs delete mode 100644 common/rust/src/discord_models/guild_template.rs delete mode 100644 common/rust/src/discord_models/invite.rs delete mode 100644 common/rust/src/discord_models/message_components.rs delete mode 100644 common/rust/src/discord_models/mod.rs delete mode 100644 common/rust/src/discord_models/permissions.rs delete mode 100644 common/rust/src/discord_models/slash_commands.rs delete mode 100644 common/rust/src/discord_models/stage_instance.rs delete mode 100644 common/rust/src/discord_models/teams.rs delete mode 100644 common/rust/src/discord_models/user.rs delete mode 100644 common/rust/src/discord_models/voice.rs delete mode 100644 common/rust/src/discord_models/webhook.rs create mode 100644 common/rust/src/serializable_event.rs (limited to 'common/rust/src') diff --git a/common/rust/src/discord_models/application.rs b/common/rust/src/discord_models/application.rs deleted file mode 100644 index 65707d2..0000000 --- a/common/rust/src/discord_models/application.rs +++ /dev/null @@ -1,38 +0,0 @@ -use enumflags2::{bitflags, BitFlags}; -use serde::{Deserialize, Serialize}; - -use super::{teams::Team, user::User}; - -#[bitflags] -#[repr(u64)] -#[derive(Debug, Clone, Copy)] -pub enum ApplicationFlags { - GatewayPresence = 1 << 12, - GatewayPresenceLimit = 1 << 13, - GatewayGuildMembers = 1 << 14, - GatewayGuildMembersLimited = 1 << 15, - VerificationPendingGuildLimit = 1 << 16, - Embedded = 1 << 17, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Application { - pub id: String, - pub name: String, - pub icon: Option, - pub description: String, - pub rpc_origins: Option>, - pub bot_public: bool, - pub bot_require_code_grant: bool, - pub terms_of_service_url: Option, - pub privacy_policy_url: Option, - pub owner: Option, - pub summary: String, - pub verify_key: String, - pub team: Option, - pub guild_id: Option, - pub primary_sku_id: Option, - pub slug: Option, - pub cover_image: Option, - pub flags: Option>, -} diff --git a/common/rust/src/discord_models/audit_log.rs b/common/rust/src/discord_models/audit_log.rs deleted file mode 100644 index f223a2f..0000000 --- a/common/rust/src/discord_models/audit_log.rs +++ /dev/null @@ -1,214 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; -use crate::discord_models::channel::Channel; - -use super::{guild::Integration, user::User, webhook::Webhook}; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum AuditLogEvents { - GuildUpdate = 1, - ChannelCreate = 10, - ChannelUpdate = 11, - ChannelDelete = 12, - ChannelOverwriteCreate = 13, - ChannelOverwriteUpdate = 14, - ChannelOverwriteDelete = 15, - MemberKick = 20, - MemberPrune = 21, - MemberBanAdd = 22, - MemberBanRemove = 23, - MemberUpdate = 24, - MemberRoleUpdate = 25, - MemberMove = 26, - MemberDisconnect = 27, - BotAdd = 28, - RoleCreate = 30, - RoleUpdate = 31, - RoleDelete = 32, - InviteCreate = 40, - InviteUpdate = 41, - InviteDelete = 42, - WebhookCreate = 50, - WebhookUpdate = 51, - WebhookDelete = 52, - EmojiCreate = 60, - EmojiUpdate = 61, - EmojiDelete = 62, - MessageDelete = 72, - MessageBulkDelete = 73, - MessagePin = 74, - MessageUnpin = 75, - IntegrationCreate = 80, - IntegrationUpdate = 81, - IntegrationDelete = 82, - StageInstanceCreate = 83, - StageInstanceUpdate = 84, - StageInstanceDelete = 85, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub enum OptionalAuditEntryInfoType { - #[serde(rename = "0")] - Role, - #[serde(rename = "1")] - Member, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct OptionalAuditEntryInfo { - pub delete_member_days: Option, - pub members_removed: Option, - pub channel_id: Option, - pub message_id: Option, - pub count: Option, - pub id: Option, - #[serde(rename = "type")] - pub type_: Option>, - pub role_name: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub enum AuditLogChangeKey { - #[serde(rename = "name")] - Name, - #[serde(rename = "description")] - Description, - #[serde(rename = "icon_hash")] - IconHash, - #[serde(rename = "splash_hash")] - SplashHash, - #[serde(rename = "discovery_splash_hash")] - DiscoverySplashHash, - #[serde(rename = "banner_hash")] - BannerHash, - #[serde(rename = "owner_id")] - OwnerId, - #[serde(rename = "region")] - Region, - #[serde(rename = "preferred_locale")] - PreferredLocale, - #[serde(rename = "afk_channel_id")] - AfkChannelId, - #[serde(rename = "afk_timeout")] - AfkTimeout, - #[serde(rename = "rules_channel_id")] - RulesChannelId, - #[serde(rename = "public_updates_channel_id")] - PublicUpdatesChannelId, - #[serde(rename = "mfa_level")] - MfaLevel, - #[serde(rename = "verification_level")] - VerificationLevel, - #[serde(rename = "explicit_content_filter")] - ExplicitContentFilter, - #[serde(rename = "default_message_notifications")] - DefaultMessageNotifications, - #[serde(rename = "vanity_url_code")] - VanityUrlCode, - #[serde(rename = "$add")] - Add, - #[serde(rename = "$remove")] - Remove, - #[serde(rename = "prune_delete_days")] - PruneDeleteDays, - #[serde(rename = "widget_enabled")] - WidgetEnabled, - #[serde(rename = "widget_channel_id")] - WidgetChannelId, - #[serde(rename = "system_channel_id")] - SystemChannelId, - #[serde(rename = "position")] - Position, - #[serde(rename = "topic")] - Topic, - #[serde(rename = "bitrate")] - Bitrate, - #[serde(rename = "permission_overwrites")] - PermissionOverwrites, - #[serde(rename = "nsfw")] - Nsfw, - #[serde(rename = "application_id")] - ApplicationId, - #[serde(rename = "rate_limit_per_user")] - RateLimitPerUser, - #[serde(rename = "permissions")] - Permissions, - #[serde(rename = "color")] - Color, - #[serde(rename = "hoist")] - Hoist, - #[serde(rename = "mentionable")] - Mentionable, - #[serde(rename = "allow")] - Allow, - #[serde(rename = "deny")] - Deny, - #[serde(rename = "code")] - Code, - #[serde(rename = "channel_id")] - ChannelId, - #[serde(rename = "inviter_id")] - InviterId, - #[serde(rename = "max_uses")] - MaxUses, - #[serde(rename = "uses")] - Uses, - #[serde(rename = "max_age")] - MaxAge, - #[serde(rename = "temporary")] - Temporary, - #[serde(rename = "deaf")] - Deaf, - #[serde(rename = "mute")] - Mute, - #[serde(rename = "nick")] - Nick, - #[serde(rename = "avatar_hash")] - AvatarHash, - #[serde(rename = "id")] - Id, - #[serde(rename = "type")] - Type, - #[serde(rename = "enable_emoticons")] - EnableEmoticons, - #[serde(rename = "expire_behavior")] - ExpireBehavior, - #[serde(rename = "expire_grace_period")] - ExpireGracePeriod, - #[serde(rename = "user_limit")] - UserLimit, - #[serde(rename = "privacy_level")] - PrivacyLevel, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct AuditLogChange { - pub new_value: Option, - pub old_value: Option, - pub key: AuditLogChangeKey, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct AuditLogEntry { - pub target_id: Option, - pub changes: Option>, - pub user_id: Option, - pub id: String, - pub action_type: AuditLogEvents, - pub options: Option, - pub reason: Option, -} - -pub enum NewAuditLogEntry { - -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct AuditLog { - pub webhooks: Vec, - pub users: Vec, - pub threads: Vec, - pub audit_log_entries: Vec, - pub integrations: Vec, -} diff --git a/common/rust/src/discord_models/channel.rs b/common/rust/src/discord_models/channel.rs deleted file mode 100644 index ef31aa1..0000000 --- a/common/rust/src/discord_models/channel.rs +++ /dev/null @@ -1,341 +0,0 @@ -use enumflags2::{bitflags, BitFlags}; -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::{ - application::Application, emoji::Emoji, guild::GuildMember, message_components::Component, - slash_commands::MessageInteraction, user::User, -}; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum ChannelTypes { - GuildText = 0, - Dm = 1, - GuildVoice = 2, - GroupDm = 3, - GuildCategory = 4, - GuildNews = 5, - GuildStore = 6, - GuildNewsThread = 10, - GuildPublicThread = 11, - GuildPrivateThread = 12, - GuildStageVoice = 13, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum VideoQualityModes { - Auto = 1, - Full = 2, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum OverwriteTypes { - Role = 0, - Member = 1, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Overwrite { - pub id: String, - #[serde(rename = "type")] - pub type_: OverwriteTypes, - pub allow: String, - pub deny: String, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ThreadMetadata { - pub archived: bool, - pub auto_archive_duration: i64, - pub archive_timestamp: String, - pub locked: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ThreadMember { - pub id: Option, - pub user_id: Option, - pub join_timestamp: String, - pub flags: i64, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Channel { - pub id: String, - #[serde(rename = "type")] - pub type_: ChannelTypes, - pub guild_id: Option, - pub position: Option, - pub permission_overwrites: Option>, - pub name: Option, - pub topic: Option, - pub nsfw: Option, - pub last_message_id: Option, - pub bitrate: Option, - pub user_limit: Option, - pub rate_limit_per_user: Option, - pub recipients: Option>, - pub icon: Option, - pub owner_id: Option, - pub application_id: Option, - pub parent_id: Option, - pub last_pin_timestamp: Option, - pub rtc_region: Option, - pub video_quality_mode: Option, - pub message_count: Option, - pub member_count: Option, - pub thread_metadata: Option, - pub member: Option, - pub default_auto_archive_duration: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Attachment { - pub id: String, - pub filename: String, - pub content_type: String, - pub size: i64, - pub url: String, - pub proxy_url: String, - pub height: Option, - pub width: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ChannelMention { - pub id: String, - pub guild_id: String, - #[serde(rename = "type")] - pub type_: ChannelTypes, - pub name: String, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub enum EmbedTypes { - #[serde(rename = "rich")] - Rich, - #[serde(rename = "image")] - Image, - #[serde(rename = "video")] - Video, - #[serde(rename = "gifv")] - Gifv, - #[serde(rename = "article")] - Article, - #[serde(rename = "link")] - Link, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct EmbedThumbnail { - pub url: Option, - pub proxy_url: Option, - pub height: Option, - pub width: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct EmbedVideo { - pub url: Option, - pub proxy_url: Option, - pub height: Option, - pub width: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct EmbedImage { - pub url: Option, - pub proxy_url: Option, - pub height: Option, - pub width: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct EmbedProvider { - pub name: Option, - pub url: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct EmbedAuthor { - pub name: Option, - pub url: Option, - pub icon_url: Option, - pub proxy_icon_url: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct EmbedFooter { - pub text: String, - pub icon_url: Option, - pub proxy_icon_url: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct EmbedField { - pub name: String, - pub value: String, - pub inline: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Embed { - pub title: Option, - #[serde(rename = "type")] - pub type_: Option, - pub description: Option, - pub url: Option, - pub timestamp: Option, - pub color: Option, - pub footer: Option, - pub image: Option, - pub thumbnail: Option, - pub video: Option, - pub provider: Option, - pub author: Option, - pub fields: Option>, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Reaction { - pub count: i64, - pub me: bool, - pub emoji: Emoji, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum MessageTypes { - Default = 0, - RecipientAdd = 1, - RecipientRemove = 2, - Call = 3, - ChannelNameChange = 4, - ChannelIconChange = 5, - ChannelPinnedMessage = 6, - GuildMemberJoin = 7, - UserPremiumGuildSubscription = 8, - UserPremiumGuildSubscriptionTier1 = 9, - UserPremiumGuildSubscriptionTier2 = 10, - UserPremiumGuildSubscriptionTier3 = 11, - ChannelFollowAdd = 12, - GuildDiscoveryDisqualified = 14, - GuildDiscoveryRequalified = 15, - GuildDiscoveryGracePeriodInitialWarning = 16, - GuildDiscoveryGracePeriodFinalWarning = 17, - ThreadCreated = 18, - Reply = 19, - ApplicationCommand = 20, - ThreadStarterMessage = 21, - GuildInviteReminder = 22, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum MessageActivityTypes { - Join = 1, - Spectate = 2, - Listen = 3, - JoinRequest = 5, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct MessageActivity { - #[serde(rename = "type")] - pub type_: MessageActivityTypes, - pub party_id: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct MessageReference { - pub message_id: Option, - pub channel_id: Option, - pub guild_id: Option, - pub fail_if_not_exists: Option, -} - -#[bitflags] -#[repr(u64)] -#[derive(Debug, Clone, Copy)] -pub enum MessageFlags { - Crossposted = 1 << 0, - IsCrosspost = 1 << 1, - SuppressEmbeds = 1 << 2, - SourceMessageDeleted = 1 << 3, - Urgent = 1 << 4, - HasThread = 1 << 5, - Ephemeral = 1 << 6, - Loading = 1 << 7, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum MessageStickerFormatTypes { - Png = 1, - Apng = 2, - Lottie = 3, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct MessageStickerItem { - pub id: String, - pub name: String, - pub format_type: MessageStickerFormatTypes, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct MessageSticker { - pub id: String, - pub pack_id: Option, - pub name: String, - pub description: String, - pub tags: String, - // deprecated - // pub asset: String, - pub format_type: MessageStickerFormatTypes, - pub available: Option, - pub guild_id: Option, - pub user: Option, - pub sort_value: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Message { - pub id: String, - pub channel_id: String, - pub guild_id: Option, - pub author: User, - pub member: Option, - pub content: String, - pub timestamp: String, - pub edited_timestamp: String, - pub tts: bool, - pub mention_everyone: bool, - pub mentions: Vec, // todo: It is a Vector of User objects, with an additional partial member field (GuildMember) - pub mentions_roles: Vec, - pub mention_channels: Option>, - pub attachments: Vec, - pub embeds: Vec, - pub reactions: Option>, - /// ! Can be a String or an int ! - pub nonce: Option, - pub pinned: bool, - pub webhook_id: Option, - #[serde(rename = "type")] - pub type_: MessageTypes, - pub activity: Option, - pub application: Option, - pub application_id: Option, - pub message_reference: Option, - pub flags: Option>, - pub referenced_message: Option>, - pub interaction: Option, - pub thread: Option, - pub components: Option, - pub sticker_items: Option>, - // deprecated - // pub stickers: Option>, -} diff --git a/common/rust/src/discord_models/emoji.rs b/common/rust/src/discord_models/emoji.rs deleted file mode 100644 index eec02e7..0000000 --- a/common/rust/src/discord_models/emoji.rs +++ /dev/null @@ -1,15 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::user::User; - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Emoji { - pub id: Option, - pub name: Option, - pub roles: Vec, - pub user: Option, - pub require_colons: Option, - pub managed: Option, - pub animated: Option, - pub available: Option, -} diff --git a/common/rust/src/discord_models/gateway.rs b/common/rust/src/discord_models/gateway.rs deleted file mode 100644 index a886d99..0000000 --- a/common/rust/src/discord_models/gateway.rs +++ /dev/null @@ -1,124 +0,0 @@ -use enumflags2::{bitflags, BitFlags}; -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::user::User; - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub enum PresenceUpdateStatus { - #[serde(rename = "online")] - Online, - #[serde(rename = "idle")] - Idle, - #[serde(rename = "dnd")] - Dnd, - #[serde(rename = "offline")] - Offline, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ClientStatus { - pub desktop: Option, - pub mobile: Option, - pub web: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct PresenceUpdate { - pub user: User, - pub guild_id: String, - pub status: PresenceUpdateStatus, - pub activities: Vec, - pub client_status: ClientStatus, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum ActivityTypes { - Game = 0, - Streaming = 1, - Listening = 2, - Watching = 3, - Custom = 4, - Competing = 5, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ActivityTimestamps { - pub start: Option, - pub end: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ActivityEmoji { - pub name: String, - pub id: Option, - pub animated: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ActivityParty { - pub id: Option, - /// [current_size, max_size] - pub size: Option>, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ActivityAssets { - pub large_image: Option, - pub large_text: Option, - pub small_image: Option, - pub small_text: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ActivitySecrets { - pub join: Option, - pub spectate: Option, - #[serde(rename = "match")] - pub match_: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ActivityButtons { - pub label: String, - pub url: String, -} - -#[bitflags] -#[repr(u64)] -#[derive(Debug, Clone, Copy)] -pub enum ActivityFlags { - Instance = 1 << 0, - Join = 1 << 1, - Spectate = 1 << 2, - JoinRequest = 1 << 3, - Sync = 1 << 4, - Play = 1 << 5, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Activity { - pub name: String, - #[serde(rename = "type")] - pub type_: ActivityTypes, - pub url: Option, - pub created_at: String, - pub timestamps: Option, - pub application_id: Option, - pub details: Option, - pub state: Option, - pub emoji: Option, - pub party: Option, - pub assets: Option, - pub secrets: Option, - pub instance: Option, - pub flags: Option>, - pub buttons: Option>, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -#[serde(tag = "type")] -pub enum NewActivity { - -} \ No newline at end of file diff --git a/common/rust/src/discord_models/guild.rs b/common/rust/src/discord_models/guild.rs deleted file mode 100644 index 85da5b2..0000000 --- a/common/rust/src/discord_models/guild.rs +++ /dev/null @@ -1,255 +0,0 @@ -use enumflags2::{bitflags, BitFlags}; -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::{ - channel::Channel, emoji::Emoji, gateway::PresenceUpdate, permissions::Role, - stage_instance::StageInstance, user::User, voice::VoiceState, -}; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum IntegrationExpireBehavior { - RemoveRole = 0, - Kick = 1, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct IntegrationAccount { - pub id: String, - pub name: String, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct IntegrationApplication { - pub id: String, - pub name: String, - pub icon: Option, - pub description: String, - pub summary: Option, - pub bot: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Integration { - pub id: String, - pub name: String, - #[serde(rename = "type")] - pub type_: String, - pub enabled: bool, - pub syncing: Option, - pub role_id: Option, - pub enable_emoticons: Option, - pub expire_behavior: Option, - pub expire_grace_period: Option, - pub user: Option, - pub account: IntegrationAccount, - pub synced_at: Option, - pub subscriber_count: Option, - pub revoked: Option, - pub application: Option, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum VerificationLevel { - None = 0, - Low = 1, - Medium = 2, - High = 3, - VeryHigh = 4, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum PremiumTier { - None = 0, - Tier1 = 1, - Tier2 = 2, - Tier3 = 3, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum ExplicitContentFilter { - Disabled = 0, - MembersWithoutRoles = 1, - AllMembers = 2, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum MfaLevel { - None = 0, - Elevated = 1, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum DefaultMessageNotificationLevel { - AllMessages = 0, - OnlyMentions = 1, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum GuildNsfwLevel { - Default = 0, - Explicit = 1, - Safe = 2, - AgeRestricted = 3, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum GuildFeatures { - #[serde(rename = "ANIMATED_ICON")] - AnimatedIcon, - #[serde(rename = "BANNER")] - Banner, - #[serde(rename = "COMMERCE")] - Commerce, - #[serde(rename = "COMMUNITY")] - Community, - #[serde(rename = "DISCOVERABLE")] - Discoverable, - #[serde(rename = "FEATURABLE")] - Featurable, - #[serde(rename = "INVITE_SPLASH")] - InviteSplash, - #[serde(rename = "MEMBER_VERIFICATION_GATE_ENABLED")] - MemberVerificationGateEnabled, - #[serde(rename = "NEWS")] - News, - #[serde(rename = "PARTNERED")] - Partnered, - #[serde(rename = "PREVIEW_ENABLED")] - PreviewEnabled, - #[serde(rename = "VANITY_URL")] - VanityUrl, - #[serde(rename = "VERIFIED")] - Verified, - #[serde(rename = "VIP_REGIONS")] - VipRegions, - #[serde(rename = "WELCOME_SCREEN_ENABLED")] - WelcomeScreenEnabled, - #[serde(rename = "TICKETED_EVENTS_ENABLED")] - TicketedEventsEnabled, - #[serde(rename = "MONETIZATION_ENABLED")] - MonetizationEnabled, - #[serde(rename = "MORE_STICKERS")] - MoreStickers, - #[serde(rename = "THREE_DAY_THREAD_ARCHIVE")] - ThreeDayThreadArchive, - #[serde(rename = "SEVEN_DAY_THREAD_ARCHIVE")] - SevenDayThreadArchive, - #[serde(rename = "PRIVATE_THREADS")] - PrivateThreads, -} - -#[bitflags] -#[repr(u64)] -#[derive(Debug, Clone, Copy)] -pub enum SystemChannelFlags { - SuppressJoinNotifications = 1 << 0, - SuppressPremiumSubscriptions = 1 << 1, - SuppressGuildReminderNotifications = 1 << 2, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct WelcomeScreenChannel { - pub channel_id: String, - pub description: String, - pub emoji_id: Option, - pub emoji_name: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct WelcomeScreen { - pub description: String, - pub welcome_channels: Vec, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Guild { - pub id: String, - pub name: String, - pub icon: Option, - pub icon_hash: Option, - pub splash: Option, - pub discovery_splash: Option, - pub owner: Option, - pub owner_id: String, - pub permissions: Option, - /// DEPRECATED - pub region: Option, - pub afk_channel_id: Option, - pub afk_timeout: i64, - pub widget_enabled: Option, - pub widget_channel_id: Option, - pub verification_level: VerificationLevel, - pub default_message_notifications: DefaultMessageNotificationLevel, - pub explicit_content_filter: ExplicitContentFilter, - pub roles: Vec, - pub emojis: Vec, - pub features: Vec, - pub mfa_level: MfaLevel, - pub application_id: Option, - pub system_channel_id: Option, - pub system_channel_flags: BitFlags, - pub rules_channel_id: Option, - pub joined_at: Option, - pub large: Option, - pub unavailable: Option, - pub member_count: Option, - pub voice_states: Option>, - pub members: Option>, - pub channels: Option>, - pub threads: Option>, - pub presences: Option>, - pub max_presences: Option, - pub vanity_url_code: Option, - pub description: Option, - pub banner: Option, - pub premium_tier: PremiumTier, - pub premium_subscription_count: i64, - pub preferred_locale: String, - pub public_updates_channel_id: Option, - pub max_video_channel_users: Option, - pub approximate_member_count: Option, - pub welcome_screen: Option, - pub nsfw_level: GuildNsfwLevel, - pub stage_instances: Option>, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct GuildMember { - pub user: Option, - pub nick: Option, - pub roles: Vec, - pub joined_at: String, - pub premium_since: Option, - pub deaf: bool, - pub mute: bool, - pub pending: Option, - pub permissions: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct GuildPreview { - pub id: String, - pub name: String, - pub icon: Option, - pub splash: Option, - pub discovery_splash: Option, - pub emojis: Vec, - pub features: Vec, - pub approximate_member_count: i64, - pub approximate_presence_count: i64, - pub description: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct GuildWidget { - pub enabled: bool, - pub channel_id: Option, -} diff --git a/common/rust/src/discord_models/guild_template.rs b/common/rust/src/discord_models/guild_template.rs deleted file mode 100644 index 960631d..0000000 --- a/common/rust/src/discord_models/guild_template.rs +++ /dev/null @@ -1,18 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::{guild::Guild, user::User}; - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct GuildTemplate { - pub code: String, - pub name: String, - pub description: Option, - pub usage_count: i64, - pub creator_id: String, - pub creator: User, - pub created_at: String, - pub updated_at: String, - pub source_guild_ild: String, - pub serialized_source_guild: Guild, - pub is_dirty: Option, -} diff --git a/common/rust/src/discord_models/invite.rs b/common/rust/src/discord_models/invite.rs deleted file mode 100644 index 639278c..0000000 --- a/common/rust/src/discord_models/invite.rs +++ /dev/null @@ -1,48 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::{ - application::Application, - channel::Channel, - guild::{Guild, GuildMember}, - user::User, -}; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum InviteTargetTypes { - Stream = 1, - EmbeddedApplication = 2, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct InviteStageInstance { - pub members: Vec, - pub participant_count: i64, - pub speaker_count: i64, - pub topic: String, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Invite { - pub code: String, - pub guild: Option, - pub channel: Channel, - pub inviter: Option, - pub target_type: Option, - pub target_user: Option, - pub target_application: Option, - pub approximate_presence_count: Option, - pub approximate_member_count: Option, - pub expires_at: Option, - pub stage_instance: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct InviteMetadata { - pub uses: i64, - pub max_uses: i64, - pub max_age: i64, - pub temporary: bool, - pub created_at: String, -} diff --git a/common/rust/src/discord_models/message_components.rs b/common/rust/src/discord_models/message_components.rs deleted file mode 100644 index f71d7ed..0000000 --- a/common/rust/src/discord_models/message_components.rs +++ /dev/null @@ -1,75 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::emoji::Emoji; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum ComponentTypes { - ActionRow = 1, - Button = 2, - SelectMenu = 3, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -/// Global representation of a Component, more detailed are Button (if button) and Select Menu (if select menu) -/// Action Rows are just type: 1, content + components -pub struct Component { - #[serde(rename = "type")] - pub type_: ComponentTypes, - pub custom_id: Option, - pub disabled: Option, - pub style: Option, - pub label: Option, - pub emoji: Option, - pub url: Option, - pub options: Vec, - pub placeholder: Option, - pub min_values: Option, - pub max_values: Option, - pub components: Option>, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Button { - #[serde(rename = "type")] - /// it should be `2` - pub type_: ComponentTypes, - pub style: ButtonStyles, - pub label: Option, - pub emoji: Option, - pub custom_id: Option, - pub url: Option, - pub disabled: Option, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum ButtonStyles { - Primary = 1, - Secondary = 2, - Success = 3, - Danger = 4, - Link = 5, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct SelectOption { - pub label: String, - pub value: String, - pub description: Option, - pub emoji: Option, - pub default: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct SelectMenu { - /// it should be 3 - pub type_: ComponentTypes, - pub custom_id: String, - pub options: Vec, - pub placeholder: Option, - pub min_values: Option, - pub max_values: Option, - pub disabled: Option, -} diff --git a/common/rust/src/discord_models/mod.rs b/common/rust/src/discord_models/mod.rs deleted file mode 100644 index 8017e2a..0000000 --- a/common/rust/src/discord_models/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -pub mod application; -pub mod audit_log; -pub mod channel; -pub mod emoji; -pub mod gateway; -pub mod guild; -pub mod guild_template; -pub mod invite; -pub mod message_components; -pub mod permissions; -pub mod slash_commands; -pub mod stage_instance; -pub mod teams; -pub mod user; -pub mod voice; -pub mod webhook; diff --git a/common/rust/src/discord_models/permissions.rs b/common/rust/src/discord_models/permissions.rs deleted file mode 100644 index 76fa34a..0000000 --- a/common/rust/src/discord_models/permissions.rs +++ /dev/null @@ -1,21 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct RoleTags { - pub bot_id: Option, - pub integration_id: Option, - pub premium_subscriber: Option, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Role { - pub id: String, - pub name: String, - pub color: i64, - pub hoist: bool, - pub position: i64, - pub permissions: String, - pub managed: bool, - pub mentionable: bool, - pub tags: Option, -} diff --git a/common/rust/src/discord_models/slash_commands.rs b/common/rust/src/discord_models/slash_commands.rs deleted file mode 100644 index 181a622..0000000 --- a/common/rust/src/discord_models/slash_commands.rs +++ /dev/null @@ -1,104 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::{channel::Message, guild::GuildMember, user::User}; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum ApplicationCommandOptionType { - SubCommand = 1, - SubCommandGroup = 2, - String = 3, - Integer = 4, - Boolean = 5, - User = 6, - Channel = 7, - Role = 8, - Mentionable = 9, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ApplicationCommandOptionChoice { - pub name: String, - /// todo: Can also be a String!!!! - pub value: i64, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ApplicationCommandOption { - #[serde(rename = "type")] - pub type_: ApplicationCommandOptionType, - pub name: String, - pub description: String, - pub required: Option, - pub choices: Option>, - pub options: Option>, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ApplicationCommand { - pub id: String, - pub application_id: String, - pub guild_id: Option, - pub name: String, - pub description: String, - pub options: Option>, - pub default_permission: Option, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum ApplicationCommandPermissionType { - Role = 1, - User = 2, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct GuildApplicationCommandPermissions { - pub id: String, - pub application_id: String, - pub guild_id: String, - pub permissions: Vec, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ApplicationCommandPermissions { - pub id: String, - #[serde(rename = "type")] - pub type_: ApplicationCommandPermissionType, - pub permission: bool, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum InteractionRequestType { - Ping = 1, - ApplicationCommand = 2, - MessageComponent = 3, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct MessageInteraction { - pub id: String, - #[serde(rename = "type")] - pub type_: InteractionRequestType, - pub name: String, - pub user: User, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Interaction { - pub id: String, - pub application_id: String, - #[serde(rename = "type")] - pub type_: InteractionRequestType, - /// i am not sure about this one https://canary.discord.com/developers/docs/interactions/slash-commands#interaction-object-application-command-interaction-data - pub data: Option, - pub guild_id: Option, - pub channel_id: Option, - pub member: Option, - pub user: Option, - pub token: String, - pub version: i64, - pub message: Option, -} diff --git a/common/rust/src/discord_models/stage_instance.rs b/common/rust/src/discord_models/stage_instance.rs deleted file mode 100644 index 1eee1c2..0000000 --- a/common/rust/src/discord_models/stage_instance.rs +++ /dev/null @@ -1,19 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum PrivacyLevel { - Public = 1, - GuildOnly = 2, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct StageInstance { - pub id: String, - pub guild_id: String, - pub channel_id: String, - pub topic: String, - pub privacy_level: PrivacyLevel, - pub discoverable_disabled: bool, -} diff --git a/common/rust/src/discord_models/teams.rs b/common/rust/src/discord_models/teams.rs deleted file mode 100644 index 369b3cd..0000000 --- a/common/rust/src/discord_models/teams.rs +++ /dev/null @@ -1,28 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::user::User; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum MembershipState { - Invited = 0, - Accepted = 1, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct TeamMembers { - pub membership_state: MembershipState, - pub permissions: Vec, - pub team_id: String, - pub user: User, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Team { - pub icon: Option, - pub id: String, - pub members: Vec, - pub name: String, - pub owner_user_id: String, -} diff --git a/common/rust/src/discord_models/user.rs b/common/rust/src/discord_models/user.rs deleted file mode 100644 index 36914ce..0000000 --- a/common/rust/src/discord_models/user.rs +++ /dev/null @@ -1,73 +0,0 @@ -use enumflags2::{bitflags, BitFlags}; -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::guild::Integration; - -#[bitflags] -#[repr(u64)] -#[derive(Debug, Clone, Copy)] -pub enum UserFlags { - // None = 0 << 0, - DiscordEmployee = 1 << 0, - PartneredServerOwner = 1 << 1, - HypesquadEvents = 1 << 2, - BugHunterLevel1 = 1 << 3, - HouseBravery = 1 << 6, - HouseBrilliance = 1 << 7, - HouseBalance = 1 << 8, - EarlySupporter = 1 << 9, - TeamUser = 1 << 10, - BugHunterLevel2 = 1 << 14, - VerifiedBot = 1 << 16, - EarlyVerifiedBotDeveloper = 1 << 17, - DiscordCertifiedModerator = 1 << 18, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum PremiumTypes { - None = 0, - NitroClassic = 1, - Nitro = 2, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -/// Represents a User within Discord -pub struct User { - pub id: String, - pub username: String, - pub discriminator: String, - pub avatar: Option, - pub bot: Option, - pub system: Option, - pub mfa_enabled: Option, - pub locale: Option, - pub verified: Option, - pub email: Option, - pub flags: Option>, - pub premium_type: Option, - pub public_flags: Option>, -} - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum VisibilityTypes { - None = 0, - Everyone = 1, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -/// The connection object that the user has attached. -pub struct Connection { - pub id: String, - pub name: String, - #[serde(rename = "type")] - pub type_: String, - pub revoked: Option, - pub integrations: Option>, - pub verified: bool, - pub friend_sync: bool, - pub show_activity: bool, - pub visibility: VisibilityTypes, -} diff --git a/common/rust/src/discord_models/voice.rs b/common/rust/src/discord_models/voice.rs deleted file mode 100644 index 8263af5..0000000 --- a/common/rust/src/discord_models/voice.rs +++ /dev/null @@ -1,30 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::guild::GuildMember; - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct VoiceState { - pub guild_id: Option, - pub channel_id: Option, - pub user_id: String, - pub member: Option, - pub session_id: 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, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct VoiceRegion { - pub id: String, - pub name: String, - pub vip: bool, - pub optimal: bool, - pub deprecated: bool, - pub custom: bool, -} diff --git a/common/rust/src/discord_models/webhook.rs b/common/rust/src/discord_models/webhook.rs deleted file mode 100644 index 4648772..0000000 --- a/common/rust/src/discord_models/webhook.rs +++ /dev/null @@ -1,29 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - -use super::{channel::Channel, guild::Guild, user::User}; - -#[derive(Debug, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum WebhookTypes { - Incoming = 1, - ChannelFollower = 2, - Application = 3, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Webhook { - pub id: String, - #[serde(rename = "type")] - pub type_: WebhookTypes, - pub guild_id: Option, - pub channel_id: Option, - pub user: Option, - pub name: Option, - pub avatar: Option, - pub token: Option, - pub application_id: Option, - pub source_guild: Option, - pub source_channel: Option, - pub url: String, -} diff --git a/common/rust/src/lib.rs b/common/rust/src/lib.rs index fa2c6fc..cbe6934 100644 --- a/common/rust/src/lib.rs +++ b/common/rust/src/lib.rs @@ -9,10 +9,10 @@ pub use testcontainers; /// This crate is all the utilities shared by the nova rust projects /// It includes logging, config and protocols. pub mod config; -pub mod discord_models; pub mod error; pub mod monitoring; pub mod nats; pub mod payloads; pub mod redis; +mod serializable_event; diff --git a/common/rust/src/payloads.rs b/common/rust/src/payloads.rs index fd7717d..454baf1 100644 --- a/common/rust/src/payloads.rs +++ b/common/rust/src/payloads.rs @@ -1,27 +1,19 @@ use std::fmt::Debug; use serde::{Deserialize, Serialize}; +use twilight_model::gateway::event::Event; +use crate::serializable_event::SerializableEvent; -use crate::discord_models::{ - application::Application, - channel::{Channel, Message, ThreadMember}, - emoji::Emoji, - gateway::PresenceUpdate, - guild::{Guild, GuildMember, Integration}, - invite::InviteTargetTypes, - permissions::Role, - slash_commands::{ApplicationCommand, Interaction}, - stage_instance::StageInstance, - user::User, - voice::VoiceState, -}; +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct SerializeHelper(#[serde(with = "SerializableEvent")] pub Event); /// Payload send to the nova cache queues #[derive(Serialize, Deserialize, Debug, Clone)] // #[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))] pub struct CachePayload { pub tracing: Tracing, - pub data: CacheData, + #[serde(flatten)] + pub data: SerializeHelper, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -29,242 +21,3 @@ pub struct Tracing { pub node_id: String, pub span: Option, } - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub enum CacheData { - Ready { - version: u8, - user: User, - guilds: Vec, - session_id: String, - shard: Option>, - application: Application, - }, - ApplicationCommandCreate { - guild_id: Option, - command: ApplicationCommand, - }, - ApplicationCommandUpdate { - guild_id: Option, - command: ApplicationCommand, - }, - ApplicationCommandDelete { - guild_id: Option, - command: ApplicationCommand, - }, - ChannelCreate { - channel: Channel, - }, - ChannelUpdate { - channel: Channel, - }, - ChannelDelete { - channel: Channel, - }, - ThreadCreate { - channel: Channel, - }, - ThreadUpdate { - channel: Channel, - }, - ThreadDelete { - channel: Channel, - }, - ThreadListSync { - guild_id: String, - channel_ids: Option>, - threads: Vec, - members: Vec, - }, - ThreadMemberUpdate { - member: ThreadMember, - }, - ThreadMembersUpdate { - id: String, - guild_id: String, - member_count: i64, - added_members: Option>, - removed_member_ids: Option>, - }, - ChannelPinsUpdate { - guild_id: Option, - channel_id: String, - last_pin_timestamp: Option, - }, - GuildCreate { - guild: Guild, - }, - GuildUpdate { - guild: Guild, - }, - GuildDelete { - guild: Guild, - }, - GuildBanAdd { - guild_id: String, - user: User, - }, - GuildBanRemove { - guild_id: String, - user: User, - }, - GuildEmojisUpdate { - guild_id: String, - emojis: Vec, - }, - GuildIntegrationsUpdate { - guild_id: String, - }, - GuildMemberAdd { - guild_id: String, - member: GuildMember, - }, - GuildMemberRemove { - guild_id: String, - user: User, - }, - GuildMemberUpdate { - guild_id: String, - roles: Vec, - user: User, - nick: Option, - joined_at: Option, - premium_since: Option, - deaf: Option, - mute: Option, - pending: Option, - }, - GuildMembersChunk { - guild_id: String, - members: Vec, - chunk_index: i64, - chunk_count: i64, - not_found: Option>, - presences: Option>, - nonce: Option, - }, - GuildRoleCreate { - guild_id: String, - role: Role, - }, - GuildRoleUpdate { - guild_id: String, - role: Role, - }, - GuildRoleDelete { - guild_id: String, - role_id: String, - }, - IntegrationCreate { - guild_id: String, - integration: Integration, - }, - IntegrationUpdate { - guild_id: String, - integration: Integration, - }, - IntegrationDelete { - id: String, - guild_id: String, - application_id: Option, - }, - InviteCreate { - channel_id: String, - code: String, - created_at: String, - guild_id: Option, - inviter: Option, - max_age: i64, - max_uses: i64, - target_type: Option, - target_user: Option, - target_application: Option, - temporary: bool, - uses: i64, - }, - InviteDelete { - channel_id: String, - guild_id: Option, - code: String, - }, - InteractionCreate { - // boxed to avoid a large difference size between variants (https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant) - interaction: Box, - }, - MessageCreate { - message: Message, - }, - MessageUpdate { - message: Message, - }, - MessageDelete { - id: String, - channel_id: String, - guild_id: Option, - }, - MessageDeleteBulk { - ids: Vec, - channel_id: String, - guild_id: Option, - }, - MessageReactionAdd { - user_id: String, - channel_id: String, - message_id: String, - guild_id: Option, - member: Option, - emoji: Emoji, - }, - MessageReactionRemove { - user_id: String, - channel_id: String, - message_id: String, - guild_id: Option, - emoji: Emoji, - }, - MessageReactionRemoveAll { - channel_id: String, - message_id: String, - guild_id: Option, - }, - MessageReactionRemoveEmoji { - channel_id: String, - message_id: String, - guild_id: Option, - emoji: Emoji, - }, - PresenceUpdate { - presence: PresenceUpdate, - }, - TypingStart { - channel_id: String, - guild_id: Option, - user_id: String, - timestamp: i64, - member: Option, - }, - UserUpdate { - user: User, - }, - VoiceStateUpdate { - state: VoiceState, - }, - VoiceServerUpdate { - token: String, - guild_id: String, - endpoint: Option, - }, - WebhookUpdate { - guild_id: String, - channel_id: String, - }, - StageInstanceCreate { - instance: StageInstance, - }, - StageInstanceUpdate { - instance: StageInstance, - }, - StageInstanceDelete { - instance: StageInstance, - }, -} diff --git a/common/rust/src/serializable_event.rs b/common/rust/src/serializable_event.rs new file mode 100644 index 0000000..269b0aa --- /dev/null +++ b/common/rust/src/serializable_event.rs @@ -0,0 +1,165 @@ +use serde::{Deserialize, Serialize}; +use twilight_model::gateway::{ + event::{ + shard::{ + Connected, Connecting, Disconnected, Identifying, Payload, Reconnecting, Resuming, + }, + Event, + }, + payload::{ + BanAdd, BanRemove, ChannelCreate, ChannelDelete, ChannelPinsUpdate, ChannelUpdate, + GuildCreate, GuildDelete, GuildEmojisUpdate, GuildIntegrationsUpdate, GuildUpdate, + IntegrationCreate, IntegrationDelete, IntegrationUpdate, InteractionCreate, InviteCreate, + InviteDelete, MemberAdd, MemberChunk, MemberRemove, MemberUpdate, MessageCreate, + MessageDelete, MessageDeleteBulk, MessageUpdate, PresenceUpdate, ReactionAdd, + ReactionRemove, ReactionRemoveAll, ReactionRemoveEmoji, Ready, RoleCreate, RoleDelete, + RoleUpdate, StageInstanceCreate, StageInstanceDelete, StageInstanceUpdate, ThreadCreate, + ThreadDelete, ThreadListSync, ThreadMemberUpdate, ThreadMembersUpdate, ThreadUpdate, + TypingStart, UnavailableGuild, UserUpdate, VoiceServerUpdate, VoiceStateUpdate, + WebhooksUpdate, + }, +}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(remote = "Event")] +#[serde(rename_all = "snake_case")] +#[serde(tag = "t", content = "c")] +pub enum SerializableEvent { + /// A user was banned from a guild. + BanAdd(BanAdd), + /// A user's ban from a guild was removed. + BanRemove(BanRemove), + /// A channel was created. + ChannelCreate(ChannelCreate), + /// A channel was deleted. + ChannelDelete(ChannelDelete), + /// A channel's pins were updated. + ChannelPinsUpdate(ChannelPinsUpdate), + /// A channel was updated. + ChannelUpdate(ChannelUpdate), + /// A heartbeat was sent to or received from the gateway. + GatewayHeartbeat(u64), + /// A heartbeat acknowledgement was received from the gateway. + GatewayHeartbeatAck, + /// A "hello" packet was received from the gateway. + GatewayHello(u64), + /// A shard's session was invalidated. + /// + /// `true` if resumeable. If not, then the shard must do a full reconnect. + GatewayInvalidateSession(bool), + /// The gateway is indicating to perform a reconnect. + GatewayReconnect, + /// Undocumented event, should be ignored + GiftCodeUpdate, + /// A guild was created. + GuildCreate(Box), + /// A guild was deleted or the current user was removed from a guild. + GuildDelete(Box), + /// A guild's emojis were updated. + GuildEmojisUpdate(GuildEmojisUpdate), + /// A guild's integrations were updated. + GuildIntegrationsUpdate(GuildIntegrationsUpdate), + /// A guild was updated. + GuildUpdate(Box), + /// A guild integration was created. + IntegrationCreate(Box), + /// A guild integration was updated. + IntegrationDelete(IntegrationDelete), + /// A guild integration was deleted. + IntegrationUpdate(Box), + /// An interaction was invoked by a user. + InteractionCreate(Box), + /// A invite was made. + InviteCreate(Box), + /// A invite was deleted. + InviteDelete(InviteDelete), + /// A user was added to a guild. + MemberAdd(Box), + /// A user was removed from a guild. + MemberRemove(MemberRemove), + /// A user's member object in a guild was updated. + MemberUpdate(Box), + /// A chunk of members were received from the gateway. + MemberChunk(MemberChunk), + /// A message was created in a channel. + MessageCreate(Box), + /// A message was deleted in a channel. + MessageDelete(MessageDelete), + /// Multiple messages were deleted in a channel. + MessageDeleteBulk(MessageDeleteBulk), + /// A message was updated in a channel. + MessageUpdate(Box), + /// A user's active presence (such as game or online status) was updated. + PresenceUpdate(Box), + /// Multiple presences outside of a guild were updated. + /// + /// For bots this is always empty and useless. + PresencesReplace, + /// A reaction was added to a message. + ReactionAdd(Box), + /// A reaction was removed from a message. + ReactionRemove(Box), + /// All reactions were removed from a message. + ReactionRemoveAll(ReactionRemoveAll), + /// All instances of a given emoji from the reactions of a message were + /// removed. + ReactionRemoveEmoji(ReactionRemoveEmoji), + /// A shard is now "ready" and fully connected. + Ready(Box), + /// A shard has successfully resumed. + Resumed, + /// A role was created in a guild. + RoleCreate(RoleCreate), + /// A role was deleted in a guild. + RoleDelete(RoleDelete), + /// A role was updated in a guild. + RoleUpdate(RoleUpdate), + /// A shard is now in a connected stage after being fully connected to the + /// gateway. + ShardConnected(Connected), + /// A shard is now in a connecting stage after starting to connect to the + /// gateway. + ShardConnecting(Connecting), + /// A shard is now in a disconnected stage after the connection was closed. + ShardDisconnected(Disconnected), + /// A shard is now in a identifying stage after starting a new session. + ShardIdentifying(Identifying), + /// A shard is now in a reconnecting stage after a disconnect or session was + /// ended. + ShardReconnecting(Reconnecting), + /// A payload of bytes came in through the shard's connection. + ShardPayload(Payload), + /// A shard is now in a Resuming stage after a disconnect. + ShardResuming(Resuming), + /// A stage instance was created in a stage channel. + StageInstanceCreate(StageInstanceCreate), + /// A stage instance was deleted in a stage channel. + StageInstanceDelete(StageInstanceDelete), + /// A stage instance was updated in a stage channel. + StageInstanceUpdate(StageInstanceUpdate), + /// A thread has been created, relevant to the current user, + /// or the current user has been added to a thread. + ThreadCreate(ThreadCreate), + /// A thread, relevant to the current user, has been deleted. + ThreadDelete(ThreadDelete), + /// The current user has gained access to a thread. + ThreadListSync(ThreadListSync), + /// The thread member object for the current user has been updated. + ThreadMemberUpdate(ThreadMemberUpdate), + /// A user has been added to or removed from a thread. + ThreadMembersUpdate(ThreadMembersUpdate), + /// A thread has been updated. + ThreadUpdate(ThreadUpdate), + /// A user started typing in a channel. + TypingStart(Box), + /// A guild is now unavailable. + UnavailableGuild(UnavailableGuild), + /// The current user was updated. + UserUpdate(UserUpdate), + /// A voice server update was sent. + VoiceServerUpdate(VoiceServerUpdate), + /// A voice state in a voice channel was updated. + VoiceStateUpdate(Box), + /// A webhook was updated. + WebhooksUpdate(WebhooksUpdate), +} -- cgit v1.2.3