Skip to content

Commit

Permalink
Add Member::permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis authored and Zeyla Hellyer committed Jun 14, 2017
1 parent 32e07e4 commit 39a28d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/error.rs
Expand Up @@ -139,6 +139,12 @@ impl From<ParseIntError> for Error {
}
}

impl From<ModelError> for Error {
fn from(e: ModelError) -> Error {
Error::Model(e)
}
}

#[cfg(feature="voice")]
impl From<OpusError> for Error {
fn from(e: OpusError) -> Error {
Expand Down
27 changes: 27 additions & 0 deletions src/model/guild/member.rs
Expand Up @@ -218,6 +218,33 @@ impl Member {
self.guild_id.kick(self.user.read().unwrap().id)
}

/// Returns the permissions for the member.
///
/// # Examples
///
/// ```rust,ignore
/// // assuming there's a `member` variable gotten from anything.
/// println!("The permission bits for the member are: {}", member.permissions().expect("permissions").bits);
/// ```
///
/// # Errors
///
/// Returns a [`ModelError::GuildNotFound`] if the guild the member's in could not be
/// found in the cache.
///
/// [`ModelError::GuildNotFound`]: enum.ModelError.html#variant.GuildNotFound
#[cfg(feature="cache")]
pub fn permissions(&self) -> Result<Permissions> {
let guild = match self.guild_id.find() {
Some(guild) => guild,
None => return Err(From::from(ModelError::GuildNotFound)),
};

let guild = guild.read().unwrap();

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
/// request was successful.
///
Expand Down

0 comments on commit 39a28d3

Please sign in to comment.