diff options
| author | Maiddog <[email protected]> | 2017-08-26 17:55:43 -0500 |
|---|---|---|
| committer | alex <[email protected]> | 2017-08-27 00:55:43 +0200 |
| commit | 3e0b1032d80a1847558a752e8316d97f9ae58f04 (patch) | |
| tree | ca65390091cb3c0ab98b6497a1447ba69df3d20d /src/model/guild/mod.rs | |
| parent | Use `$crate` for `Args` (diff) | |
| download | serenity-3e0b1032d80a1847558a752e8316d97f9ae58f04.tar.xz serenity-3e0b1032d80a1847558a752e8316d97f9ae58f04.zip | |
Add ability to play DCA and Opus files. (#148)
Diffstat (limited to 'src/model/guild/mod.rs')
| -rw-r--r-- | src/model/guild/mod.rs | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 7fdd7d4..5ffbf4e 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -168,7 +168,10 @@ impl Guild { None => return Err(Error::Model(ModelError::ItemMissing)), }; - let perms = self.permissions_for(default_channel.id, member.user.read().unwrap().id); + let perms = self.permissions_for( + default_channel.id, + member.user.read().unwrap().id, + ); permissions.remove(perms); Ok(permissions.is_empty()) @@ -442,7 +445,7 @@ impl Guild { /// /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html #[inline] -pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> Result<()>{ + pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> Result<()> { self.id.delete_integration(integration_id) } @@ -626,9 +629,9 @@ pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> R /// Returns the formatted URL of the guild's icon, if one exists. pub fn icon_url(&self) -> Option<String> { - self.icon - .as_ref() - .map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon)) + self.icon.as_ref().map( + |icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon), + ) } /// Gets all integration of the guild. @@ -706,8 +709,10 @@ pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> R for (&id, member) in &self.members { match self.presences.get(&id) { - Some(presence) => if status == presence.status { - members.push(member); + Some(presence) => { + if status == presence.status { + members.push(member); + } }, None => continue, } @@ -831,8 +836,8 @@ pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> R // If this is a text channel, then throw out voice permissions. if channel.kind == ChannelType::Text { - permissions &= - !(CONNECT | SPEAK | MUTE_MEMBERS | DEAFEN_MEMBERS | MOVE_MEMBERS | USE_VAD); + permissions &= !(CONNECT | SPEAK | MUTE_MEMBERS | DEAFEN_MEMBERS | MOVE_MEMBERS | + USE_VAD); } // Apply the permission overwrites for the channel for each of the @@ -958,9 +963,9 @@ pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> R /// Returns the formatted URL of the guild's splash image, if one exists. pub fn splash_url(&self) -> Option<String> { - self.icon - .as_ref() - .map(|icon| format!(cdn!("/splashes/{}/{}.webp"), self.id, icon)) + self.icon.as_ref().map( + |icon| format!(cdn!("/splashes/{}/{}.webp"), self.id, icon), + ) } /// Starts an integration sync for the given integration Id. @@ -969,7 +974,7 @@ pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> R /// /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html #[inline] -pub fn start_integration_sync<I: Into<IntegrationId>>(&self, integration_id: I) -> Result<()>{ + pub fn start_integration_sync<I: Into<IntegrationId>>(&self, integration_id: I) -> Result<()> { self.id.start_integration_sync(integration_id) } @@ -1039,16 +1044,18 @@ impl<'de> Deserialize<'de> for Guild { fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> { let mut map = JsonMap::deserialize(deserializer)?; - let id = map.get("id") - .and_then(|x| x.as_str()) - .and_then(|x| x.parse::<u64>().ok()); + let id = map.get("id").and_then(|x| x.as_str()).and_then(|x| { + x.parse::<u64>().ok() + }); if let Some(guild_id) = id { if let Some(array) = map.get_mut("channels").and_then(|x| x.as_array_mut()) { for value in array { if let Some(channel) = value.as_object_mut() { - channel - .insert("guild_id".to_owned(), Value::Number(Number::from(guild_id))); + channel.insert( + "guild_id".to_owned(), + Value::Number(Number::from(guild_id)), + ); } } } @@ -1056,16 +1063,21 @@ impl<'de> Deserialize<'de> for Guild { if let Some(array) = map.get_mut("members").and_then(|x| x.as_array_mut()) { for value in array { if let Some(member) = value.as_object_mut() { - member - .insert("guild_id".to_owned(), Value::Number(Number::from(guild_id))); + member.insert( + "guild_id".to_owned(), + Value::Number(Number::from(guild_id)), + ); } } } } let afk_channel_id = match map.remove("afk_channel_id") { - Some(v) => serde_json::from_value::<Option<ChannelId>>(v) - .map_err(DeError::custom)?, + Some(v) => { + serde_json::from_value::<Option<ChannelId>>(v).map_err( + DeError::custom, + )? + }, None => None, }; let afk_timeout = map.remove("afk_timeout") @@ -1217,9 +1229,9 @@ pub struct GuildInfo { impl GuildInfo { /// Returns the formatted URL of the guild's icon, if the guild has an icon. pub fn icon_url(&self) -> Option<String> { - self.icon - .as_ref() - .map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon)) + self.icon.as_ref().map( + |icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon), + ) } } @@ -1239,9 +1251,9 @@ impl From<u64> for GuildContainer { impl InviteGuild { /// Returns the formatted URL of the guild's splash image, if one exists. pub fn splash_url(&self) -> Option<String> { - self.icon - .as_ref() - .map(|icon| format!(cdn!("/splashes/{}/{}.webp"), self.id, icon)) + self.icon.as_ref().map( + |icon| format!(cdn!("/splashes/{}/{}.webp"), self.id, icon), + ) } } |