1use super::{Channel, File, RE_COLOUR};
2
3use revolt_permissions::{Override, OverrideField};
4use std::collections::HashMap;
5
6#[cfg(feature = "validator")]
7use validator::Validate;
8
9#[cfg(feature = "rocket")]
10use rocket::FromForm;
11
12auto_derived_partial!(
13 pub struct Server {
15 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
17 pub id: String,
18 pub owner: String,
20
21 pub name: String,
23 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
25 pub description: Option<String>,
26
27 pub channels: Vec<String>,
30 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
32 pub categories: Option<Vec<Category>>,
33 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
35 pub system_messages: Option<SystemMessageChannels>,
36
37 #[cfg_attr(
39 feature = "serde",
40 serde(
41 default = "HashMap::<String, Role>::new",
42 skip_serializing_if = "HashMap::<String, Role>::is_empty"
43 )
44 )]
45 pub roles: HashMap<String, Role>,
46 pub default_permissions: i64,
48
49 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
51 pub icon: Option<File>,
52 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
54 pub banner: Option<File>,
55
56 #[cfg_attr(
58 feature = "serde",
59 serde(skip_serializing_if = "crate::if_zero_u32", default)
60 )]
61 pub flags: u32,
62
63 #[cfg_attr(
65 feature = "serde",
66 serde(skip_serializing_if = "crate::if_false", default)
67 )]
68 pub nsfw: bool,
69 #[cfg_attr(
71 feature = "serde",
72 serde(skip_serializing_if = "crate::if_false", default)
73 )]
74 pub analytics: bool,
75 #[cfg_attr(
77 feature = "serde",
78 serde(skip_serializing_if = "crate::if_false", default)
79 )]
80 pub discoverable: bool,
81
82 pub approximate_member_count: usize,
84 },
85 "PartialServer"
86);
87
88auto_derived_partial!(
89 pub struct Role {
91 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
93 pub id: String,
94 pub name: String,
96 pub permissions: OverrideField,
98 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
102 pub colour: Option<String>,
103 #[cfg_attr(
105 feature = "serde",
106 serde(skip_serializing_if = "crate::if_false", default)
107 )]
108 pub hoist: bool,
109 #[cfg_attr(feature = "serde", serde(default))]
111 pub rank: i64,
112 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
114 pub icon: Option<File>,
115 },
116 "PartialRole"
117);
118
119auto_derived!(
120 pub enum FieldsServer {
122 Description,
123 Categories,
124 SystemMessages,
125 Icon,
126 Banner,
127 }
128
129 pub enum FieldsRole {
131 Colour,
132 Icon,
133 }
134
135 #[cfg_attr(feature = "validator", derive(Validate))]
137 pub struct Category {
138 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
140 pub id: String,
141 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
143 pub title: String,
144 pub channels: Vec<String>,
146 }
147
148 pub struct SystemMessageChannels {
150 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
152 pub user_joined: Option<String>,
153 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
155 pub user_left: Option<String>,
156 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
158 pub user_kicked: Option<String>,
159 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
161 pub user_banned: Option<String>,
162 }
163
164 #[derive(Default)]
166 #[cfg_attr(feature = "validator", derive(Validate))]
167 pub struct DataCreateServer {
168 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
170 pub name: String,
171 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
173 pub description: Option<String>,
174 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
176 pub nsfw: Option<bool>,
177 }
178
179 #[cfg_attr(feature = "validator", derive(Validate))]
181 pub struct DataCreateRole {
182 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
184 pub name: String,
185 pub rank: Option<i64>,
191 }
192
193 pub struct NewRoleResponse {
196 pub id: String,
198 pub role: Role,
200 }
201
202 pub struct CreateServerLegacyResponse {
204 pub server: Server,
206 pub channels: Vec<Channel>,
208 }
209
210 #[cfg_attr(feature = "rocket", derive(FromForm))]
212 pub struct OptionsFetchServer {
213 pub include_channels: Option<bool>,
215 }
216
217 #[serde(untagged)]
219 pub enum FetchServerResponse {
220 JustServer(Server),
221 ServerWithChannels {
222 #[serde(flatten)]
223 server: Server,
224 channels: Vec<Channel>,
225 },
226 }
227
228 #[cfg_attr(feature = "validator", derive(Validate))]
230 pub struct DataEditServer {
231 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
233 pub name: Option<String>,
234 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
236 pub description: Option<String>,
237
238 pub icon: Option<String>,
240 pub banner: Option<String>,
242
243 #[cfg_attr(feature = "validator", validate)]
245 pub categories: Option<Vec<Category>>,
246 pub system_messages: Option<SystemMessageChannels>,
248
249 #[cfg_attr(feature = "validator", serde(skip_serializing_if = "Option::is_none"))]
251 pub flags: Option<i32>,
252
253 pub discoverable: Option<bool>,
257 pub analytics: Option<bool>,
261
262 pub owner: Option<String>,
264
265 #[cfg_attr(feature = "serde", serde(default))]
267 pub remove: Vec<FieldsServer>,
268 }
269
270 #[cfg_attr(feature = "validator", derive(Validate))]
272 pub struct DataEditRole {
273 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
275 pub name: Option<String>,
276 #[cfg_attr(
278 feature = "validator",
279 validate(length(min = 1, max = 128), regex = "RE_COLOUR")
280 )]
281 pub colour: Option<String>,
282 pub hoist: Option<bool>,
284 pub rank: Option<i64>,
288 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
292 pub icon: Option<String>,
293 #[cfg_attr(feature = "serde", serde(default))]
295 pub remove: Vec<FieldsRole>,
296 }
297
298 pub struct DataSetServerRolePermission {
300 pub permissions: Override,
302 }
303
304 #[cfg_attr(feature = "rocket", derive(FromForm))]
306 pub struct OptionsServerDelete {
307 pub leave_silently: Option<bool>,
309 }
310
311 pub struct DataEditRoleRanks {
313 pub ranks: Vec<String>,
314 }
315);