aboutsummaryrefslogtreecommitdiff
path: root/src/model/guild
diff options
context:
space:
mode:
authorMaiddog <[email protected]>2017-08-26 17:55:43 -0500
committeralex <[email protected]>2017-08-27 00:55:43 +0200
commit3e0b1032d80a1847558a752e8316d97f9ae58f04 (patch)
treeca65390091cb3c0ab98b6497a1447ba69df3d20d /src/model/guild
parentUse `$crate` for `Args` (diff)
downloadserenity-3e0b1032d80a1847558a752e8316d97f9ae58f04.tar.xz
serenity-3e0b1032d80a1847558a752e8316d97f9ae58f04.zip
Add ability to play DCA and Opus files. (#148)
Diffstat (limited to 'src/model/guild')
-rw-r--r--src/model/guild/audit_log.rs16
-rw-r--r--src/model/guild/guild_id.rs10
-rw-r--r--src/model/guild/integration.rs3
-rw-r--r--src/model/guild/member.rs35
-rw-r--r--src/model/guild/mod.rs68
-rw-r--r--src/model/guild/partial_guild.rs24
-rw-r--r--src/model/guild/role.rs7
7 files changed, 90 insertions, 73 deletions
diff --git a/src/model/guild/audit_log.rs b/src/model/guild/audit_log.rs
index 6c24662..962b145 100644
--- a/src/model/guild/audit_log.rs
+++ b/src/model/guild/audit_log.rs
@@ -91,9 +91,12 @@ 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)]
@@ -123,7 +126,7 @@ pub struct AuditLogEntry {
pub id: AuditLogEntryId,
}
-fn deserialize_target<'de, D: Deserializer<'de>>(de: D) -> Result<Target, D::Error>{
+fn deserialize_target<'de, D: Deserializer<'de>>(de: D) -> Result<Target, D::Error> {
struct TargetVisitor;
impl<'de> Visitor<'de> for TargetVisitor {
@@ -144,7 +147,7 @@ fn deserialize_target<'de, D: Deserializer<'de>>(de: D) -> Result<Target, D::Err
de.deserialize_i32(TargetVisitor)
}
-fn deserialize_action<'de, D: Deserializer<'de>>(de: D) -> Result<Action, D::Error>{
+fn deserialize_action<'de, D: Deserializer<'de>>(de: D) -> Result<Action, D::Error> {
struct ActionVisitor;
impl<'de> Visitor<'de> for ActionVisitor {
@@ -177,7 +180,8 @@ 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/guild_id.rs b/src/model/guild/guild_id.rs
index 02775ba..4d6ba9b 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -48,7 +48,7 @@ impl GuildId {
/// [`Guild::ban`]: struct.Guild.html#method.ban
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
-pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, ban_options: BO) -> Result<()>{
+ pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, ban_options: BO) -> Result<()> {
let dmd = ban_options.dmd();
if dmd > 7 {
return Err(Error::Model(ModelError::DeleteMessageDaysAmount(dmd)));
@@ -167,7 +167,7 @@ pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, ban_options: BO) ->
/// [`Guild::create_role`]: struct.Guild.html#method.create_role
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
#[inline]
-pub fn create_role<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role>{
+ pub fn create_role<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role> {
http::create_role(self.0, &f(EditRole::default()).0)
}
@@ -199,7 +199,7 @@ pub fn create_role<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role>
///
/// [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<()> {
http::delete_guild_integration(self.0, integration_id.into().0)
}
@@ -228,7 +228,7 @@ pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> R
/// [`Guild::edit`]: struct.Guild.html#method.edit
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
#[inline]
-pub fn edit<F: FnOnce(EditGuild) -> EditGuild>(&mut self, f: F) -> Result<PartialGuild>{
+ pub fn edit<F: FnOnce(EditGuild) -> EditGuild>(&mut self, f: F) -> Result<PartialGuild> {
http::edit_guild(self.0, &f(EditGuild::default()).0)
}
@@ -459,7 +459,7 @@ pub fn edit<F: FnOnce(EditGuild) -> EditGuild>(&mut self, f: F) -> Result<Partia
///
/// [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<()> {
http::start_integration_sync(self.0, integration_id.into().0)
}
diff --git a/src/model/guild/integration.rs b/src/model/guild/integration.rs
index b903a2c..18da39d 100644
--- a/src/model/guild/integration.rs
+++ b/src/model/guild/integration.rs
@@ -6,7 +6,8 @@ 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 370f555..f1a5114 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -168,10 +168,9 @@ 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.
@@ -179,10 +178,9 @@ 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.
@@ -204,7 +202,7 @@ impl Member {
/// [`Guild::edit_member`]: ../model/struct.Guild.html#method.edit_member
/// [`EditMember`]: ../builder/struct.EditMember.html
#[cfg(feature = "cache")]
-pub fn edit<F: FnOnce(EditMember) -> EditMember>(&self, f: F) -> Result<()>{
+ pub fn edit<F: FnOnce(EditMember) -> EditMember>(&self, f: F) -> Result<()> {
let map = f(EditMember::default()).0;
http::edit_member(self.guild_id.0, self.user.read().unwrap().id.0, &map)
@@ -248,12 +246,11 @@ pub fn edit<F: FnOnce(EditMember) -> EditMember>(&self, f: F) -> Result<()>{
{
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)));
@@ -288,10 +285,10 @@ pub fn edit<F: FnOnce(EditMember) -> EditMember>(&self, f: F) -> Result<()>{
let guild = guild.read().unwrap();
- Ok(
- guild
- .permissions_for(ChannelId(guild.id.0), self.user.read().unwrap().id),
- )
+ Ok(guild.permissions_for(
+ ChannelId(guild.id.0),
+ 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 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),
+ )
}
}
diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs
index 1690167..799f6b6 100644
--- a/src/model/guild/partial_guild.rs
+++ b/src/model/guild/partial_guild.rs
@@ -16,14 +16,16 @@ 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,
}
@@ -150,7 +152,7 @@ impl PartialGuild {
/// [`Guild::create_role`]: struct.Guild.html#method.create_role
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
#[inline]
-pub fn create_role<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role>{
+ pub fn create_role<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role> {
self.id.create_role(f)
}
@@ -178,7 +180,7 @@ pub fn create_role<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role>
///
/// [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)
}
@@ -315,9 +317,9 @@ pub fn delete_integration<I: Into<IntegrationId>>(&self, integration_id: I) -> R
/// 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.
@@ -417,9 +419,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.
@@ -428,7 +430,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)
}
diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs
index 5a6f75c..5956113 100644
--- a/src/model/guild/role.rs
+++ b/src/model/guild/role.rs
@@ -92,9 +92,10 @@ impl Role {
/// [`Role`]: struct.Role.html
/// [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))
+ 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),
+ )
}
/// Searches the cache for the guild that owns the role.