diff options
| author | Zeyla Hellyer <[email protected]> | 2017-12-15 14:15:45 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-12-15 14:34:10 -0800 |
| commit | 8c9baa74c2716d62c405d909bb453ffea636c94d (patch) | |
| tree | b686b0913eb7e5e070207d441662e32df00ec8ed /src/model/guild | |
| parent | Add missing fields to Guild model (diff) | |
| download | serenity-8c9baa74c2716d62c405d909bb453ffea636c94d.tar.xz serenity-8c9baa74c2716d62c405d909bb453ffea636c94d.zip | |
Change type of a couple Guild/PartialGuild fields
Changes the types of `Guild` and `PartialGuild`'s
`default_message_notifications` and `mfa_level` structfields to be a bit
more type-strong.
Diffstat (limited to 'src/model/guild')
| -rw-r--r-- | src/model/guild/mod.rs | 46 | ||||
| -rw-r--r-- | src/model/guild/partial_guild.rs | 4 |
2 files changed, 44 insertions, 6 deletions
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index ea68572..b50988b 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -57,7 +57,7 @@ pub struct Guild { pub channels: HashMap<ChannelId, Arc<RwLock<GuildChannel>>>, /// Indicator of whether notifications for all messages are enabled by /// default in the guild. - pub default_message_notifications: u64, + pub default_message_notifications: DefaultMessageNotificationLevel, /// All of the guild's custom emojis. pub emojis: HashMap<EmojiId, Emoji>, /// Default explicit content filter level. @@ -102,7 +102,7 @@ pub struct Guild { /// /// [`Role`]: struct.Role.html /// [`User`]: struct.User.html - pub mfa_level: u64, + pub mfa_level: MfaLevel, /// The name of the guild. pub name: String, /// The Id of the [`User`] who owns the guild. @@ -1439,7 +1439,7 @@ impl<'de> Deserialize<'de> for Guild { .ok_or_else(|| { DeError::custom("expected guild default_message_notifications") }) - .and_then(u64::deserialize) + .and_then(DefaultMessageNotificationLevel::deserialize) .map_err(DeError::custom)?; let emojis = map.remove("emojis") .ok_or_else(|| DeError::custom("expected guild emojis")) @@ -1481,7 +1481,7 @@ impl<'de> Deserialize<'de> for Guild { .map_err(DeError::custom)?; let mfa_level = map.remove("mfa_level") .ok_or_else(|| DeError::custom("expected guild mfa_level")) - .and_then(u64::deserialize) + .and_then(MfaLevel::deserialize) .map_err(DeError::custom)?; let name = map.remove("name") .ok_or_else(|| DeError::custom("expected guild name")) @@ -1688,6 +1688,25 @@ impl GuildStatus { } enum_number!( + /// Default message notification level for a guild. + DefaultMessageNotificationLevel { + /// Receive notifications for everything. + All = 0, + /// Receive only mentions. + Mentions = 1, + } +); + +impl DefaultMessageNotificationLevel { + pub fn num(&self) -> u64 { + match *self { + DefaultMessageNotificationLevel::All => 0, + DefaultMessageNotificationLevel::Mentions => 1, + } + } +} + +enum_number!( /// Setting used to filter explicit messages from members. ExplicitContentFilter { /// Don't scan any messages. @@ -1710,6 +1729,25 @@ impl ExplicitContentFilter { } enum_number!( + /// Multi-Factor Authentication level for guild moderators. + MfaLevel { + /// MFA is disabled. + None = 0, + /// MFA is enabled. + Elevated = 1, + } +); + +impl MfaLevel { + pub fn num(&self) -> u64 { + match *self { + MfaLevel::None => 0, + MfaLevel::Elevated => 1, + } + } +} + +enum_number!( #[doc="The level to set as criteria prior to a user being able to send messages in a [`Guild`]. diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index c33c8d0..857ef0d 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -13,7 +13,7 @@ pub struct PartialGuild { pub id: GuildId, pub afk_channel_id: Option<ChannelId>, pub afk_timeout: u64, - pub default_message_notifications: u64, + pub default_message_notifications: DefaultMessageNotificationLevel, pub embed_channel_id: Option<ChannelId>, pub embed_enabled: bool, #[serde(deserialize_with = "deserialize_emojis")] pub emojis: HashMap<EmojiId, Emoji>, @@ -24,7 +24,7 @@ pub struct PartialGuild { /// [`Guild::features`]: struct.Guild.html#structfield.features pub features: Vec<String>, pub icon: Option<String>, - pub mfa_level: u64, + pub mfa_level: MfaLevel, pub name: String, pub owner_id: UserId, pub region: String, |