Try making permissions to PermissionFlags

This commit is contained in:
bitfl0wer 2023-06-07 22:44:16 +02:00
parent 6c0d21867c
commit 97ca0c17eb
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
1 changed files with 8 additions and 2 deletions

View File

@ -16,8 +16,7 @@ pub struct RoleObject {
pub unicode_emoji: Option<String>,
pub position: u16,
#[serde(default)]
#[serde(deserialize_with = "deserialize_string_from_number")]
pub permissions: String,
pub permissions: PermissionFlags,
pub managed: bool,
pub mentionable: bool,
#[cfg(feature = "sqlx")]
@ -53,6 +52,7 @@ pub struct RoleTags {
}
bitflags! {
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct PermissionFlags: u64 {
const CREATE_INSTANT_INVITE = 1 << 0;
const KICK_MEMBERS = 1 << 1;
@ -101,3 +101,9 @@ bitflags! {
const SEND_VOICE_MESSAGES = 1 << 46;
}
}
impl PermissionFlags {
pub fn has_permission(&self, permission: PermissionFlags) -> bool {
self.contains(permission) || self.contains(PermissionFlags::ADMINISTRATOR)
}
}