1#![allow(clippy::option_option)]
8
9use serde::de::Error as DeError;
10use serde::Serialize;
11
12use crate::constants::Opcode;
13use crate::model::prelude::*;
14use crate::model::utils::{
15 deserialize_val,
16 emojis,
17 members,
18 optional_deserialize_components,
19 remove_from_map,
20 remove_from_map_opt,
21 stickers,
22};
23
24#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
28#[derive(Clone, Debug, Deserialize, Serialize)]
29#[serde(transparent)]
30#[non_exhaustive]
31pub struct CommandPermissionsUpdateEvent {
32 pub permission: CommandPermissions,
33}
34
35#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
39#[derive(Clone, Debug, Deserialize, Serialize)]
40#[serde(transparent)]
41#[non_exhaustive]
42pub struct AutoModRuleCreateEvent {
43 pub rule: Rule,
44}
45
46#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
50#[derive(Clone, Debug, Deserialize, Serialize)]
51#[serde(transparent)]
52#[non_exhaustive]
53pub struct AutoModRuleUpdateEvent {
54 pub rule: Rule,
55}
56
57#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
61#[derive(Clone, Debug, Deserialize, Serialize)]
62#[serde(transparent)]
63#[non_exhaustive]
64pub struct AutoModRuleDeleteEvent {
65 pub rule: Rule,
66}
67
68#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
72#[derive(Clone, Debug, Deserialize, Serialize)]
73#[serde(transparent)]
74#[non_exhaustive]
75pub struct AutoModActionExecutionEvent {
76 pub execution: ActionExecution,
77}
78
79#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
88#[derive(Clone, Debug, Deserialize, Serialize)]
89#[serde(transparent)]
90#[non_exhaustive]
91pub struct ChannelCreateEvent {
92 pub channel: GuildChannel,
94}
95
96#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
100#[derive(Clone, Debug, Deserialize, Serialize)]
101#[serde(transparent)]
102#[non_exhaustive]
103pub struct ChannelDeleteEvent {
104 pub channel: GuildChannel,
105}
106
107#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
111#[derive(Clone, Debug, Deserialize, Serialize)]
112#[non_exhaustive]
113pub struct ChannelPinsUpdateEvent {
114 pub guild_id: Option<GuildId>,
115 pub channel_id: ChannelId,
116 pub last_pin_timestamp: Option<Timestamp>,
117}
118
119#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
123#[derive(Clone, Debug, Deserialize, Serialize)]
124#[serde(transparent)]
125#[non_exhaustive]
126pub struct ChannelUpdateEvent {
127 pub channel: GuildChannel,
128}
129
130#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
134#[derive(Clone, Debug, Deserialize, Serialize)]
135#[non_exhaustive]
136pub struct GuildAuditLogEntryCreateEvent {
137 pub guild_id: GuildId,
138 #[serde(flatten)]
139 pub entry: AuditLogEntry,
140}
141
142#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
146#[derive(Clone, Debug, Deserialize, Serialize)]
147#[non_exhaustive]
148pub struct GuildBanAddEvent {
149 pub guild_id: GuildId,
150 pub user: User,
151}
152
153#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
157#[derive(Clone, Debug, Deserialize, Serialize)]
158#[non_exhaustive]
159pub struct GuildBanRemoveEvent {
160 pub guild_id: GuildId,
161 pub user: User,
162}
163
164#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
168#[derive(Clone, Debug, Serialize)]
169#[serde(transparent)]
170#[non_exhaustive]
171pub struct GuildCreateEvent {
172 pub guild: Guild,
173}
174
175impl<'de> Deserialize<'de> for GuildCreateEvent {
177 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
178 let mut guild: Guild = Guild::deserialize(deserializer)?;
179 guild.channels.values_mut().for_each(|x| x.guild_id = guild.id);
180 guild.members.values_mut().for_each(|x| x.guild_id = guild.id);
181 guild.roles.values_mut().for_each(|x| x.guild_id = guild.id);
182 Ok(Self {
183 guild,
184 })
185 }
186}
187
188#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
192#[derive(Clone, Debug, Deserialize, Serialize)]
193#[serde(transparent)]
194#[non_exhaustive]
195pub struct GuildDeleteEvent {
196 pub guild: UnavailableGuild,
197}
198
199#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
203#[derive(Clone, Debug, Deserialize, Serialize)]
204#[non_exhaustive]
205pub struct GuildEmojisUpdateEvent {
206 #[serde(with = "emojis")]
207 pub emojis: HashMap<EmojiId, Emoji>,
208 pub guild_id: GuildId,
209}
210
211#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
215#[derive(Clone, Debug, Deserialize, Serialize)]
216#[non_exhaustive]
217pub struct GuildIntegrationsUpdateEvent {
218 pub guild_id: GuildId,
219}
220
221#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
225#[derive(Clone, Debug, Deserialize, Serialize)]
226#[serde(transparent)]
227#[non_exhaustive]
228pub struct GuildMemberAddEvent {
229 pub member: Member,
230}
231
232#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
236#[derive(Clone, Debug, Deserialize, Serialize)]
237#[non_exhaustive]
238pub struct GuildMemberRemoveEvent {
239 pub guild_id: GuildId,
240 pub user: User,
241}
242
243#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
247#[derive(Clone, Debug, Deserialize, Serialize)]
248#[non_exhaustive]
249pub struct GuildMemberUpdateEvent {
250 pub guild_id: GuildId,
251 pub nick: Option<String>,
252 pub joined_at: Timestamp,
253 pub roles: Vec<RoleId>,
254 pub user: User,
255 pub premium_since: Option<Timestamp>,
256 #[serde(default)]
257 pub pending: bool,
258 #[serde(default)]
259 pub deaf: bool,
260 #[serde(default)]
261 pub mute: bool,
262 pub avatar: Option<ImageHash>,
263 pub communication_disabled_until: Option<Timestamp>,
264 pub unusual_dm_activity_until: Option<Timestamp>,
265}
266
267#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
271#[derive(Clone, Debug, Deserialize, Serialize)]
272#[serde(remote = "Self")]
273#[non_exhaustive]
274pub struct GuildMembersChunkEvent {
275 pub guild_id: GuildId,
277 #[serde(with = "members")]
279 pub members: HashMap<UserId, Member>,
280 pub chunk_index: u32,
282 pub chunk_count: u32,
284 #[serde(default)]
287 pub not_found: Vec<GenericId>,
288 pub presences: Option<Vec<Presence>>,
291 pub nonce: Option<String>,
293}
294
295impl<'de> Deserialize<'de> for GuildMembersChunkEvent {
297 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
298 let mut event = Self::deserialize(deserializer)?; event.members.values_mut().for_each(|m| m.guild_id = event.guild_id);
300 Ok(event)
301 }
302}
303
304impl Serialize for GuildMembersChunkEvent {
305 fn serialize<S: serde::Serializer>(&self, serializer: S) -> StdResult<S::Ok, S::Error> {
306 Self::serialize(self, serializer) }
308}
309
310#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
312#[derive(Deserialize)]
313struct RoleEventHelper {
314 guild_id: GuildId,
315 role: Role,
316}
317
318#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
322#[derive(Clone, Debug, Serialize)]
323#[non_exhaustive]
324pub struct GuildRoleCreateEvent {
325 pub role: Role,
326}
327
328impl<'de> Deserialize<'de> for GuildRoleCreateEvent {
330 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
331 let mut event = RoleEventHelper::deserialize(deserializer)?;
332 event.role.guild_id = event.guild_id;
333 Ok(Self {
334 role: event.role,
335 })
336 }
337}
338
339#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
343#[derive(Clone, Debug, Deserialize, Serialize)]
344#[non_exhaustive]
345pub struct GuildRoleDeleteEvent {
346 pub guild_id: GuildId,
347 pub role_id: RoleId,
348}
349
350#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
354#[derive(Clone, Debug, Serialize)]
355#[non_exhaustive]
356pub struct GuildRoleUpdateEvent {
357 pub role: Role,
358}
359
360impl<'de> Deserialize<'de> for GuildRoleUpdateEvent {
362 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
363 let mut event = RoleEventHelper::deserialize(deserializer)?;
364 event.role.guild_id = event.guild_id;
365 Ok(Self {
366 role: event.role,
367 })
368 }
369}
370
371#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
375#[derive(Clone, Debug, Deserialize, Serialize)]
376#[non_exhaustive]
377pub struct GuildStickersUpdateEvent {
378 #[serde(with = "stickers")]
379 pub stickers: HashMap<StickerId, Sticker>,
380 pub guild_id: GuildId,
381}
382
383#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
387#[derive(Clone, Debug, Deserialize, Serialize)]
388#[non_exhaustive]
389pub struct InviteCreateEvent {
390 pub channel_id: ChannelId,
393 pub code: String,
395 pub created_at: Timestamp,
397 pub guild_id: Option<GuildId>,
399 pub inviter: Option<User>,
401 pub max_age: u32,
403 pub max_uses: u8,
405 pub target_type: Option<InviteTargetType>,
407 pub target_user: Option<User>,
409 pub target_application: Option<Value>,
411 pub temporary: bool,
413 pub uses: u64,
415}
416
417#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
421#[derive(Clone, Debug, Deserialize, Serialize)]
422#[non_exhaustive]
423pub struct InviteDeleteEvent {
424 pub channel_id: ChannelId,
425 pub guild_id: Option<GuildId>,
426 pub code: String,
427}
428
429#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
433#[derive(Clone, Debug, Deserialize, Serialize)]
434#[serde(transparent)]
435#[non_exhaustive]
436pub struct GuildUpdateEvent {
437 pub guild: PartialGuild,
439}
440
441#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
445#[derive(Clone, Debug, Deserialize, Serialize)]
446#[serde(transparent)]
447#[non_exhaustive]
448pub struct MessageCreateEvent {
449 pub message: Message,
450}
451
452#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
456#[derive(Clone, Debug, Deserialize, Serialize)]
457#[non_exhaustive]
458pub struct MessageDeleteBulkEvent {
459 pub guild_id: Option<GuildId>,
460 pub channel_id: ChannelId,
461 pub ids: Vec<MessageId>,
462}
463
464#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
468#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
469#[non_exhaustive]
470pub struct MessageDeleteEvent {
471 pub guild_id: Option<GuildId>,
472 pub channel_id: ChannelId,
473 #[serde(rename = "id")]
474 pub message_id: MessageId,
475}
476
477fn deserialize_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
480where
481 T: Deserialize<'de>,
482 D: Deserializer<'de>,
483{
484 Deserialize::deserialize(deserializer).map(Some)
485}
486
487#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
496#[derive(Clone, Debug, Deserialize, Serialize)]
497#[non_exhaustive]
498pub struct MessageUpdateEvent {
499 pub id: MessageId,
500 pub channel_id: ChannelId,
501 pub author: Option<User>,
502 pub content: Option<String>,
503 pub timestamp: Option<Timestamp>,
504 pub edited_timestamp: Option<Timestamp>,
505 pub tts: Option<bool>,
506 pub mention_everyone: Option<bool>,
507 pub mentions: Option<Vec<User>>,
508 pub mention_roles: Option<Vec<RoleId>>,
509 pub mention_channels: Option<Vec<ChannelMention>>,
510 pub attachments: Option<Vec<Attachment>>,
511 pub embeds: Option<Vec<Embed>>,
512 pub reactions: Option<Vec<MessageReaction>>,
513 pub pinned: Option<bool>,
514 #[serde(default, deserialize_with = "deserialize_some")]
515 pub webhook_id: Option<Option<WebhookId>>,
516 #[serde(rename = "type")]
517 pub kind: Option<MessageType>,
518 #[serde(default, deserialize_with = "deserialize_some")]
519 pub activity: Option<Option<MessageActivity>>,
520 #[serde(default, deserialize_with = "deserialize_some")]
521 pub application: Option<Option<MessageApplication>>,
522 #[serde(default, deserialize_with = "deserialize_some")]
523 pub application_id: Option<Option<ApplicationId>>,
524 pub message_reference: Option<Option<MessageReference>>,
525 #[serde(default, deserialize_with = "deserialize_some")]
526 pub flags: Option<Option<MessageFlags>>,
527 #[serde(default, deserialize_with = "deserialize_some")]
528 pub referenced_message: Option<Option<Box<Message>>>,
529 #[cfg_attr(not(ignore_serenity_deprecated), deprecated = "Use interaction_metadata")]
530 #[serde(default, deserialize_with = "deserialize_some")]
531 pub interaction: Option<Option<Box<MessageInteraction>>>,
532 pub interaction_metadata: Option<Option<Box<MessageInteractionMetadata>>>,
533 #[serde(default, deserialize_with = "deserialize_some")]
534 pub thread: Option<Option<GuildChannel>>,
535 #[serde(default, deserialize_with = "optional_deserialize_components")]
536 pub components: Option<Vec<ActionRow>>,
537 pub sticker_items: Option<Vec<StickerItem>>,
538 pub position: Option<Option<u64>>,
539 pub role_subscription_data: Option<Option<RoleSubscriptionData>>,
540 pub guild_id: Option<GuildId>,
541 pub member: Option<Option<Box<PartialMember>>>,
542}
543
544impl MessageUpdateEvent {
545 #[allow(clippy::clone_on_copy)] #[rustfmt::skip]
547 pub fn apply_to_message(&self, message: &mut Message) {
549 #[allow(deprecated)] let Self {
553 id,
554 channel_id,
555 author,
556 content,
557 timestamp,
558 edited_timestamp,
559 tts,
560 mention_everyone,
561 mentions,
562 mention_roles,
563 mention_channels,
564 attachments,
565 embeds,
566 reactions,
567 pinned,
568 webhook_id,
569 kind,
570 activity,
571 application,
572 application_id,
573 message_reference,
574 flags,
575 referenced_message,
576 interaction,
577 interaction_metadata,
578 thread,
579 components,
580 sticker_items,
581 position,
582 role_subscription_data,
583 guild_id,
584 member,
585 } = self;
586
587 message.id = *id;
591 message.channel_id = *channel_id;
592
593 if let Some(x) = author { message.author = x.clone() }
594 if let Some(x) = content { message.content.clone_from(x) }
595 if let Some(x) = timestamp { message.timestamp = x.clone() }
596 message.edited_timestamp = *edited_timestamp;
597 if let Some(x) = tts { message.tts = x.clone() }
598 if let Some(x) = mention_everyone { message.mention_everyone = x.clone() }
599 if let Some(x) = mentions { message.mentions.clone_from(x) }
600 if let Some(x) = mention_roles { message.mention_roles.clone_from(x) }
601 if let Some(x) = mention_channels { message.mention_channels.clone_from(x) }
602 if let Some(x) = attachments { message.attachments.clone_from(x) }
603 if let Some(x) = embeds { message.embeds.clone_from(x) }
604 if let Some(x) = reactions { message.reactions.clone_from(x) }
605 if let Some(x) = pinned { message.pinned = x.clone() }
606 if let Some(x) = webhook_id { message.webhook_id.clone_from(x) }
607 if let Some(x) = kind { message.kind = x.clone() }
608 if let Some(x) = activity { message.activity.clone_from(x) }
609 if let Some(x) = application { message.application.clone_from(x) }
610 if let Some(x) = application_id { message.application_id.clone_from(x) }
611 if let Some(x) = message_reference { message.message_reference.clone_from(x) }
612 if let Some(x) = flags { message.flags.clone_from(x) }
613 if let Some(x) = referenced_message { message.referenced_message.clone_from(x) }
614 if let Some(x) = interaction { message.interaction.clone_from(x) }
615 if let Some(x) = interaction_metadata { message.interaction_metadata.clone_from(x) }
616 if let Some(x) = thread { message.thread.clone_from(x) }
617 if let Some(x) = components { message.components.clone_from(x) }
618 if let Some(x) = sticker_items { message.sticker_items.clone_from(x) }
619 if let Some(x) = position { message.position.clone_from(x) }
620 if let Some(x) = role_subscription_data { message.role_subscription_data.clone_from(x) }
621 message.guild_id = *guild_id;
622 if let Some(x) = member { message.member.clone_from(x) }
623 }
624}
625
626#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
630#[derive(Clone, Debug, Deserialize, Serialize)]
631#[serde(transparent)]
632#[non_exhaustive]
633pub struct PresenceUpdateEvent {
634 pub presence: Presence,
635}
636
637#[cfg_attr(not(ignore_serenity_deprecated), deprecated = "This event doesn't exist")]
639#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
640#[derive(Clone, Debug, Deserialize, Serialize)]
641#[serde(transparent)]
642#[non_exhaustive]
643pub struct PresencesReplaceEvent {
644 pub presences: Vec<Presence>,
645}
646
647#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
652#[derive(Clone, Debug, Deserialize, Serialize)]
653#[serde(transparent)]
654#[non_exhaustive]
655pub struct ReactionAddEvent {
656 pub reaction: Reaction,
657}
658
659#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
664#[derive(Clone, Debug, Deserialize, Serialize)]
665#[serde(transparent)]
666#[non_exhaustive]
667pub struct ReactionRemoveEvent {
668 pub reaction: Reaction,
672}
673
674#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
679#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
680#[non_exhaustive]
681pub struct ReactionRemoveAllEvent {
682 pub channel_id: ChannelId,
683 pub message_id: MessageId,
684 pub guild_id: Option<GuildId>,
685}
686
687#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
692#[derive(Clone, Debug, Deserialize, Serialize)]
693#[serde(transparent)]
694#[non_exhaustive]
695pub struct ReactionRemoveEmojiEvent {
696 pub reaction: Reaction,
697}
698
699#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
705#[derive(Clone, Debug, Deserialize, Serialize)]
706#[serde(transparent)]
707#[non_exhaustive]
708pub struct ReadyEvent {
709 pub ready: Ready,
710}
711
712#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
716#[derive(Clone, Debug, Deserialize, Serialize)]
717#[non_exhaustive]
718pub struct ResumedEvent {}
719
720#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
724#[derive(Clone, Debug, Deserialize, Serialize)]
725#[non_exhaustive]
726pub struct TypingStartEvent {
727 pub channel_id: ChannelId,
729 pub guild_id: Option<GuildId>,
731 pub user_id: UserId,
733 pub timestamp: u64,
735 pub member: Option<Member>,
737}
738
739#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
740#[derive(Clone, Debug, Deserialize, Serialize)]
741#[non_exhaustive]
742pub struct UnknownEvent {
743 #[serde(rename = "t")]
744 pub kind: String,
745 #[serde(rename = "d")]
746 pub value: Value,
747}
748
749#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
755#[derive(Clone, Debug, Deserialize, Serialize)]
756#[serde(transparent)]
757#[non_exhaustive]
758pub struct UserUpdateEvent {
759 pub current_user: CurrentUser,
760}
761
762#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
766#[derive(Clone, Debug, Deserialize, Serialize)]
767#[non_exhaustive]
768pub struct VoiceServerUpdateEvent {
769 pub token: String,
770 pub guild_id: Option<GuildId>,
771 pub endpoint: Option<String>,
772}
773
774#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
778#[derive(Clone, Debug, Deserialize, Serialize)]
779#[serde(transparent)]
780#[non_exhaustive]
781pub struct VoiceStateUpdateEvent {
782 pub voice_state: VoiceState,
783}
784
785#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
789#[derive(Clone, Debug, Deserialize, Serialize)]
790#[non_exhaustive]
791pub struct VoiceChannelStatusUpdateEvent {
792 pub status: Option<String>,
793 pub id: ChannelId,
794 pub guild_id: GuildId,
795}
796
797#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
801#[derive(Clone, Debug, Deserialize, Serialize)]
802#[non_exhaustive]
803pub struct WebhookUpdateEvent {
804 pub channel_id: ChannelId,
805 pub guild_id: GuildId,
806}
807
808#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
812#[derive(Clone, Debug, Deserialize, Serialize)]
813#[serde(transparent)]
814#[non_exhaustive]
815pub struct InteractionCreateEvent {
816 pub interaction: Interaction,
817}
818
819#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
823#[derive(Clone, Debug, Deserialize, Serialize)]
824#[serde(transparent)]
825#[non_exhaustive]
826pub struct IntegrationCreateEvent {
827 pub integration: Integration,
828}
829
830#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
834#[derive(Clone, Debug, Deserialize, Serialize)]
835#[serde(transparent)]
836#[non_exhaustive]
837pub struct IntegrationUpdateEvent {
838 pub integration: Integration,
839}
840
841#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
845#[derive(Clone, Debug, Serialize, Deserialize)]
846#[non_exhaustive]
847pub struct IntegrationDeleteEvent {
848 pub id: IntegrationId,
849 pub guild_id: GuildId,
850 pub application_id: Option<ApplicationId>,
851}
852
853#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
857#[derive(Clone, Debug, Deserialize, Serialize)]
858#[serde(transparent)]
859#[non_exhaustive]
860pub struct StageInstanceCreateEvent {
861 pub stage_instance: StageInstance,
862}
863
864#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
868#[derive(Clone, Debug, Deserialize, Serialize)]
869#[serde(transparent)]
870#[non_exhaustive]
871pub struct StageInstanceUpdateEvent {
872 pub stage_instance: StageInstance,
873}
874
875#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
879#[derive(Clone, Debug, Deserialize, Serialize)]
880#[serde(transparent)]
881#[non_exhaustive]
882pub struct StageInstanceDeleteEvent {
883 pub stage_instance: StageInstance,
884}
885
886#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
890#[derive(Clone, Debug, Deserialize, Serialize)]
891#[serde(transparent)]
892#[non_exhaustive]
893pub struct ThreadCreateEvent {
894 pub thread: GuildChannel,
895}
896
897#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
901#[derive(Clone, Debug, Deserialize, Serialize)]
902#[serde(transparent)]
903#[non_exhaustive]
904pub struct ThreadUpdateEvent {
905 pub thread: GuildChannel,
906}
907
908#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
912#[derive(Clone, Debug, Deserialize, Serialize)]
913#[serde(transparent)]
914#[non_exhaustive]
915pub struct ThreadDeleteEvent {
916 pub thread: PartialGuildChannel,
917}
918
919#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
923#[derive(Clone, Debug, Deserialize, Serialize)]
924#[non_exhaustive]
925pub struct ThreadListSyncEvent {
926 pub guild_id: GuildId,
928 pub channel_ids: Option<Vec<ChannelId>>,
932 pub threads: Vec<GuildChannel>,
934 pub members: Vec<ThreadMember>,
937}
938
939#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
944#[derive(Clone, Debug, Deserialize, Serialize)]
945#[serde(transparent)]
946#[non_exhaustive]
947pub struct ThreadMemberUpdateEvent {
948 pub member: ThreadMember,
949}
950
951#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
955#[derive(Clone, Debug, Deserialize, Serialize)]
956#[non_exhaustive]
957pub struct ThreadMembersUpdateEvent {
958 pub id: ChannelId,
960 pub guild_id: GuildId,
962 pub member_count: i16,
967 #[serde(default)]
969 pub added_members: Vec<ThreadMember>,
970 #[serde(default)]
972 pub removed_member_ids: Vec<UserId>,
973}
974
975#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
979#[derive(Clone, Debug, Deserialize, Serialize)]
980#[serde(transparent)]
981#[non_exhaustive]
982pub struct GuildScheduledEventCreateEvent {
983 pub event: ScheduledEvent,
984}
985
986#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
990#[derive(Clone, Debug, Deserialize, Serialize)]
991#[serde(transparent)]
992#[non_exhaustive]
993pub struct GuildScheduledEventUpdateEvent {
994 pub event: ScheduledEvent,
995}
996
997#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1001#[derive(Clone, Debug, Deserialize, Serialize)]
1002#[serde(transparent)]
1003#[non_exhaustive]
1004pub struct GuildScheduledEventDeleteEvent {
1005 pub event: ScheduledEvent,
1006}
1007
1008#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1012#[derive(Clone, Debug, Deserialize, Serialize)]
1013#[non_exhaustive]
1014pub struct GuildScheduledEventUserAddEvent {
1015 #[serde(rename = "guild_scheduled_event_id")]
1016 pub scheduled_event_id: ScheduledEventId,
1017 pub user_id: UserId,
1018 pub guild_id: GuildId,
1019}
1020
1021#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1025#[derive(Clone, Debug, Deserialize, Serialize)]
1026#[non_exhaustive]
1027pub struct GuildScheduledEventUserRemoveEvent {
1028 #[serde(rename = "guild_scheduled_event_id")]
1029 pub scheduled_event_id: ScheduledEventId,
1030 pub user_id: UserId,
1031 pub guild_id: GuildId,
1032}
1033
1034#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1038#[derive(Clone, Debug, Deserialize, Serialize)]
1039#[serde(transparent)]
1040#[non_exhaustive]
1041pub struct EntitlementCreateEvent {
1042 pub entitlement: Entitlement,
1043}
1044
1045#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1049#[derive(Clone, Debug, Deserialize, Serialize)]
1050#[serde(transparent)]
1051#[non_exhaustive]
1052pub struct EntitlementUpdateEvent {
1053 pub entitlement: Entitlement,
1054}
1055
1056#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1060#[derive(Clone, Debug, Deserialize, Serialize)]
1061#[serde(transparent)]
1062#[non_exhaustive]
1063pub struct EntitlementDeleteEvent {
1064 pub entitlement: Entitlement,
1065}
1066
1067#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1071#[derive(Clone, Debug, Deserialize, Serialize)]
1072#[non_exhaustive]
1073pub struct MessagePollVoteAddEvent {
1074 pub user_id: UserId,
1075 pub channel_id: ChannelId,
1076 pub message_id: MessageId,
1077 pub guild_id: Option<GuildId>,
1078 pub answer_id: AnswerId,
1079}
1080
1081#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1085#[derive(Clone, Debug, Deserialize, Serialize)]
1086#[non_exhaustive]
1087pub struct MessagePollVoteRemoveEvent {
1088 pub user_id: UserId,
1089 pub channel_id: ChannelId,
1090 pub message_id: MessageId,
1091 pub guild_id: Option<GuildId>,
1092 pub answer_id: AnswerId,
1093}
1094
1095#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1097#[allow(clippy::large_enum_variant)]
1098#[derive(Debug, Clone, Serialize)]
1099#[non_exhaustive]
1100#[serde(untagged)]
1101pub enum GatewayEvent {
1102 Dispatch(u64, Event),
1103 Heartbeat(#[deprecated = "always 0 because it is never provided by the gateway"] u64),
1104 Reconnect,
1105 InvalidateSession(bool),
1107 Hello(u64),
1108 HeartbeatAck,
1109}
1110
1111impl<'de> Deserialize<'de> for GatewayEvent {
1113 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
1114 let mut map = JsonMap::deserialize(deserializer)?;
1115 let seq = remove_from_map_opt(&mut map, "s")?.flatten();
1116
1117 Ok(match remove_from_map(&mut map, "op")? {
1118 Opcode::Dispatch => Self::Dispatch(
1119 seq.ok_or_else(|| DeError::missing_field("s"))?,
1120 deserialize_val(Value::from(map))?,
1121 ),
1122 Opcode::Heartbeat => {
1123 GatewayEvent::Heartbeat(0)
1126 },
1127 Opcode::InvalidSession => {
1128 GatewayEvent::InvalidateSession(remove_from_map(&mut map, "d")?)
1129 },
1130 Opcode::Hello => {
1131 #[derive(Deserialize)]
1132 struct HelloPayload {
1133 heartbeat_interval: u64,
1134 }
1135
1136 let inner: HelloPayload = remove_from_map(&mut map, "d")?;
1137 GatewayEvent::Hello(inner.heartbeat_interval)
1138 },
1139 Opcode::Reconnect => GatewayEvent::Reconnect,
1140 Opcode::HeartbeatAck => GatewayEvent::HeartbeatAck,
1141 _ => return Err(DeError::custom("invalid opcode")),
1142 })
1143 }
1144}
1145
1146#[allow(clippy::large_enum_variant)]
1150#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1151#[derive(Clone, Debug, Deserialize, Serialize)]
1152#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
1153#[serde(tag = "t", content = "d")]
1154#[non_exhaustive]
1155pub enum Event {
1156 #[serde(rename = "APPLICATION_COMMAND_PERMISSIONS_UPDATE")]
1163 CommandPermissionsUpdate(CommandPermissionsUpdateEvent),
1164 #[serde(rename = "AUTO_MODERATION_RULE_CREATE")]
1171 AutoModRuleCreate(AutoModRuleCreateEvent),
1172 #[serde(rename = "AUTO_MODERATION_RULE_UPDATE")]
1179 AutoModRuleUpdate(AutoModRuleUpdateEvent),
1180 #[serde(rename = "AUTO_MODERATION_RULE_DELETE")]
1187 AutoModRuleDelete(AutoModRuleDeleteEvent),
1188 #[serde(rename = "AUTO_MODERATION_ACTION_EXECUTION")]
1195 AutoModActionExecution(AutoModActionExecutionEvent),
1196 ChannelCreate(ChannelCreateEvent),
1202 ChannelDelete(ChannelDeleteEvent),
1208 ChannelPinsUpdate(ChannelPinsUpdateEvent),
1214 ChannelUpdate(ChannelUpdateEvent),
1220 GuildAuditLogEntryCreate(GuildAuditLogEntryCreateEvent),
1221 GuildBanAdd(GuildBanAddEvent),
1222 GuildBanRemove(GuildBanRemoveEvent),
1223 GuildCreate(GuildCreateEvent),
1224 GuildDelete(GuildDeleteEvent),
1225 GuildEmojisUpdate(GuildEmojisUpdateEvent),
1226 GuildIntegrationsUpdate(GuildIntegrationsUpdateEvent),
1227 GuildMemberAdd(GuildMemberAddEvent),
1228 GuildMemberRemove(GuildMemberRemoveEvent),
1229 GuildMemberUpdate(GuildMemberUpdateEvent),
1231 GuildMembersChunk(GuildMembersChunkEvent),
1232 GuildRoleCreate(GuildRoleCreateEvent),
1233 GuildRoleDelete(GuildRoleDeleteEvent),
1234 GuildRoleUpdate(GuildRoleUpdateEvent),
1235 GuildStickersUpdate(GuildStickersUpdateEvent),
1237 GuildUpdate(GuildUpdateEvent),
1238 InviteCreate(InviteCreateEvent),
1244 InviteDelete(InviteDeleteEvent),
1250 MessageCreate(MessageCreateEvent),
1251 MessageDelete(MessageDeleteEvent),
1252 MessageDeleteBulk(MessageDeleteBulkEvent),
1253 MessageUpdate(MessageUpdateEvent),
1255 PresenceUpdate(PresenceUpdateEvent),
1257 #[cfg_attr(not(ignore_serenity_deprecated), deprecated = "This event doesn't exist")]
1259 PresencesReplace(PresencesReplaceEvent),
1260 #[serde(rename = "MESSAGE_REACTION_ADD")]
1266 ReactionAdd(ReactionAddEvent),
1267 #[serde(rename = "MESSAGE_REACTION_REMOVE")]
1273 ReactionRemove(ReactionRemoveEvent),
1274 #[serde(rename = "MESSAGE_REACTION_REMOVE_ALL")]
1280 ReactionRemoveAll(ReactionRemoveAllEvent),
1281 #[serde(rename = "MESSAGE_REACTION_REMOVE_EMOJI")]
1287 ReactionRemoveEmoji(ReactionRemoveEmojiEvent),
1288 Ready(ReadyEvent),
1292 Resumed(ResumedEvent),
1294 TypingStart(TypingStartEvent),
1296 UserUpdate(UserUpdateEvent),
1298 VoiceStateUpdate(VoiceStateUpdateEvent),
1300 VoiceServerUpdate(VoiceServerUpdateEvent),
1302 VoiceChannelStatusUpdate(VoiceChannelStatusUpdateEvent),
1304 #[serde(rename = "WEBHOOKS_UPDATE")]
1306 WebhookUpdate(WebhookUpdateEvent),
1307 InteractionCreate(InteractionCreateEvent),
1309 IntegrationCreate(IntegrationCreateEvent),
1311 IntegrationUpdate(IntegrationUpdateEvent),
1313 IntegrationDelete(IntegrationDeleteEvent),
1315 StageInstanceCreate(StageInstanceCreateEvent),
1317 StageInstanceUpdate(StageInstanceUpdateEvent),
1319 StageInstanceDelete(StageInstanceDeleteEvent),
1321 ThreadCreate(ThreadCreateEvent),
1324 ThreadUpdate(ThreadUpdateEvent),
1326 ThreadDelete(ThreadDeleteEvent),
1328 ThreadListSync(ThreadListSyncEvent),
1330 ThreadMemberUpdate(ThreadMemberUpdateEvent),
1332 ThreadMembersUpdate(ThreadMembersUpdateEvent),
1334 GuildScheduledEventCreate(GuildScheduledEventCreateEvent),
1336 GuildScheduledEventUpdate(GuildScheduledEventUpdateEvent),
1338 GuildScheduledEventDelete(GuildScheduledEventDeleteEvent),
1340 GuildScheduledEventUserAdd(GuildScheduledEventUserAddEvent),
1342 GuildScheduledEventUserRemove(GuildScheduledEventUserRemoveEvent),
1344 EntitlementCreate(EntitlementCreateEvent),
1346 EntitlementUpdate(EntitlementUpdateEvent),
1348 EntitlementDelete(EntitlementDeleteEvent),
1350 MessagePollVoteAdd(MessagePollVoteAddEvent),
1352 MessagePollVoteRemove(MessagePollVoteRemoveEvent),
1354 #[serde(untagged)]
1356 Unknown(UnknownEvent),
1357}
1358
1359impl Event {
1360 #[must_use]
1363 pub fn name(&self) -> Option<String> {
1364 if let Self::Unknown(_) = self {
1365 None
1366 } else {
1367 let map = serde_json::to_value(self).ok()?;
1368 Some(map.get("t")?.as_str()?.to_string())
1369 }
1370 }
1371}