Skip to content

Commit

Permalink
Update Guild::ban to use BanOptions
Browse files Browse the repository at this point in the history
Also update `Member::permissions` to the default channel change
  • Loading branch information
arqunis committed Sep 6, 2017
1 parent 619a91d commit 421c709
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/model/guild/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,11 @@ impl Member {
///
/// Returns a [`ModelError::GuildNotFound`] if the guild the member's in could not be
/// found in the cache.
///
/// And/or returns [`ModelError::ItemMissing`] if the "default channel" of the guild is not found.
///
/// [`ModelError::GuildNotFound`]: enum.ModelError.html#variant.GuildNotFound
/// [`ModelError::ItemMissing`]: enum.ModelError.html#variant.ItemMissing
#[cfg(feature = "cache")]
pub fn permissions(&self) -> Result<Permissions> {
let guild = match self.guild_id.find() {
Expand All @@ -285,8 +288,13 @@ impl Member {

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

let default_channel = match guild.default_channel() {
Some(dc) => dc,
None => return Err(From::from(ModelError::ItemMissing)),
};

Ok(guild.permissions_for(
ChannelId(guild.id.0),
default_channel.id,
self.user.read().unwrap().id,
))
}
Expand Down
10 changes: 2 additions & 8 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,7 @@ impl Guild {
/// [`Guild::ban`]: struct.Guild.html#method.ban
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
pub fn ban<U: Into<UserId>>(&self, user: U, delete_message_days: u8) -> Result<()> {
if delete_message_days > 7 {
return Err(Error::Model(
ModelError::DeleteMessageDaysAmount(delete_message_days),
));
}

pub fn ban<U: Into<UserId>, BO: BanOptions>(&self, user: U, options: BO) -> Result<()> {
#[cfg(feature = "cache")]
{
let req = permissions::BAN_MEMBERS;
Expand All @@ -223,7 +217,7 @@ impl Guild {
}
}

self.id.ban(user, delete_message_days)
self.id.ban(user, options)
}

/// Retrieves a list of [`Ban`]s for the guild.
Expand Down

0 comments on commit 421c709

Please sign in to comment.