1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use serde::{Deserialize, Serialize};
bitflags::bitflags! {
    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
    /// Permission
    pub struct Permission: u64 {
        // * Generic permissions
        /// Manage the channel or channels on the server
        const ManageChannel = 1 << 0;
        /// Manage the server
        const ManageServer = 1 << 1;
        /// Manage permissions on servers or channels
        const ManagePermissions = 1 << 2;
        /// Manage roles on server
        const ManageRole = 1 << 3;
        /// Manage server customisation (includes emoji)
        const ManageCustomisation = 1 << 4;
        // % 1 bits reserved
        // * Member permissions
        /// Kick other members below their ranking
        const KickMembers = 1 << 6;
        /// Ban other members below their ranking
        const BanMembers = 1 << 7;
        /// Timeout other members below their ranking
        const TimeoutMembers = 1 << 8;
        /// Assign roles to members below their ranking
        const AssignRoles = 1 << 9;
        /// Change own nickname
        const ChangeNickname = 1 << 10;
        /// Change or remove other's nicknames below their ranking
        const ManageNicknames = 1 << 11;
        /// Change own avatar
        const ChangeAvatar = 1 << 12;
        /// Remove other's avatars below their ranking
        const RemoveAvatars = 1 << 13;
        // % 7 bits reserved
        // * Channel permissions
        /// View a channel
        const ViewChannel = 1 << 20;
        /// Read a channel's past message history
        const ReadMessageHistory = 1 << 21;
        /// Send a message in a channel
        const SendMessage = 1 << 22;
        /// Delete messages in a channel
        const ManageMessages = 1 << 23;
        /// Manage webhook entries on a channel
        const ManageWebhooks = 1 << 24;
        /// Create invites to this channel
        const InviteOthers = 1 << 25;
        /// Send embedded content in this channel
        const SendEmbeds = 1 << 26;
        /// Send attachments and media in this channel
        const UploadFiles = 1 << 27;
        /// Masquerade messages using custom nickname and avatar
        const Masquerade = 1 << 28;
        /// React to messages with emojis
        const React = 1 << 29;
        // * Voice permissions
        /// Connect to a voice channel
        const Connect = 1 << 30;
        /// Speak in a voice call
        const Speak = 1 << 31;
        /// Share video in a voice call
        const Video = 1 << 32;
        /// Mute other members with lower ranking in a voice call
        const MuteMembers = 1 << 33;
        /// Deafen other members with lower ranking in a voice call
        const DeafenMembers = 1 << 34;
        /// Move members between voice channels
        const MoveMembers = 1 << 35;
        // * Misc. permissions
        // % Bits 36 to 52: free area
        // % Bits 53 to 64: do not use
    }
}
crate::impl_serde_bitflags!(Permission);
bitflags::bitflags! {
    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
    /// User permission
    pub struct UserPermission: u64 {
        const Access = 1 << 0;
        const ViewProfile = 1 << 1;
        const SendMessage = 1 << 2;
        const Invite = 1 << 3;
    }
}
crate::impl_serde_bitflags!(UserPermission);
/// Representation of a single permission override
/// as it appears on models and in the database
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct OverrideField {
    /// Allow bit flags
    a: Permission,
    /// Disallow bit flags
    d: Permission,
}
/// Representation of a single permission override
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Override {
    /// Allow bit flags
    allow: Permission,
    /// Disallow bit flags
    deny: Permission,
}