From 03a7e3e1d82ca667ca065367d2cf21b847f984ac Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Sat, 27 Jan 2018 11:59:39 -0800 Subject: 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. --- src/model/guild/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/model/guild') 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(&self, lhs_id: T, rhs_id: U) -> Option where T: Into, U: Into { 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)); -- cgit v1.2.3