diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index ea206f3d89d..9677cc40d44 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -4,6 +4,8 @@ use serenity::model::prelude::interaction::application_command::*; use serenity::model::prelude::*; use serenity::prelude::*; +mod model_type_sizes; + const IMAGE_URL: &str = "https://raw.githubusercontent.com/serenity-rs/serenity/current/logo.png"; const IMAGE_URL_2: &str = "https://rustacean.net/assets/rustlogo.png"; @@ -71,6 +73,8 @@ async fn message(ctx: &Context, msg: Message) -> Result<(), serenity::Error> { .add_existing_attachment(msg.attachments[0].id), ) .await?; + } else if msg.content == "ranking" { + model_type_sizes::print_ranking(); } else if msg.content == "auditlog" { // Test special characters in audit log reason msg.channel_id diff --git a/examples/testing/src/model_type_sizes.rs b/examples/testing/src/model_type_sizes.rs new file mode 100644 index 00000000000..7da5c56c745 --- /dev/null +++ b/examples/testing/src/model_type_sizes.rs @@ -0,0 +1,293 @@ +// TODO: remove extra imports once https://github.com/serenity-rs/serenity/pull/2204 is merged +use serenity::model::prelude::application_command::*; +use serenity::model::prelude::automod::*; +use serenity::model::prelude::message_component::*; +use serenity::model::prelude::modal::*; +use serenity::model::prelude::ping::*; +use serenity::model::prelude::*; + +pub fn print_ranking() { + let mut sizes = vec![ + ("ActionExecution", std::mem::size_of::()), + ("Activity", std::mem::size_of::()), + ("ActivityAssets", std::mem::size_of::()), + ("ActivityButton", std::mem::size_of::()), + ("ActivityEmoji", std::mem::size_of::()), + ("ActivityFlags", std::mem::size_of::()), + ("ActivityParty", std::mem::size_of::()), + ("ActivitySecrets", std::mem::size_of::()), + ("ActivityTimestamps", std::mem::size_of::()), + ("AffectedComponent", std::mem::size_of::()), + ("AffectedRole", std::mem::size_of::()), + ("ApplicationCommandInteraction", std::mem::size_of::()), + ( + "ApplicationCommandPermissionsUpdateEvent", + std::mem::size_of::(), + ), + ("ApplicationFlags", std::mem::size_of::()), + ("ApplicationId", std::mem::size_of::()), + ("Attachment", std::mem::size_of::()), + ("AttachmentId", std::mem::size_of::()), + ("AuditLogEntry", std::mem::size_of::()), + ("AuditLogEntryId", std::mem::size_of::()), + ("AuditLogs", std::mem::size_of::()), + ( + "AutoModerationActionExecutionEvent", + std::mem::size_of::(), + ), + ("AutoModerationRuleCreateEvent", std::mem::size_of::()), + ("AutoModerationRuleDeleteEvent", std::mem::size_of::()), + ("AutoModerationRuleUpdateEvent", std::mem::size_of::()), + ("AutocompleteOption", std::mem::size_of::()), + ("Ban", std::mem::size_of::()), + ("BotGateway", std::mem::size_of::()), + ("ChannelCreateEvent", std::mem::size_of::()), + ("ChannelDeleteEvent", std::mem::size_of::()), + ("ChannelId", std::mem::size_of::()), + ("ChannelMention", std::mem::size_of::()), + ("ChannelPinsUpdateEvent", std::mem::size_of::()), + ("ChannelUpdateEvent", std::mem::size_of::()), + ("ClientStatus", std::mem::size_of::()), + ("Colour", std::mem::size_of::()), + ("CommandData", std::mem::size_of::()), + ("CommandDataOption", std::mem::size_of::()), + ("CommandDataResolved", std::mem::size_of::()), + ("CommandId", std::mem::size_of::()), + ("CommandPermissionId", std::mem::size_of::()), + ("CommandVersionId", std::mem::size_of::()), + ("Connection", std::mem::size_of::()), + ("CurrentApplicationInfo", std::mem::size_of::()), + ("CurrentUser", std::mem::size_of::()), + ("Embed", std::mem::size_of::()), + ("EmbedAuthor", std::mem::size_of::()), + ("EmbedField", std::mem::size_of::()), + ("EmbedFooter", std::mem::size_of::()), + ("EmbedImage", std::mem::size_of::()), + ("EmbedProvider", std::mem::size_of::()), + ("EmbedThumbnail", std::mem::size_of::()), + ("EmbedVideo", std::mem::size_of::()), + ("Emoji", std::mem::size_of::()), + ("EmojiId", std::mem::size_of::()), + ("EmojiIdentifier", std::mem::size_of::()), + ("EmojiIdentifierParseError", std::mem::size_of::()), + ("FollowedChannel", std::mem::size_of::()), + ("Gateway", std::mem::size_of::()), + ("GatewayIntents", std::mem::size_of::()), + ("GenericId", std::mem::size_of::()), + ("Guild", std::mem::size_of::()), + ("GuildBanAddEvent", std::mem::size_of::()), + ("GuildBanRemoveEvent", std::mem::size_of::()), + ("GuildChannel", std::mem::size_of::()), + ("GuildCreateEvent", std::mem::size_of::()), + ("GuildDeleteEvent", std::mem::size_of::()), + ("GuildEmojisUpdateEvent", std::mem::size_of::()), + ("GuildId", std::mem::size_of::()), + ("GuildInfo", std::mem::size_of::()), + ("GuildIntegrationsUpdateEvent", std::mem::size_of::()), + ("GuildMemberAddEvent", std::mem::size_of::()), + ("GuildMemberRemoveEvent", std::mem::size_of::()), + ("GuildMemberUpdateEvent", std::mem::size_of::()), + ("GuildMembersChunkEvent", std::mem::size_of::()), + ("GuildPreview", std::mem::size_of::()), + ("GuildPrune", std::mem::size_of::()), + ("GuildRoleCreateEvent", std::mem::size_of::()), + ("GuildRoleDeleteEvent", std::mem::size_of::()), + ("GuildRoleUpdateEvent", std::mem::size_of::()), + ("GuildScheduledEventCreateEvent", std::mem::size_of::()), + ("GuildScheduledEventDeleteEvent", std::mem::size_of::()), + ("GuildScheduledEventUpdateEvent", std::mem::size_of::()), + ("GuildScheduledEventUserAddEvent", std::mem::size_of::()), + ( + "GuildScheduledEventUserRemoveEvent", + std::mem::size_of::(), + ), + ("GuildStickersUpdateEvent", std::mem::size_of::()), + ("GuildUpdateEvent", std::mem::size_of::()), + ("GuildWelcomeChannel", std::mem::size_of::()), + ("GuildWelcomeScreen", std::mem::size_of::()), + ("GuildWidget", std::mem::size_of::()), + ("Incident", std::mem::size_of::()), + ("IncidentUpdate", std::mem::size_of::()), + ("InstallParams", std::mem::size_of::()), + ("Integration", std::mem::size_of::()), + ("IntegrationAccount", std::mem::size_of::()), + ("IntegrationApplication", std::mem::size_of::()), + ("IntegrationCreateEvent", std::mem::size_of::()), + ("IntegrationDeleteEvent", std::mem::size_of::()), + ("IntegrationId", std::mem::size_of::()), + ("IntegrationUpdateEvent", std::mem::size_of::()), + ("InteractionMessageFlags", std::mem::size_of::()), + ("InteractionCreateEvent", std::mem::size_of::()), + ("InteractionId", std::mem::size_of::()), + ("Invite", std::mem::size_of::()), + ("InviteChannel", std::mem::size_of::()), + ("InviteCreateEvent", std::mem::size_of::()), + ("InviteDeleteEvent", std::mem::size_of::()), + ("InviteGuild", std::mem::size_of::()), + ("InviteStageInstance", std::mem::size_of::()), + ("Maintenance", std::mem::size_of::()), + ("Member", std::mem::size_of::()), + ("Message", std::mem::size_of::()), + ("MessageActivity", std::mem::size_of::()), + ("MessageApplication", std::mem::size_of::()), + ("MessageComponentInteraction", std::mem::size_of::()), + ("MessageComponentInteractionData", std::mem::size_of::()), + ("MessageCreateEvent", std::mem::size_of::()), + ("MessageDeleteBulkEvent", std::mem::size_of::()), + ("MessageDeleteEvent", std::mem::size_of::()), + ("MessageFlags", std::mem::size_of::()), + ("MessageFlags", std::mem::size_of::()), + ("MessageId", std::mem::size_of::()), + ("MessageInteraction", std::mem::size_of::()), + ("MessageReaction", std::mem::size_of::()), + ("MessageReference", std::mem::size_of::()), + ("MessageUpdateEvent", std::mem::size_of::()), + ("ModalSubmitInteraction", std::mem::size_of::()), + ("ModalSubmitInteractionData", std::mem::size_of::()), + ("Options", std::mem::size_of::()), + ("PartialChannel", std::mem::size_of::()), + ("PartialCurrentApplicationInfo", std::mem::size_of::()), + ("PartialGuild", std::mem::size_of::()), + ("PartialGuildChannel", std::mem::size_of::()), + ("PartialMember", std::mem::size_of::()), + ("PermissionOverwrite", std::mem::size_of::()), + ("Permissions", std::mem::size_of::()), + ("PingInteraction", std::mem::size_of::()), + ("Presence", std::mem::size_of::()), + ("PresenceUpdateEvent", std::mem::size_of::()), + ("PresenceUser", std::mem::size_of::()), + ("PresencesReplaceEvent", std::mem::size_of::()), + ("PrivateChannel", std::mem::size_of::()), + ("Reaction", std::mem::size_of::()), + ("ReactionAddEvent", std::mem::size_of::()), + ("ReactionConversionError", std::mem::size_of::()), + ("ReactionRemoveAllEvent", std::mem::size_of::()), + ("ReactionRemoveEvent", std::mem::size_of::()), + ("Ready", std::mem::size_of::()), + ("ReadyEvent", std::mem::size_of::()), + ("RelatedIdsForEventType", std::mem::size_of::()), + ("ResolvedOption", std::mem::size_of::()), + ("ResumedEvent", std::mem::size_of::()), + ("RichInvite", std::mem::size_of::()), + ("Role", std::mem::size_of::()), + ("RoleId", std::mem::size_of::()), + ("RoleTags", std::mem::size_of::()), + ("Rule", std::mem::size_of::()), + ("RuleId", std::mem::size_of::()), + ("ScheduledEvent", std::mem::size_of::()), + ("ScheduledEventId", std::mem::size_of::()), + ("ScheduledEventMetadata", std::mem::size_of::()), + ("ScheduledEventUser", std::mem::size_of::()), + ("SessionStartLimit", std::mem::size_of::()), + ("ShardInfo", std::mem::size_of::()), + ("SkuId", std::mem::size_of::()), + ("StageInstance", std::mem::size_of::()), + ("StageInstanceCreateEvent", std::mem::size_of::()), + ("StageInstanceDeleteEvent", std::mem::size_of::()), + ("StageInstanceId", std::mem::size_of::()), + ("StageInstanceUpdateEvent", std::mem::size_of::()), + ("Sticker", std::mem::size_of::()), + ("StickerId", std::mem::size_of::()), + ("StickerItem", std::mem::size_of::()), + ("StickerPack", std::mem::size_of::()), + ("StickerPackBannerId", std::mem::size_of::()), + ("StickerPackId", std::mem::size_of::()), + ("SystemChannelFlags", std::mem::size_of::()), + ("TargetId", std::mem::size_of::()), + ("Team", std::mem::size_of::()), + ("TeamMember", std::mem::size_of::()), + ("ThreadCreateEvent", std::mem::size_of::()), + ("ThreadDeleteEvent", std::mem::size_of::()), + ("ThreadListSyncEvent", std::mem::size_of::()), + ("ThreadMember", std::mem::size_of::()), + ("ThreadMemberFlags", std::mem::size_of::()), + ("ThreadMemberUpdateEvent", std::mem::size_of::()), + ("ThreadMembersUpdateEvent", std::mem::size_of::()), + ("ThreadMetadata", std::mem::size_of::()), + ("ThreadUpdateEvent", std::mem::size_of::()), + ("ThreadsData", std::mem::size_of::()), + ("TriggerMetadata", std::mem::size_of::()), + ("TypingStartEvent", std::mem::size_of::()), + ("UnavailableGuild", std::mem::size_of::()), + ("UnknownEvent", std::mem::size_of::()), + ("User", std::mem::size_of::()), + ("UserId", std::mem::size_of::()), + ("UserPublicFlags", std::mem::size_of::()), + ("UserUpdateEvent", std::mem::size_of::()), + ("VoiceRegion", std::mem::size_of::()), + ("VoiceServerUpdateEvent", std::mem::size_of::()), + ("VoiceState", std::mem::size_of::()), + ("VoiceStateUpdateEvent", std::mem::size_of::()), + ("Webhook", std::mem::size_of::()), + ("WebhookId", std::mem::size_of::()), + ("WebhookUpdateEvent", std::mem::size_of::()), + ("ActionType", std::mem::size_of::()), + ("ActivityType", std::mem::size_of::()), + ("AutoModerationAction", std::mem::size_of::()), + ("Change", std::mem::size_of::()), + ("Channel", std::mem::size_of::()), + ("ChannelAction", std::mem::size_of::()), + ("ChannelIdParseError", std::mem::size_of::()), + ("ChannelOverwriteAction", std::mem::size_of::()), + ("ChannelType", std::mem::size_of::()), + ("CommandDataOptionValue", std::mem::size_of::()), + ("ConnectionVisibility", std::mem::size_of::()), + ("DefaultAvatar", std::mem::size_of::()), + ("DefaultMessageNotificationLevel", std::mem::size_of::()), + ("EmojiAction", std::mem::size_of::()), + ("EntityType", std::mem::size_of::()), + ("Event", std::mem::size_of::()), + ("ExplicitContentFilter", std::mem::size_of::()), + ("GatewayEvent", std::mem::size_of::()), + ("GuildWelcomeChannelEmoji", std::mem::size_of::()), + ("GuildWidgetStyle", std::mem::size_of::()), + ("IncidentStatus", std::mem::size_of::()), + ("IntegrationAction", std::mem::size_of::()), + ("IntegrationExpireBehaviour", std::mem::size_of::()), + ("Interaction", std::mem::size_of::()), + ("InteractionResponseType", std::mem::size_of::()), + ("InteractionType", std::mem::size_of::()), + ("InviteAction", std::mem::size_of::()), + ("InviteTargetType", std::mem::size_of::()), + ("KeywordPresetType", std::mem::size_of::()), + ("MemberAction", std::mem::size_of::()), + ("MembershipState", std::mem::size_of::()), + ("Mention", std::mem::size_of::()), + ("MentionParseError", std::mem::size_of::()), + ("MessageAction", std::mem::size_of::()), + ("MessageActivityKind", std::mem::size_of::()), + ("MessageType", std::mem::size_of::()), + ("MfaLevel", std::mem::size_of::()), + ("Nonce", std::mem::size_of::()), + ("NsfwLevel", std::mem::size_of::()), + ("OnlineStatus", std::mem::size_of::()), + ("PermissionOverwriteType", std::mem::size_of::()), + ("PremiumTier", std::mem::size_of::()), + ("ReactionType", std::mem::size_of::()), + ("ResolvedTarget", std::mem::size_of::()), + ("ResolvedValue", std::mem::size_of::()), + ("RoleAction", std::mem::size_of::()), + ("RoleIdParseError", std::mem::size_of::()), + ("ScheduledEventAction", std::mem::size_of::()), + ("ScheduledEventStatus", std::mem::size_of::()), + ("ScheduledEventType", std::mem::size_of::()), + ("Scope", std::mem::size_of::()), + ("StageInstanceAction", std::mem::size_of::()), + ("StickerAction", std::mem::size_of::()), + ("StickerFormatType", std::mem::size_of::()), + ("StickerType", std::mem::size_of::()), + ("ThreadAction", std::mem::size_of::()), + ("Trigger", std::mem::size_of::()), + ("TriggerType", std::mem::size_of::()), + ("Unresolved", std::mem::size_of::()), + ("UserIdParseError", std::mem::size_of::()), + ("VerificationLevel", std::mem::size_of::()), + ("VideoQualityMode", std::mem::size_of::()), + ("WebhookAction", std::mem::size_of::()), + ("WebhookType", std::mem::size_of::()), + ]; + sizes.sort_by_key(|&(_name, size)| size); + for (i, (name, size)) in sizes.iter().rev().take_while(|&&(_, size)| size >= 200).enumerate() { + println!("#{} {}: {} bytes", i + 1, name, size); + } +} diff --git a/src/model/application/interaction/application_command.rs b/src/model/application/interaction/application_command.rs index 943bb6ca783..bda85743c09 100644 --- a/src/model/application/interaction/application_command.rs +++ b/src/model/application/interaction/application_command.rs @@ -59,7 +59,7 @@ pub struct ApplicationCommandInteraction { /// /// **Note**: It is only present if the interaction is triggered in a guild. #[serde(skip_serializing_if = "Option::is_none")] - pub member: Option, + pub member: Option>, /// The `user` object for the invoking user. pub user: User, /// A continuation token for responding to the interaction. @@ -247,7 +247,7 @@ impl<'de> Deserialize<'de> for ApplicationCommandInteraction { add_guild_id_to_resolved(&mut map, guild_id); } - let member = remove_from_map_opt::(&mut map, "member")?; + let member = remove_from_map_opt::, _>(&mut map, "member")?; let user = remove_from_map_opt(&mut map, "user")? .or_else(|| member.as_ref().map(|m| m.user.clone())) .ok_or_else(|| DeError::custom("expected user or member"))?; diff --git a/src/model/application/interaction/message_component.rs b/src/model/application/interaction/message_component.rs index 3e3a674d81c..7dd269e496e 100644 --- a/src/model/application/interaction/message_component.rs +++ b/src/model/application/interaction/message_component.rs @@ -54,7 +54,7 @@ pub struct MessageComponentInteraction { pub version: u8, /// The message this interaction was triggered by, if /// it is a component. - pub message: Message, + pub message: Box, /// Permissions the app or bot has within the channel the interaction was sent from. pub app_permissions: Option, /// The selected language of the invoking user. diff --git a/src/model/application/interaction/modal.rs b/src/model/application/interaction/modal.rs index ba25dfa5094..aa8bafc7c1e 100644 --- a/src/model/application/interaction/modal.rs +++ b/src/model/application/interaction/modal.rs @@ -56,7 +56,7 @@ pub struct ModalSubmitInteraction { /// **Note**: Does not exist if the modal interaction originates from /// an application command interaction #[serde(skip_serializing_if = "Option::is_none")] - pub message: Option, + pub message: Option>, /// Permissions the app or bot has within the channel the interaction was sent from. pub app_permissions: Option, /// The selected language of the invoking user. diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index a6101c587fd..1bd7d389c59 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -110,7 +110,7 @@ pub struct Message { /// Sent if the message is a response to an [`Interaction`]. /// /// [`Interaction`]: crate::model::application::interaction::Interaction - pub interaction: Option, + pub interaction: Option>, /// The thread that was started from this message, includes thread member object. pub thread: Option, /// The components of this message @@ -130,7 +130,7 @@ pub struct Message { pub guild_id: Option, /// A partial amount of data about the user's member data, if this message /// was sent in a guild. - pub member: Option, + pub member: Option>, } #[cfg(feature = "model")] @@ -546,7 +546,7 @@ impl Message { message_id: self.id, user_id, guild_id: self.guild_id, - member: self.member.clone(), + member: self.member.as_deref().cloned(), }) } diff --git a/src/utils/custom_message.rs b/src/utils/custom_message.rs index 33c31f20422..094695b6873 100644 --- a/src/utils/custom_message.rs +++ b/src/utils/custom_message.rs @@ -125,7 +125,7 @@ impl CustomMessage { /// [author]: Self::author #[inline] pub fn member(&mut self, member: PartialMember) -> &mut Self { - self.msg.member = Some(member); + self.msg.member = Some(Box::new(member)); self }