polyphony_types/utils/
rights.rs1use bitflags::bitflags;
2
3bitflags! {
4 pub struct Rights: u64 {
5 const OPERATOR = 1 << 0;
6 const MANAGE_APPLICATIONS = 1 << 1;
7 const MANAGE_GUILDS = 1 << 2;
8 const MANAGE_MESSAGES = 1 << 3;
9 const MANAGE_RATE_LIMITS = 1 << 4;
10 const MANAGE_ROUTING = 1 << 5;
11 const MANAGE_TICKETS = 1 << 6;
12 const MANAGE_USERS = 1 << 7;
13 const ADD_MEMBERS = 1 << 8;
14 const BYPASS_RATE_LIMITS = 1 << 9;
15 const CREATE_APPLICATIONS = 1 << 10;
16 const CREATE_CHANNELS = 1 << 11;
17 const CREATE_DMS = 1 << 12;
18 const CREATE_DM_GROUPS = 1 << 13;
19 const CREATE_GUILDS = 1 << 14;
20 const CREATE_INVITES = 1 << 15;
21 const CREATE_ROLES = 1 << 16;
22 const CREATE_TEMPLATES = 1 << 17;
23 const CREATE_WEBHOOKS = 1 << 18;
24 const JOIN_GUILDS = 1 << 19;
25 const PIN_MESSAGES = 1 << 20;
26 const SELF_ADD_REACTIONS = 1 << 21;
27 const SELF_DELETE_MESSAGES = 1 << 22;
28 const SELF_EDIT_MESSAGES = 1 << 23;
29 const SELF_EDIT_NAME = 1 << 24;
30 const SEND_MESSAGES = 1 << 25;
31 const USE_ACTIVITIES = 1 << 26;
32 const USE_VIDEO = 1 << 27;
33 const USE_VOICE = 1 << 28;
34 const INVITE_USERS = 1 << 29;
35 const SELF_DELETE_DISABLE = 1 << 30;
36 const DEBTABLE = 1 << 31;
37 const CREDITABLE = 1 << 32;
38 const KICK_BAN_MEMBERS = 1 << 33;
39 const SELF_LEAVE_GROUPS = 1 << 34;
40 const PRESENCE = 1 << 35;
41 const SELF_ADD_DISCOVERABLE = 1 << 36;
42 const MANAGE_GUILD_DIRECTORY = 1 << 37;
43 const POGGERS = 1 << 38;
44 const USE_ACHIEVEMENTS = 1 << 39;
45 const INITIATE_INTERACTIONS = 1 << 40;
46 const RESPOND_TO_INTERACTIONS = 1 << 41;
47 const SEND_BACKDATED_EVENTS = 1 << 42;
48 const USE_MASS_INVITES = 1 << 43;
49 const ACCEPT_INVITES = 1 << 44;
50 const SELF_EDIT_FLAGS = 1 << 45;
51 const EDIT_FLAGS = 1 << 46;
52 const MANAGE_GROUPS = 1 << 47;
53 const VIEW_SERVER_STATS = 1 << 48;
54 const RESEND_VERIFICATION_EMAIL = 1 << 49;
55 }
56}
57
58impl Rights {
59 pub fn any(&self, permission: Rights, check_operator: bool) -> bool {
60 (check_operator && self.contains(Rights::OPERATOR)) || self.contains(permission)
61 }
62
63 pub fn has(&self, permission: Rights, check_operator: bool) -> bool {
64 (check_operator && self.contains(Rights::OPERATOR)) || self.contains(permission)
65 }
66
67 pub fn has_throw(&self, permission: Rights) -> Result<bool, &'static str> {
68 if self.has(permission, true) {
69 Ok(true)
70 } else {
71 Err("You are missing the following rights")
72 }
73 }
74}
75
76fn all_rights() -> Rights {
77 Rights::OPERATOR
78 | Rights::MANAGE_APPLICATIONS
79 | Rights::MANAGE_GUILDS
80 | Rights::MANAGE_MESSAGES
81 | Rights::MANAGE_RATE_LIMITS
82 | Rights::MANAGE_ROUTING
83 | Rights::MANAGE_TICKETS
84 | Rights::MANAGE_USERS
85 | Rights::ADD_MEMBERS
86 | Rights::BYPASS_RATE_LIMITS
87 | Rights::CREATE_APPLICATIONS
88 | Rights::CREATE_CHANNELS
89 | Rights::CREATE_DMS
90 | Rights::CREATE_DM_GROUPS
91 | Rights::CREATE_GUILDS
92 | Rights::CREATE_INVITES
93 | Rights::CREATE_ROLES
94 | Rights::CREATE_TEMPLATES
95 | Rights::CREATE_WEBHOOKS
96 | Rights::JOIN_GUILDS
97 | Rights::PIN_MESSAGES
98 | Rights::SELF_ADD_REACTIONS
99 | Rights::SELF_DELETE_MESSAGES
100 | Rights::SELF_EDIT_MESSAGES
101 | Rights::SELF_EDIT_NAME
102 | Rights::SEND_MESSAGES
103 | Rights::USE_ACTIVITIES
104 | Rights::USE_VIDEO
105 | Rights::USE_VOICE
106 | Rights::INVITE_USERS
107 | Rights::SELF_DELETE_DISABLE
108 | Rights::DEBTABLE
109 | Rights::CREDITABLE
110 | Rights::KICK_BAN_MEMBERS
111 | Rights::SELF_LEAVE_GROUPS
112 | Rights::PRESENCE
113 | Rights::SELF_ADD_DISCOVERABLE
114 | Rights::MANAGE_GUILD_DIRECTORY
115 | Rights::POGGERS
116 | Rights::USE_ACHIEVEMENTS
117 | Rights::INITIATE_INTERACTIONS
118 | Rights::RESPOND_TO_INTERACTIONS
119 | Rights::SEND_BACKDATED_EVENTS
120 | Rights::USE_MASS_INVITES
121 | Rights::ACCEPT_INVITES
122 | Rights::SELF_EDIT_FLAGS
123 | Rights::EDIT_FLAGS
124 | Rights::MANAGE_GROUPS
125 | Rights::VIEW_SERVER_STATS
126 | Rights::RESEND_VERIFICATION_EMAIL
127}