Skip to content

Commit

Permalink
Implement UpdateMessage for GuildCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Sep 5, 2023
1 parent b3bbff5 commit f556997
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/types/events/guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@ use super::UpdateMessage;
#[cfg(feature = "client")]
use std::sync::{Arc, RwLock};

#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, SourceUrlField, JsonField)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-create>;
/// Received to give data about a guild;
// This one is particularly painful, it can be a Guild object with an extra field or an unavailable guild object
pub struct GuildCreate {
#[serde(flatten)]
pub d: GuildCreateDataOption,
#[serde(skip)]
pub source_url: String,
#[serde(skip)]
pub json: String,
}

impl UpdateMessage<Guild> for GuildCreate {
fn id(&self) -> Option<Snowflake> {
match &self.d {
GuildCreateDataOption::UnavailableGuild(unavailable) => Some(unavailable.id),
GuildCreateDataOption::Guild(guild) => Some(guild.id),
}
}

fn update(&mut self, _: Arc<RwLock<Guild>>) {}
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down

0 comments on commit f556997

Please sign in to comment.