diff options
| author | Zeyla Hellyer <[email protected]> | 2018-01-27 11:59:39 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-01-27 11:59:39 -0800 |
| commit | 03a7e3e1d82ca667ca065367d2cf21b847f984ac (patch) | |
| tree | 45958b530d60d28ed541b78f78bdd0cb9cfbaef2 /src | |
| parent | Add a way to register middleware functions directly in `CreateCommand` (diff) | |
| download | serenity-03a7e3e1d82ca667ca065367d2cf21b847f984ac.tar.xz serenity-03a7e3e1d82ca667ca065367d2cf21b847f984ac.zip | |
Account for guild owners in member hierarchy check
When using `Guild::greater_member_hierarchy`, check if both user IDs are
the same (returning None) or if one of them is the guild owner, in which
case the guild owner's ID is returned.
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/guild/mod.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index f9f7f17..9d576ea 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -663,12 +663,27 @@ impl Guild { /// Returns [`None`] if at least one of the given users' member instances /// is not present. Returns `None` if the users have the same hierarchy, as /// neither are greater than the other. + /// + /// If both user IDs are the same, `None` is returned. If one of the users + /// is the guild owner, their ID is returned. #[cfg(feature = "cache")] pub fn greater_member_hierarchy<T, U>(&self, lhs_id: T, rhs_id: U) -> Option<UserId> where T: Into<UserId>, U: Into<UserId> { let lhs_id = lhs_id.into(); let rhs_id = rhs_id.into(); + // Check that the IDs are the same. If they are, neither is greater. + if lhs_id == rhs_id { + return None; + } + + // Check if either user is the guild owner. + if lhs_id == self.owner_id { + return Some(lhs_id); + } else if rhs_id == self.owner_id { + return Some(rhs_id); + } + let lhs = self.members.get(&lhs_id)? .highest_role_info() .unwrap_or((RoleId(0), 0)); |