twilight_util/permission_calculator/
preset.rs1use super::bitops;
5use twilight_model::guild::Permissions;
6
7pub const PERMISSIONS_MESSAGING: Permissions = Permissions::from_bits_truncate(
9 Permissions::ATTACH_FILES.bits()
10 | Permissions::EMBED_LINKS.bits()
11 | Permissions::MENTION_EVERYONE.bits()
12 | Permissions::SEND_TTS_MESSAGES.bits(),
13);
14
15pub const PERMISSIONS_ROOT_ONLY: Permissions = Permissions::from_bits_truncate(
18 Permissions::ADMINISTRATOR.bits()
19 | Permissions::BAN_MEMBERS.bits()
20 | Permissions::CHANGE_NICKNAME.bits()
21 | Permissions::KICK_MEMBERS.bits()
22 | Permissions::MANAGE_GUILD_EXPRESSIONS.bits()
23 | Permissions::MANAGE_GUILD.bits()
24 | Permissions::MANAGE_NICKNAMES.bits()
25 | Permissions::VIEW_AUDIT_LOG.bits()
26 | Permissions::VIEW_GUILD_INSIGHTS.bits(),
27);
28
29pub const PERMISSIONS_STAGE_OMIT: Permissions = bitops::remove(
32 bitops::insert(PERMISSIONS_TEXT, PERMISSIONS_VOICE),
33 PERMISSIONS_STAGE,
34);
35
36pub const PERMISSIONS_TEXT_OMIT: Permissions = bitops::remove(
39 bitops::insert(PERMISSIONS_STAGE, PERMISSIONS_VOICE),
40 PERMISSIONS_TEXT,
41);
42
43pub const PERMISSIONS_VOICE_OMIT: Permissions = bitops::remove(
46 bitops::insert(PERMISSIONS_STAGE, PERMISSIONS_TEXT),
47 PERMISSIONS_VOICE,
48);
49
50const PERMISSIONS_STAGE: Permissions = Permissions::from_bits_truncate(
52 Permissions::CONNECT.bits()
53 | Permissions::CREATE_INVITE.bits()
54 | Permissions::MANAGE_CHANNELS.bits()
55 | Permissions::MANAGE_ROLES.bits()
56 | Permissions::MOVE_MEMBERS.bits()
57 | Permissions::MUTE_MEMBERS.bits()
58 | Permissions::REQUEST_TO_SPEAK.bits()
59 | Permissions::VIEW_CHANNEL.bits(),
60);
61
62const PERMISSIONS_TEXT: Permissions = Permissions::from_bits_truncate(
64 Permissions::ADD_REACTIONS.bits()
65 | Permissions::ATTACH_FILES.bits()
66 | Permissions::CREATE_INVITE.bits()
67 | Permissions::EMBED_LINKS.bits()
68 | Permissions::MANAGE_CHANNELS.bits()
69 | Permissions::MANAGE_MESSAGES.bits()
70 | Permissions::MANAGE_ROLES.bits()
71 | Permissions::MANAGE_WEBHOOKS.bits()
72 | Permissions::MENTION_EVERYONE.bits()
73 | Permissions::READ_MESSAGE_HISTORY.bits()
74 | Permissions::SEND_MESSAGES.bits()
75 | Permissions::SEND_TTS_MESSAGES.bits()
76 | Permissions::USE_EXTERNAL_EMOJIS.bits()
77 | Permissions::USE_SLASH_COMMANDS.bits()
78 | Permissions::VIEW_CHANNEL.bits(),
79);
80
81const PERMISSIONS_VOICE: Permissions = Permissions::from_bits_truncate(
83 Permissions::CONNECT.bits()
84 | Permissions::CREATE_INVITE.bits()
85 | Permissions::DEAFEN_MEMBERS.bits()
86 | Permissions::MANAGE_CHANNELS.bits()
87 | Permissions::MANAGE_ROLES.bits()
88 | Permissions::MOVE_MEMBERS.bits()
89 | Permissions::MUTE_MEMBERS.bits()
90 | Permissions::PRIORITY_SPEAKER.bits()
91 | Permissions::SPEAK.bits()
92 | Permissions::STREAM.bits()
93 | Permissions::USE_VAD.bits()
94 | Permissions::VIEW_CHANNEL.bits(),
95);
96
97#[cfg(test)]
98mod tests {
99 use super::{PERMISSIONS_STAGE_OMIT, PERMISSIONS_TEXT_OMIT, PERMISSIONS_VOICE_OMIT};
100 use twilight_model::guild::Permissions;
101
102 #[test]
103 fn permissions_stage_omitted() {
104 let expected = Permissions::ADD_REACTIONS
105 | Permissions::PRIORITY_SPEAKER
106 | Permissions::STREAM
107 | Permissions::SEND_MESSAGES
108 | Permissions::SEND_TTS_MESSAGES
109 | Permissions::MANAGE_MESSAGES
110 | Permissions::EMBED_LINKS
111 | Permissions::ATTACH_FILES
112 | Permissions::READ_MESSAGE_HISTORY
113 | Permissions::MENTION_EVERYONE
114 | Permissions::USE_EXTERNAL_EMOJIS
115 | Permissions::SPEAK
116 | Permissions::DEAFEN_MEMBERS
117 | Permissions::USE_VAD
118 | Permissions::MANAGE_WEBHOOKS
119 | Permissions::USE_SLASH_COMMANDS;
120
121 assert_eq!(expected, PERMISSIONS_STAGE_OMIT);
122 }
123
124 #[test]
125 fn permissions_text_omitted() {
126 let expected = Permissions::CONNECT
127 | Permissions::DEAFEN_MEMBERS
128 | Permissions::MOVE_MEMBERS
129 | Permissions::MUTE_MEMBERS
130 | Permissions::PRIORITY_SPEAKER
131 | Permissions::REQUEST_TO_SPEAK
132 | Permissions::SPEAK
133 | Permissions::STREAM
134 | Permissions::USE_VAD;
135
136 assert_eq!(expected, PERMISSIONS_TEXT_OMIT);
137 }
138
139 #[test]
140 fn permissions_voice_omitted() {
141 let expected = Permissions::ADD_REACTIONS
142 | Permissions::ATTACH_FILES
143 | Permissions::EMBED_LINKS
144 | Permissions::MANAGE_MESSAGES
145 | Permissions::MANAGE_WEBHOOKS
146 | Permissions::MENTION_EVERYONE
147 | Permissions::READ_MESSAGE_HISTORY
148 | Permissions::REQUEST_TO_SPEAK
149 | Permissions::SEND_MESSAGES
150 | Permissions::SEND_TTS_MESSAGES
151 | Permissions::USE_EXTERNAL_EMOJIS
152 | Permissions::USE_SLASH_COMMANDS;
153
154 assert_eq!(expected, PERMISSIONS_VOICE_OMIT);
155 }
156}