aboutsummaryrefslogtreecommitdiff
path: root/src/model/guild/mod.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-10-30 10:14:16 -0700
committerZeyla Hellyer <[email protected]>2017-10-30 10:19:24 -0700
commit1b7101fe71335c0e18bf855c0703acc23d87e427 (patch)
tree20d72c82fd735f61cac834d0584593f7c850f3f0 /src/model/guild/mod.rs
parentAdd Guild::member_permissions (diff)
downloadserenity-1b7101fe71335c0e18bf855c0703acc23d87e427.tar.xz
serenity-1b7101fe71335c0e18bf855c0703acc23d87e427.zip
Guild::has_perms: use Guild::member_permissions
Make `Guild`'s internal method `has_perms` go through `Guild::member_permissions` to check permissions, since all method that use it don't need channel-specific permissions.
Diffstat (limited to 'src/model/guild/mod.rs')
-rw-r--r--src/model/guild/mod.rs36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index 0a8fe16..1ad2b36 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -158,21 +158,13 @@ impl Guild {
}
#[cfg(feature = "cache")]
- fn has_perms(&self, mut permissions: Permissions) -> Result<bool> {
- let member = match self.members.get(&CACHE.read().unwrap().user.id) {
- Some(member) => member,
- None => return Err(Error::Model(ModelError::ItemMissing)),
- };
-
- let default_channel = match self.default_channel() {
- Some(dc) => dc,
- None => return Err(Error::Model(ModelError::ItemMissing)),
- };
+ fn has_perms(&self, mut permissions: Permissions) -> bool {
+ let user_id = CACHE.read().unwrap().user.id;
- let perms = self.permissions_for(default_channel.id, member.user.read().unwrap().id);
+ let perms = self.member_permissions(user_id);
permissions.remove(perms);
- Ok(permissions.is_empty())
+ permissions.is_empty()
}
/// Ban a [`User`] from the guild. All messages by the
@@ -210,7 +202,7 @@ impl Guild {
{
let req = Permissions::BAN_MEMBERS;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -235,7 +227,7 @@ impl Guild {
{
let req = Permissions::BAN_MEMBERS;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -317,7 +309,7 @@ impl Guild {
{
let req = Permissions::MANAGE_CHANNELS;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -388,7 +380,7 @@ impl Guild {
{
let req = Permissions::MANAGE_ROLES;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -490,7 +482,7 @@ impl Guild {
{
let req = Permissions::MANAGE_GUILD;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -570,7 +562,7 @@ impl Guild {
{
let req = Permissions::CHANGE_NICKNAME;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -652,7 +644,7 @@ impl Guild {
{
let req = Permissions::MANAGE_GUILD;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -1217,7 +1209,7 @@ impl Guild {
{
let req = Permissions::KICK_MEMBERS;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -1300,7 +1292,7 @@ impl Guild {
{
let req = Permissions::KICK_MEMBERS;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -1325,7 +1317,7 @@ impl Guild {
{
let req = Permissions::BAN_MEMBERS;
- if !self.has_perms(req)? {
+ if !self.has_perms(req) {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}