Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/model/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct BotGateway {
#[non_exhaustive]
pub struct Activity {
/// The ID of the application for the activity.
#[serde(deserialize_with = "deserialize_buggy_id")]
pub application_id: Option<ApplicationId>,
/// Images for the presence and their texts.
pub assets: Option<ActivityAssets>,
Expand Down
12 changes: 12 additions & 0 deletions src/model/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::fmt;
use std::hash::Hash;
use std::marker::PhantomData;
use std::num::NonZeroU64;

use serde::ser::{Serialize, SerializeSeq, Serializer};

Expand Down Expand Up @@ -67,6 +68,17 @@ where
remove_from_map_opt(map, key)?.ok_or_else(|| serde::de::Error::missing_field(key))
}

/// Workaround for Discord sending 0 value Ids as default values.
/// This has been fixed properly on next by swapping to a NonMax based impl.
pub fn deserialize_buggy_id<'de, D, Id>(deserializer: D) -> StdResult<Option<Id>, D::Error>
where
D: Deserializer<'de>,
Id: From<NonZeroU64>,
{
let raw = Option::<u64>::deserialize(deserializer)?;
Ok(raw.and_then(NonZeroU64::new).map(Into::into))
}

/// Used with `#[serde(with = "emojis")]`
pub mod emojis {
use std::collections::HashMap;
Expand Down