Init
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
use bitflags::bitflags;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
bitflags! {
|
||||
/// Permissions liées aux serveurs (gestion globale)
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct ServerPermission: u64 {
|
||||
const ManageServer = 1 << 0;
|
||||
const ManageRoles = 1 << 1;
|
||||
const KickMember = 1 << 2;
|
||||
const BanMember = 1 << 3;
|
||||
// ... jusqu'à 64 perms serveur
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// Permissions liées aux canaux (texte + vocal)
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct ChannelPermission: u64 {
|
||||
const ReadChannel = 1 << 0;
|
||||
const SendMessage = 1 << 1;
|
||||
const DeleteMessage = 1 << 2;
|
||||
const DeleteOthersMessage = 1 << 3;
|
||||
const ManageChannel = 1 << 4;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// Permissions liées au vocal
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct VoicePermission: u64 {
|
||||
const JoinChannel = 1 << 0;
|
||||
const VoiceSpeak = 1 << 1;
|
||||
const VoiceMuteOthers = 1 << 2;
|
||||
const VoiceDeafenOthers = 1 << 3;
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
/// Agrégat de permissions traversant tous les domaines.
|
||||
/// Utile pour les API et les contrôles complets.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||
pub struct PermissionSet {
|
||||
pub server: ServerPermission,
|
||||
pub channel: ChannelPermission,
|
||||
pub voice: VoicePermission,
|
||||
}
|
||||
|
||||
impl PermissionSet {
|
||||
pub const fn new(
|
||||
server: ServerPermission,
|
||||
channel: ChannelPermission,
|
||||
voice: VoicePermission,
|
||||
) -> Self {
|
||||
Self {
|
||||
server,
|
||||
channel,
|
||||
voice,
|
||||
}
|
||||
}
|
||||
|
||||
pub const DEFAULT: Self = Self::new(
|
||||
ServerPermission::empty(),
|
||||
ChannelPermission::from_bits_truncate(
|
||||
ChannelPermission::ReadChannel.bits()
|
||||
| ChannelPermission::SendMessage.bits()
|
||||
| ChannelPermission::DeleteMessage.bits(),
|
||||
),
|
||||
VoicePermission::from_bits_truncate(
|
||||
VoicePermission::JoinChannel.bits() | VoicePermission::VoiceSpeak.bits(),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user