This commit is contained in:
2026-07-13 01:38:36 +02:00
parent ede38cc042
commit 09cf5f37fb
16 changed files with 747 additions and 644 deletions
+13 -47
View File
@@ -37,6 +37,7 @@ bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(transparent)]
pub struct ChannelPermission: u64 {
// Permission communes / texte
/// Voir le canal et son contenu.
const READ_CHANNEL = 1 << 0;
@@ -66,37 +67,16 @@ bitflags! {
/// Épingler ou désépingler des messages.
const MANAGE_MESSAGES = 1 << 10;
}
}
bitflags! {
/// Permissions applicables aux canaux vocaux.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[serde(transparent)]
pub struct VoicePermission: u64 {
/// Rejoindre un canal vocal.
const JOIN_CHANNEL = 1 << 0;
/// Parler dans un canal vocal.
const SPEAK = 1 << 1;
/// Utiliser sa caméra ou partager son écran.
const STREAM = 1 << 2;
/// Couper son propre microphone.
const MUTE_SELF = 1 << 3;
/// Couper le microphone d'un autre membre.
const MUTE_OTHERS = 1 << 4;
/// Déplacer un membre vers un autre canal vocal.
const MOVE_OTHERS = 1 << 6;
/// Expulser un membre d'un canal vocal.
const DISCONNECT_OTHERS = 1 << 7;
/// Modifier les paramètres du canal vocal.
const MANAGE_VOICE_CHANNEL = 1 << 8;
// Permissions vocales (30-45 réservées)
const JOIN_VOICE = 1 << 30;
const SPEAK = 1 << 31;
const STREAM = 1 << 32;
const MUTE_SELF = 1 << 33;
const MUTE_OTHERS = 1 << 34;
const MOVE_OTHERS = 1 << 35;
const DISCONNECT_OTHERS = 1 << 36;
const MANAGE_VOICE_CHANNEL = 1 << 37;
}
}
@@ -105,20 +85,11 @@ bitflags! {
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 fn new(server: ServerPermission, channel: ChannelPermission) -> Self {
Self { server, channel }
}
/// Permissions par défaut accordées à un membre standard.
@@ -131,15 +102,10 @@ impl PermissionSet {
| ChannelPermission::DELETE_OWN_MESSAGE.bits()
| ChannelPermission::ADD_REACTIONS.bits(),
),
VoicePermission::from_bits_retain(
VoicePermission::JOIN_CHANNEL.bits() | VoicePermission::SPEAK.bits(),
),
);
/// Vérifie si l'ensemble contient la permission demandée.
pub const fn contains(&self, required: Self) -> bool {
self.server.contains(required.server)
&& self.channel.contains(required.channel)
&& self.voice.contains(required.voice)
self.server.contains(required.server) && self.channel.contains(required.channel)
}
}