Skip to content

Commit

Permalink
fix event deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
rksm committed Jun 1, 2023
1 parent c1ece76 commit 1ac78cb
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 2 deletions.
16 changes: 14 additions & 2 deletions twilight-gateway/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ impl Display for ProcessError {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match &self.kind {
ProcessErrorType::Deserializing { event } => {
f.write_str("gateway event could not be deserialized: event=")?;
f.write_str("gateway event could not be deserialized: source=")?;
if let Some(source) = &self.source {
Display::fmt(source, f)?;
} else {
f.write_str("None")?;
}
f.write_str(", event=")?;
f.write_str(event)
}
ProcessErrorType::SendingMessage => {
Expand Down Expand Up @@ -161,7 +167,13 @@ impl Display for ReceiveMessageError {
f.write_str("binary message could not be decompressed")
}
ReceiveMessageErrorType::Deserializing { ref event } => {
f.write_str("gateway event could not be deserialized: event=")?;
f.write_str("gateway event could not be deserialized: source=")?;
if let Some(source) = &self.source {
Display::fmt(source, f)?;
} else {
f.write_str("None")?;
}
f.write_str(", event=")?;
f.write_str(event)
}
ReceiveMessageErrorType::FatallyClosed { close_code } => {
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/application/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct Command {
pub description_localizations: Option<HashMap<String, String>>,
/// Guild ID of the command, if not global.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<Id<CommandMarker>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use serde::{Deserialize, Serialize};
pub struct CommandData {
/// ID of the guild the command is registered to.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// ID of the command.
pub id: Id<CommandMarker>,
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/application/interaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct Interaction {
pub data: Option<InteractionData>,
/// ID of the guild the interaction was invoked in.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// Guild’s preferred locale.
///
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/channel/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub struct Message {
///
/// [`Guild`]: crate::guild::Guild
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// Id of the message.
pub id: Id<MessageMarker>,
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/channel/message/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct MessageReference {
pub channel_id: Option<Id<ChannelMarker>>,
/// Originating message's guild ID.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// Originating message's ID.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/channel/message/sticker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Sticker {
pub format_type: StickerFormatType,
/// ID of the guild that owns the sticker.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// Unique ID of the sticker.
pub id: Id<StickerMarker>,
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub struct Channel {
pub flags: Option<ChannelFlags>,
/// ID of the guild the channel is in.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// Hash of the channel's icon.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/channel/webhook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Webhook {
pub avatar: Option<ImageHash>,
pub channel_id: Id<ChannelMarker>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
pub id: Id<WebhookMarker>,
#[serde(default = "WebhookType::default", rename = "type")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
pub struct MessageDelete {
pub channel_id: Id<ChannelMarker>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
pub id: Id<MessageMarker>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
pub struct MessageDeleteBulk {
pub channel_id: Id<ChannelMarker>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
pub ids: Vec<Id<MessageMarker>>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct MessageUpdate {
#[serde(skip_serializing_if = "Option::is_none")]
pub embeds: Option<Vec<Embed>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
pub id: Id<MessageMarker>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ pub struct ReactionRemoveAll {
pub channel_id: Id<ChannelMarker>,
pub message_id: Id<MessageMarker>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize};
pub struct TypingStart {
pub channel_id: Id<ChannelMarker>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub member: Option<Member>,
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/gateway/presence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(crate) struct PresenceIntermediary {
#[serde(default)]
pub activities: Vec<Activity>,
pub client_status: ClientStatus,
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
pub nick: Option<String>,
pub status: Status,
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/gateway/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
pub struct GatewayReaction {
pub channel_id: Id<ChannelMarker>,
pub emoji: ReactionType,
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
pub member: Option<Member>,
pub message_id: Id<MessageMarker>,
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/guild/audit_log/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct AuditLogEntry {
///
/// [`GuildAuditLogEntryCreate`]: crate::gateway::payload::incoming::GuildAuditLogEntryCreate
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// ID of the entire entry.
pub id: Id<AuditLogEntryMarker>,
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/guild/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct GuildIntegration {
#[serde(skip_serializing_if = "Option::is_none")]
pub expire_grace_period: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
pub id: Id<IntegrationMarker>,
#[serde(rename = "type")]
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/oauth/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Application {
pub custom_install_url: Option<String>,
/// Description of the application.
pub description: String,
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// Public flags of the application.
pub flags: Option<ApplicationFlags>,
Expand Down
1 change: 1 addition & 0 deletions twilight-model/src/voice/voice_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct VoiceState {
pub deaf: bool,
/// Guild this voice state is for.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub guild_id: Option<Id<GuildMarker>>,
/// Member this voice state is for.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down

0 comments on commit 1ac78cb

Please sign in to comment.