aboutsummaryrefslogtreecommitdiff
path: root/src/model/guild
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-09-18 17:48:52 -0700
committerZeyla Hellyer <[email protected]>2017-09-18 17:48:52 -0700
commitdae2cb77b407044f44a7a2790d93efba3891854e (patch)
treebef263c4490536cf8b56e988e71dd1aa43bc2696 /src/model/guild
parentFix compiles of a variety of feature combinations (diff)
downloadserenity-dae2cb77b407044f44a7a2790d93efba3891854e.tar.xz
serenity-dae2cb77b407044f44a7a2790d93efba3891854e.zip
Apply rustfmt
Diffstat (limited to 'src/model/guild')
-rw-r--r--src/model/guild/audit_log.rs12
-rw-r--r--src/model/guild/integration.rs3
-rw-r--r--src/model/guild/member.rs33
-rw-r--r--src/model/guild/mod.rs90
-rw-r--r--src/model/guild/partial_guild.rs18
-rw-r--r--src/model/guild/role.rs5
6 files changed, 75 insertions, 86 deletions
diff --git a/src/model/guild/audit_log.rs b/src/model/guild/audit_log.rs
index 962b145..d019b61 100644
--- a/src/model/guild/audit_log.rs
+++ b/src/model/guild/audit_log.rs
@@ -91,12 +91,9 @@ pub enum ActionEmoji {
#[derive(Debug, Deserialize)]
pub struct Change {
- #[serde(rename = "key")]
- pub name: String,
- #[serde(rename = "old_value")]
- pub old: String,
- #[serde(rename = "new_value")]
- pub new: String,
+ #[serde(rename = "key")] pub name: String,
+ #[serde(rename = "old_value")] pub old: String,
+ #[serde(rename = "new_value")] pub new: String,
}
#[derive(Debug)]
@@ -180,8 +177,7 @@ impl<'de> Deserialize<'de> for AuditLogs {
#[derive(Deserialize)]
#[serde(field_identifier)]
enum Field {
- #[serde(rename = "audit_log_entries")]
- Entries,
+ #[serde(rename = "audit_log_entries")] Entries,
}
struct EntriesVisitor;
diff --git a/src/model/guild/integration.rs b/src/model/guild/integration.rs
index 18da39d..b903a2c 100644
--- a/src/model/guild/integration.rs
+++ b/src/model/guild/integration.rs
@@ -6,8 +6,7 @@ pub struct Integration {
pub id: IntegrationId,
pub account: IntegrationAccount,
pub enabled: bool,
- #[serde(rename = "expire_behaviour")]
- pub expire_behaviour: u64,
+ #[serde(rename = "expire_behaviour")] pub expire_behaviour: u64,
pub expire_grace_period: u64,
pub kind: String,
pub name: String,
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index fcd2ccd..3e8ae64 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -168,9 +168,10 @@ impl Member {
let default = Colour::default();
- roles.iter().find(|r| r.colour.0 != default.0).map(
- |r| r.colour,
- )
+ roles
+ .iter()
+ .find(|r| r.colour.0 != default.0)
+ .map(|r| r.colour)
}
/// Calculates the member's display name.
@@ -178,9 +179,10 @@ impl Member {
/// The nickname takes priority over the member's username if it exists.
#[inline]
pub fn display_name(&self) -> Cow<String> {
- self.nick.as_ref().map(Cow::Borrowed).unwrap_or_else(|| {
- Cow::Owned(self.user.read().unwrap().name.clone())
- })
+ self.nick
+ .as_ref()
+ .map(Cow::Borrowed)
+ .unwrap_or_else(|| Cow::Owned(self.user.read().unwrap().name.clone()))
}
/// Returns the DiscordTag of a Member, taking possible nickname into account.
@@ -246,11 +248,12 @@ impl Member {
{
let req = permissions::KICK_MEMBERS;
- let has_perms = CACHE.read().unwrap().guilds.get(&self.guild_id).map(
- |guild| {
- guild.read().unwrap().has_perms(req)
- },
- );
+ let has_perms = CACHE
+ .read()
+ .unwrap()
+ .guilds
+ .get(&self.guild_id)
+ .map(|guild| guild.read().unwrap().has_perms(req));
if let Some(Ok(false)) = has_perms {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
@@ -294,10 +297,10 @@ impl Member {
None => return Err(From::from(ModelError::ItemMissing)),
};
- Ok(guild.permissions_for(
- default_channel.id,
- self.user.read().unwrap().id,
- ))
+ Ok(
+ guild
+ .permissions_for(default_channel.id, self.user.read().unwrap().id),
+ )
}
/// Removes a [`Role`] from the member, editing its roles in-place if the
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index b4b0461..b668875 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -168,10 +168,7 @@ 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())
@@ -607,9 +604,9 @@ impl Guild {
/// 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.
@@ -687,10 +684,8 @@ impl Guild {
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,
}
@@ -777,9 +772,11 @@ impl Guild {
let everyone = match self.roles.get(&RoleId(self.id.0)) {
Some(everyone) => everyone,
None => {
- error!("(╯°□°)╯︵ ┻━┻ @everyone role ({}) missing in '{}'",
- self.id,
- self.name);
+ error!(
+ "(╯°□°)╯︵ ┻━┻ @everyone role ({}) missing in '{}'",
+ self.id,
+ self.name
+ );
return Permissions::empty();
},
@@ -797,10 +794,12 @@ impl Guild {
if let Some(role) = self.roles.get(&role) {
permissions |= role.permissions;
} else {
- warn!("(╯°□°)╯︵ ┻━┻ {} on {} has non-existent role {:?}",
- member.user.read().unwrap().id,
- self.id,
- role);
+ warn!(
+ "(╯°□°)╯︵ ┻━┻ {} on {} has non-existent role {:?}",
+ member.user.read().unwrap().id,
+ self.id,
+ role
+ );
}
}
@@ -814,8 +813,8 @@ impl Guild {
// 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
@@ -845,9 +844,11 @@ impl Guild {
permissions = (permissions & !overwrite.deny) | overwrite.allow;
}
} else {
- warn!("(╯°□°)╯︵ ┻━┻ Guild {} does not contain channel {}",
- self.id,
- channel_id);
+ warn!(
+ "(╯°□°)╯︵ ┻━┻ Guild {} does not contain channel {}",
+ self.id,
+ channel_id
+ );
}
// The default channel is always readable.
@@ -941,9 +942,9 @@ impl Guild {
/// 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.
@@ -1057,18 +1058,16 @@ 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)));
}
}
}
@@ -1076,21 +1075,16 @@ 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")
@@ -1242,9 +1236,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))
}
}
@@ -1264,9 +1258,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))
}
}
diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs
index 02cdbf5..cb2f8ef 100644
--- a/src/model/guild/partial_guild.rs
+++ b/src/model/guild/partial_guild.rs
@@ -16,16 +16,14 @@ pub struct PartialGuild {
pub default_message_notifications: u64,
pub embed_channel_id: Option<ChannelId>,
pub embed_enabled: bool,
- #[serde(deserialize_with = "deserialize_emojis")]
- pub emojis: HashMap<EmojiId, Emoji>,
+ #[serde(deserialize_with = "deserialize_emojis")] pub emojis: HashMap<EmojiId, Emoji>,
pub features: Vec<Feature>,
pub icon: Option<String>,
pub mfa_level: u64,
pub name: String,
pub owner_id: UserId,
pub region: String,
- #[serde(deserialize_with = "deserialize_roles")]
- pub roles: HashMap<RoleId, Role>,
+ #[serde(deserialize_with = "deserialize_roles")] pub roles: HashMap<RoleId, Role>,
pub splash: Option<String>,
pub verification_level: VerificationLevel,
}
@@ -301,9 +299,9 @@ impl PartialGuild {
/// Returns a 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))
}
/// Gets all integration of the guild.
@@ -403,9 +401,9 @@ impl PartialGuild {
/// 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.
diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs
index 4b61736..e097311 100644
--- a/src/model/guild/role.rs
+++ b/src/model/guild/role.rs
@@ -93,9 +93,8 @@ impl Role {
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
#[cfg(all(feature = "builder", feature = "cache"))]
pub fn edit<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role> {
- self.find_guild().and_then(
- |guild_id| guild_id.edit_role(self.id, f),
- )
+ self.find_guild()
+ .and_then(|guild_id| guild_id.edit_role(self.id, f))
}
/// Searches the cache for the guild that owns the role.