refactor(quark): port message_react, message_send, message_unreact, permissions_set_default, permissions_set

#283
This commit is contained in:
Paul Makles
2024-04-07 17:12:59 +01:00
parent aca1fe6dff
commit 569bd1d5e1
11 changed files with 237 additions and 110 deletions

View File

@@ -63,6 +63,37 @@ impl PermissionValue {
}))
}
}
/// Throw an error if we cannot grant permissions on either allows or denies
/// going from the previous given value to the next given value.
///
/// We need to check any:
/// - allows added (permissions now granted)
/// - denies removed (permissions now neutral or granted)
pub async fn throw_permission_override<C>(
&self,
current_value: C,
next_value: &Override,
) -> Result<()>
where
C: Into<Option<Override>>,
{
let current_value = current_value.into();
if let Some(current_value) = current_value {
if !self.has(!current_value.allows() & next_value.allows())
|| !self.has(current_value.denies() & !next_value.denies())
{
return Err(create_error!(CannotGiveMissingPermissions));
}
} else {
if !self.has(next_value.allows()) {
return Err(create_error!(CannotGiveMissingPermissions));
}
}
Ok(())
}
}
impl From<i64> for PermissionValue {