#![allow(clippy::option_option)]
use serde::de::Error as DeError;
use serde::Serialize;
use crate::constants::Opcode;
use crate::model::prelude::*;
use crate::model::utils::{
deserialize_val,
emojis,
members,
optional_deserialize_components,
remove_from_map,
remove_from_map_opt,
stickers,
};
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct CommandPermissionsUpdateEvent {
pub permission: CommandPermissions,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct AutoModRuleCreateEvent {
pub rule: Rule,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct AutoModRuleUpdateEvent {
pub rule: Rule,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct AutoModRuleDeleteEvent {
pub rule: Rule,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct AutoModActionExecutionEvent {
pub execution: ActionExecution,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ChannelCreateEvent {
pub channel: GuildChannel,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ChannelDeleteEvent {
pub channel: GuildChannel,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct ChannelPinsUpdateEvent {
pub guild_id: Option<GuildId>,
pub channel_id: ChannelId,
pub last_pin_timestamp: Option<Timestamp>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ChannelUpdateEvent {
pub channel: GuildChannel,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildAuditLogEntryCreateEvent {
pub guild_id: GuildId,
#[serde(flatten)]
pub entry: AuditLogEntry,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildBanAddEvent {
pub guild_id: GuildId,
pub user: User,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildBanRemoveEvent {
pub guild_id: GuildId,
pub user: User,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct GuildCreateEvent {
pub guild: Guild,
}
impl<'de> Deserialize<'de> for GuildCreateEvent {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
let mut guild: Guild = Guild::deserialize(deserializer)?;
guild.channels.values_mut().for_each(|x| x.guild_id = guild.id);
guild.members.values_mut().for_each(|x| x.guild_id = guild.id);
guild.roles.values_mut().for_each(|x| x.guild_id = guild.id);
Ok(Self {
guild,
})
}
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct GuildDeleteEvent {
pub guild: UnavailableGuild,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildEmojisUpdateEvent {
#[serde(with = "emojis")]
pub emojis: HashMap<EmojiId, Emoji>,
pub guild_id: GuildId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildIntegrationsUpdateEvent {
pub guild_id: GuildId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct GuildMemberAddEvent {
pub member: Member,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildMemberRemoveEvent {
pub guild_id: GuildId,
pub user: User,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildMemberUpdateEvent {
pub guild_id: GuildId,
pub nick: Option<String>,
pub joined_at: Timestamp,
pub roles: Vec<RoleId>,
pub user: User,
pub premium_since: Option<Timestamp>,
#[serde(default)]
pub pending: bool,
#[serde(default)]
pub deaf: bool,
#[serde(default)]
pub mute: bool,
pub avatar: Option<ImageHash>,
pub banner: Option<ImageHash>,
pub communication_disabled_until: Option<Timestamp>,
pub unusual_dm_activity_until: Option<Timestamp>,
pub flags: Option<GuildMemberFlags>,
pub avatar_decoration_data: Option<AvatarDecorationData>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(remote = "Self")]
#[non_exhaustive]
pub struct GuildMembersChunkEvent {
pub guild_id: GuildId,
#[serde(with = "members")]
pub members: HashMap<UserId, Member>,
pub chunk_index: u32,
pub chunk_count: u32,
#[serde(default)]
pub not_found: Vec<GenericId>,
pub presences: Option<Vec<Presence>>,
pub nonce: Option<String>,
}
impl<'de> Deserialize<'de> for GuildMembersChunkEvent {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
let mut event = Self::deserialize(deserializer)?; event.members.values_mut().for_each(|m| m.guild_id = event.guild_id);
Ok(event)
}
}
impl Serialize for GuildMembersChunkEvent {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> StdResult<S::Ok, S::Error> {
Self::serialize(self, serializer) }
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct SoundboardSoundsEvent {
pub guild_id: GuildId,
pub soundboard_sounds: Vec<Soundboard>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct SoundboardSoundCreateEvent {
pub soundboard: Soundboard,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct SoundboardSoundUpdateEvent {
pub soundboard: Soundboard,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct SoundboardSoundsUpdateEvent {
pub guild_id: GuildId,
pub soundboard_sounds: Vec<Soundboard>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct SoundboardSoundDeleteEvent {
pub guild_id: GuildId,
pub sound_id: SoundId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Deserialize)]
struct RoleEventHelper {
guild_id: GuildId,
role: Role,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub struct GuildRoleCreateEvent {
pub role: Role,
}
impl<'de> Deserialize<'de> for GuildRoleCreateEvent {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
let mut event = RoleEventHelper::deserialize(deserializer)?;
event.role.guild_id = event.guild_id;
Ok(Self {
role: event.role,
})
}
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildRoleDeleteEvent {
pub guild_id: GuildId,
pub role_id: RoleId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub struct GuildRoleUpdateEvent {
pub role: Role,
}
impl<'de> Deserialize<'de> for GuildRoleUpdateEvent {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
let mut event = RoleEventHelper::deserialize(deserializer)?;
event.role.guild_id = event.guild_id;
Ok(Self {
role: event.role,
})
}
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildStickersUpdateEvent {
#[serde(with = "stickers")]
pub stickers: HashMap<StickerId, Sticker>,
pub guild_id: GuildId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct InviteCreateEvent {
pub channel_id: ChannelId,
pub code: String,
pub created_at: Timestamp,
pub guild_id: Option<GuildId>,
pub inviter: Option<User>,
pub max_age: u32,
pub max_uses: u8,
pub target_type: Option<InviteTargetType>,
pub target_user: Option<User>,
pub target_application: Option<Value>,
pub temporary: bool,
pub uses: u64,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct InviteDeleteEvent {
pub channel_id: ChannelId,
pub guild_id: Option<GuildId>,
pub code: String,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct GuildUpdateEvent {
pub guild: PartialGuild,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct MessageCreateEvent {
pub message: Message,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct MessageDeleteBulkEvent {
pub guild_id: Option<GuildId>,
pub channel_id: ChannelId,
pub ids: Vec<MessageId>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct MessageDeleteEvent {
pub guild_id: Option<GuildId>,
pub channel_id: ChannelId,
#[serde(rename = "id")]
pub message_id: MessageId,
}
fn deserialize_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
where
T: Deserialize<'de>,
D: Deserializer<'de>,
{
Deserialize::deserialize(deserializer).map(Some)
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct MessageUpdateEvent {
pub id: MessageId,
pub channel_id: ChannelId,
pub author: Option<User>,
pub content: Option<String>,
pub timestamp: Option<Timestamp>,
pub edited_timestamp: Option<Timestamp>,
pub tts: Option<bool>,
pub mention_everyone: Option<bool>,
pub mentions: Option<Vec<User>>,
pub mention_roles: Option<Vec<RoleId>>,
pub mention_channels: Option<Vec<ChannelMention>>,
pub attachments: Option<Vec<Attachment>>,
pub embeds: Option<Vec<Embed>>,
pub reactions: Option<Vec<MessageReaction>>,
pub pinned: Option<bool>,
#[serde(default, deserialize_with = "deserialize_some")]
pub webhook_id: Option<Option<WebhookId>>,
#[serde(rename = "type")]
pub kind: Option<MessageType>,
#[serde(default, deserialize_with = "deserialize_some")]
pub activity: Option<Option<MessageActivity>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub application: Option<Option<MessageApplication>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub application_id: Option<Option<ApplicationId>>,
pub message_reference: Option<Option<MessageReference>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub flags: Option<Option<MessageFlags>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub referenced_message: Option<Option<Box<Message>>>,
#[cfg_attr(not(ignore_serenity_deprecated), deprecated = "Use interaction_metadata")]
#[serde(default, deserialize_with = "deserialize_some")]
pub interaction: Option<Option<Box<MessageInteraction>>>,
pub interaction_metadata: Option<Option<Box<MessageInteractionMetadata>>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub thread: Option<Option<GuildChannel>>,
#[serde(default, deserialize_with = "optional_deserialize_components")]
pub components: Option<Vec<ActionRow>>,
pub sticker_items: Option<Vec<StickerItem>>,
pub position: Option<Option<u64>>,
pub role_subscription_data: Option<Option<RoleSubscriptionData>>,
pub guild_id: Option<GuildId>,
pub member: Option<Option<Box<PartialMember>>>,
}
impl MessageUpdateEvent {
#[allow(clippy::clone_on_copy)] #[rustfmt::skip]
pub fn apply_to_message(&self, message: &mut Message) {
#[allow(deprecated)] let Self {
id,
channel_id,
author,
content,
timestamp,
edited_timestamp,
tts,
mention_everyone,
mentions,
mention_roles,
mention_channels,
attachments,
embeds,
reactions,
pinned,
webhook_id,
kind,
activity,
application,
application_id,
message_reference,
flags,
referenced_message,
interaction,
interaction_metadata,
thread,
components,
sticker_items,
position,
role_subscription_data,
guild_id,
member,
} = self;
message.id = *id;
message.channel_id = *channel_id;
if let Some(x) = author { message.author = x.clone() }
if let Some(x) = content { message.content.clone_from(x) }
if let Some(x) = timestamp { message.timestamp = x.clone() }
message.edited_timestamp = *edited_timestamp;
if let Some(x) = tts { message.tts = x.clone() }
if let Some(x) = mention_everyone { message.mention_everyone = x.clone() }
if let Some(x) = mentions { message.mentions.clone_from(x) }
if let Some(x) = mention_roles { message.mention_roles.clone_from(x) }
if let Some(x) = mention_channels { message.mention_channels.clone_from(x) }
if let Some(x) = attachments { message.attachments.clone_from(x) }
if let Some(x) = embeds { message.embeds.clone_from(x) }
if let Some(x) = reactions { message.reactions.clone_from(x) }
if let Some(x) = pinned { message.pinned = x.clone() }
if let Some(x) = webhook_id { message.webhook_id.clone_from(x) }
if let Some(x) = kind { message.kind = x.clone() }
if let Some(x) = activity { message.activity.clone_from(x) }
if let Some(x) = application { message.application.clone_from(x) }
if let Some(x) = application_id { message.application_id.clone_from(x) }
if let Some(x) = message_reference { message.message_reference.clone_from(x) }
if let Some(x) = flags { message.flags.clone_from(x) }
if let Some(x) = referenced_message { message.referenced_message.clone_from(x) }
if let Some(x) = interaction { message.interaction.clone_from(x) }
if let Some(x) = interaction_metadata { message.interaction_metadata.clone_from(x) }
if let Some(x) = thread { message.thread.clone_from(x) }
if let Some(x) = components { message.components.clone_from(x) }
if let Some(x) = sticker_items { message.sticker_items.clone_from(x) }
if let Some(x) = position { message.position.clone_from(x) }
if let Some(x) = role_subscription_data { message.role_subscription_data.clone_from(x) }
message.guild_id = *guild_id;
if let Some(x) = member { message.member.clone_from(x) }
}
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct PresenceUpdateEvent {
pub presence: Presence,
}
#[cfg_attr(not(ignore_serenity_deprecated), deprecated = "This event doesn't exist")]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct PresencesReplaceEvent {
pub presences: Vec<Presence>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ReactionAddEvent {
pub reaction: Reaction,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ReactionRemoveEvent {
pub reaction: Reaction,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct ReactionRemoveAllEvent {
pub channel_id: ChannelId,
pub message_id: MessageId,
pub guild_id: Option<GuildId>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ReactionRemoveEmojiEvent {
pub reaction: Reaction,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ReadyEvent {
pub ready: Ready,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct ResumedEvent {}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct TypingStartEvent {
pub channel_id: ChannelId,
pub guild_id: Option<GuildId>,
pub user_id: UserId,
pub timestamp: u64,
pub member: Option<Member>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct UnknownEvent {
#[serde(rename = "t")]
pub kind: String,
#[serde(rename = "d")]
pub value: Value,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct UserUpdateEvent {
pub current_user: CurrentUser,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct VoiceServerUpdateEvent {
pub token: String,
pub guild_id: Option<GuildId>,
pub endpoint: Option<String>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct VoiceStateUpdateEvent {
pub voice_state: VoiceState,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct VoiceChannelStatusUpdateEvent {
pub status: Option<String>,
pub id: ChannelId,
pub guild_id: GuildId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct WebhookUpdateEvent {
pub channel_id: ChannelId,
pub guild_id: GuildId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct InteractionCreateEvent {
pub interaction: Interaction,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct IntegrationCreateEvent {
pub integration: Integration,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct IntegrationUpdateEvent {
pub integration: Integration,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IntegrationDeleteEvent {
pub id: IntegrationId,
pub guild_id: GuildId,
pub application_id: Option<ApplicationId>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct StageInstanceCreateEvent {
pub stage_instance: StageInstance,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct StageInstanceUpdateEvent {
pub stage_instance: StageInstance,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct StageInstanceDeleteEvent {
pub stage_instance: StageInstance,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ThreadCreateEvent {
pub thread: GuildChannel,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ThreadUpdateEvent {
pub thread: GuildChannel,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ThreadDeleteEvent {
pub thread: PartialGuildChannel,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct ThreadListSyncEvent {
pub guild_id: GuildId,
pub channel_ids: Option<Vec<ChannelId>>,
pub threads: Vec<GuildChannel>,
pub members: Vec<ThreadMember>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct ThreadMemberUpdateEvent {
pub member: ThreadMember,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct ThreadMembersUpdateEvent {
pub id: ChannelId,
pub guild_id: GuildId,
pub member_count: i16,
#[serde(default)]
pub added_members: Vec<ThreadMember>,
#[serde(default)]
pub removed_member_ids: Vec<UserId>,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct GuildScheduledEventCreateEvent {
pub event: ScheduledEvent,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct GuildScheduledEventUpdateEvent {
pub event: ScheduledEvent,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct GuildScheduledEventDeleteEvent {
pub event: ScheduledEvent,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildScheduledEventUserAddEvent {
#[serde(rename = "guild_scheduled_event_id")]
pub scheduled_event_id: ScheduledEventId,
pub user_id: UserId,
pub guild_id: GuildId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct GuildScheduledEventUserRemoveEvent {
#[serde(rename = "guild_scheduled_event_id")]
pub scheduled_event_id: ScheduledEventId,
pub user_id: UserId,
pub guild_id: GuildId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct EntitlementCreateEvent {
pub entitlement: Entitlement,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct EntitlementUpdateEvent {
pub entitlement: Entitlement,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(transparent)]
#[non_exhaustive]
pub struct EntitlementDeleteEvent {
pub entitlement: Entitlement,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct MessagePollVoteAddEvent {
pub user_id: UserId,
pub channel_id: ChannelId,
pub message_id: MessageId,
pub guild_id: Option<GuildId>,
pub answer_id: AnswerId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct MessagePollVoteRemoveEvent {
pub user_id: UserId,
pub channel_id: ChannelId,
pub message_id: MessageId,
pub guild_id: Option<GuildId>,
pub answer_id: AnswerId,
}
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, Serialize)]
#[non_exhaustive]
#[serde(untagged)]
pub enum GatewayEvent {
Dispatch(u64, Event),
Heartbeat(#[deprecated = "always 0 because it is never provided by the gateway"] u64),
Reconnect,
InvalidateSession(bool),
Hello(u64),
HeartbeatAck,
}
impl<'de> Deserialize<'de> for GatewayEvent {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
let mut map = JsonMap::deserialize(deserializer)?;
let seq = remove_from_map_opt(&mut map, "s")?.flatten();
Ok(match remove_from_map(&mut map, "op")? {
Opcode::Dispatch => Self::Dispatch(
seq.ok_or_else(|| DeError::missing_field("s"))?,
deserialize_val(Value::from(map))?,
),
Opcode::Heartbeat => {
GatewayEvent::Heartbeat(0)
},
Opcode::InvalidSession => {
GatewayEvent::InvalidateSession(remove_from_map(&mut map, "d")?)
},
Opcode::Hello => {
#[derive(Deserialize)]
struct HelloPayload {
heartbeat_interval: u64,
}
let inner: HelloPayload = remove_from_map(&mut map, "d")?;
GatewayEvent::Hello(inner.heartbeat_interval)
},
Opcode::Reconnect => GatewayEvent::Reconnect,
Opcode::HeartbeatAck => GatewayEvent::HeartbeatAck,
_ => return Err(DeError::custom("invalid opcode")),
})
}
}
#[allow(clippy::large_enum_variant)]
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[serde(tag = "t", content = "d")]
#[non_exhaustive]
pub enum Event {
#[serde(rename = "APPLICATION_COMMAND_PERMISSIONS_UPDATE")]
CommandPermissionsUpdate(CommandPermissionsUpdateEvent),
#[serde(rename = "AUTO_MODERATION_RULE_CREATE")]
AutoModRuleCreate(AutoModRuleCreateEvent),
#[serde(rename = "AUTO_MODERATION_RULE_UPDATE")]
AutoModRuleUpdate(AutoModRuleUpdateEvent),
#[serde(rename = "AUTO_MODERATION_RULE_DELETE")]
AutoModRuleDelete(AutoModRuleDeleteEvent),
#[serde(rename = "AUTO_MODERATION_ACTION_EXECUTION")]
AutoModActionExecution(AutoModActionExecutionEvent),
ChannelCreate(ChannelCreateEvent),
ChannelDelete(ChannelDeleteEvent),
ChannelPinsUpdate(ChannelPinsUpdateEvent),
ChannelUpdate(ChannelUpdateEvent),
GuildAuditLogEntryCreate(GuildAuditLogEntryCreateEvent),
GuildBanAdd(GuildBanAddEvent),
GuildBanRemove(GuildBanRemoveEvent),
GuildCreate(GuildCreateEvent),
GuildDelete(GuildDeleteEvent),
GuildEmojisUpdate(GuildEmojisUpdateEvent),
GuildIntegrationsUpdate(GuildIntegrationsUpdateEvent),
GuildMemberAdd(GuildMemberAddEvent),
GuildMemberRemove(GuildMemberRemoveEvent),
GuildMemberUpdate(GuildMemberUpdateEvent),
GuildMembersChunk(GuildMembersChunkEvent),
GuildRoleCreate(GuildRoleCreateEvent),
GuildRoleDelete(GuildRoleDeleteEvent),
GuildRoleUpdate(GuildRoleUpdateEvent),
GuildStickersUpdate(GuildStickersUpdateEvent),
GuildUpdate(GuildUpdateEvent),
InviteCreate(InviteCreateEvent),
InviteDelete(InviteDeleteEvent),
MessageCreate(MessageCreateEvent),
MessageDelete(MessageDeleteEvent),
MessageDeleteBulk(MessageDeleteBulkEvent),
MessageUpdate(MessageUpdateEvent),
PresenceUpdate(PresenceUpdateEvent),
#[cfg_attr(not(ignore_serenity_deprecated), deprecated = "This event doesn't exist")]
PresencesReplace(PresencesReplaceEvent),
#[serde(rename = "MESSAGE_REACTION_ADD")]
ReactionAdd(ReactionAddEvent),
#[serde(rename = "MESSAGE_REACTION_REMOVE")]
ReactionRemove(ReactionRemoveEvent),
#[serde(rename = "MESSAGE_REACTION_REMOVE_ALL")]
ReactionRemoveAll(ReactionRemoveAllEvent),
#[serde(rename = "MESSAGE_REACTION_REMOVE_EMOJI")]
ReactionRemoveEmoji(ReactionRemoveEmojiEvent),
Ready(ReadyEvent),
Resumed(ResumedEvent),
SoundboardSounds(SoundboardSoundsEvent),
#[serde(rename = "GUILD_SOUNDBOARD_SOUND_CREATE")]
SoundboardSoundCreate(SoundboardSoundCreateEvent),
#[serde(rename = "GUILD_SOUNDBOARD_SOUND_UPDATE")]
SoundboardSoundUpdate(SoundboardSoundUpdateEvent),
#[serde(rename = "GUILD_SOUNDBOARD_SOUNDS_UPDATE")]
SoundboardSoundsUpdate(SoundboardSoundsUpdateEvent),
#[serde(rename = "GUILD_SOUNDBOARD_SOUND_DELETE")]
SoundboardSoundDelete(SoundboardSoundDeleteEvent),
TypingStart(TypingStartEvent),
UserUpdate(UserUpdateEvent),
VoiceStateUpdate(VoiceStateUpdateEvent),
VoiceServerUpdate(VoiceServerUpdateEvent),
VoiceChannelStatusUpdate(VoiceChannelStatusUpdateEvent),
#[serde(rename = "WEBHOOKS_UPDATE")]
WebhookUpdate(WebhookUpdateEvent),
InteractionCreate(InteractionCreateEvent),
IntegrationCreate(IntegrationCreateEvent),
IntegrationUpdate(IntegrationUpdateEvent),
IntegrationDelete(IntegrationDeleteEvent),
StageInstanceCreate(StageInstanceCreateEvent),
StageInstanceUpdate(StageInstanceUpdateEvent),
StageInstanceDelete(StageInstanceDeleteEvent),
ThreadCreate(ThreadCreateEvent),
ThreadUpdate(ThreadUpdateEvent),
ThreadDelete(ThreadDeleteEvent),
ThreadListSync(ThreadListSyncEvent),
ThreadMemberUpdate(ThreadMemberUpdateEvent),
ThreadMembersUpdate(ThreadMembersUpdateEvent),
GuildScheduledEventCreate(GuildScheduledEventCreateEvent),
GuildScheduledEventUpdate(GuildScheduledEventUpdateEvent),
GuildScheduledEventDelete(GuildScheduledEventDeleteEvent),
GuildScheduledEventUserAdd(GuildScheduledEventUserAddEvent),
GuildScheduledEventUserRemove(GuildScheduledEventUserRemoveEvent),
EntitlementCreate(EntitlementCreateEvent),
EntitlementUpdate(EntitlementUpdateEvent),
EntitlementDelete(EntitlementDeleteEvent),
MessagePollVoteAdd(MessagePollVoteAddEvent),
MessagePollVoteRemove(MessagePollVoteRemoveEvent),
#[serde(untagged)]
Unknown(UnknownEvent),
}
impl Event {
#[must_use]
pub fn name(&self) -> Option<String> {
if let Self::Unknown(_) = self {
None
} else {
let map = serde_json::to_value(self).ok()?;
Some(map.get("t")?.as_str()?.to_string())
}
}
}