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 "PartialServer"
83);
84
85auto_derived_partial!(
86 pub struct Role {
88 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
90 pub id: String,
91 pub name: String,
93 pub permissions: OverrideField,
95 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
99 pub colour: Option<String>,
100 #[cfg_attr(
102 feature = "serde",
103 serde(skip_serializing_if = "crate::if_false", default)
104 )]
105 pub hoist: bool,
106 #[cfg_attr(feature = "serde", serde(default))]
108 pub rank: i64,
109 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
111 pub icon: Option<File>,
112 },
113 "PartialRole"
114);
115
116auto_derived!(
117 pub enum FieldsServer {
119 Description,
120 Categories,
121 SystemMessages,
122 Icon,
123 Banner,
124 }
125
126 pub enum FieldsRole {
128 Colour,
129 Icon,
130 }
131
132 #[cfg_attr(feature = "validator", derive(Validate))]
134 pub struct Category {
135 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
137 pub id: String,
138 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
140 pub title: String,
141 pub channels: Vec<String>,
143 }
144
145 pub struct SystemMessageChannels {
147 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
149 pub user_joined: Option<String>,
150 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
152 pub user_left: Option<String>,
153 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
155 pub user_kicked: Option<String>,
156 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
158 pub user_banned: Option<String>,
159 }
160
161 #[derive(Default)]
163 #[cfg_attr(feature = "validator", derive(Validate))]
164 pub struct DataCreateServer {
165 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
167 pub name: String,
168 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
170 pub description: Option<String>,
171 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
173 pub nsfw: Option<bool>,
174 }
175
176 #[cfg_attr(feature = "validator", derive(Validate))]
178 pub struct DataCreateRole {
179 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
181 pub name: String,
182 pub rank: Option<i64>,
188 }
189
190 pub struct NewRoleResponse {
193 pub id: String,
195 pub role: Role,
197 }
198
199 pub struct CreateServerLegacyResponse {
201 pub server: Server,
203 pub channels: Vec<Channel>,
205 }
206
207 #[cfg_attr(feature = "rocket", derive(FromForm))]
209 pub struct OptionsFetchServer {
210 pub include_channels: Option<bool>,
212 }
213
214 #[serde(untagged)]
216 pub enum FetchServerResponse {
217 JustServer(Server),
218 ServerWithChannels {
219 #[serde(flatten)]
220 server: Server,
221 channels: Vec<Channel>,
222 },
223 }
224
225 #[cfg_attr(feature = "validator", derive(Validate))]
227 pub struct DataEditServer {
228 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
230 pub name: Option<String>,
231 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
233 pub description: Option<String>,
234
235 pub icon: Option<String>,
237 pub banner: Option<String>,
239
240 #[cfg_attr(feature = "validator", validate)]
242 pub categories: Option<Vec<Category>>,
243 pub system_messages: Option<SystemMessageChannels>,
245
246 #[cfg_attr(feature = "validator", serde(skip_serializing_if = "Option::is_none"))]
248 pub flags: Option<i32>,
249
250 pub discoverable: Option<bool>,
254 pub analytics: Option<bool>,
258
259 pub owner: Option<String>,
261
262 #[cfg_attr(feature = "serde", serde(default))]
264 pub remove: Vec<FieldsServer>,
265 }
266
267 #[cfg_attr(feature = "validator", derive(Validate))]
269 pub struct DataEditRole {
270 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
272 pub name: Option<String>,
273 #[cfg_attr(
275 feature = "validator",
276 validate(length(min = 1, max = 128), regex = "RE_COLOUR")
277 )]
278 pub colour: Option<String>,
279 pub hoist: Option<bool>,
281 pub rank: Option<i64>,
285 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
289 pub icon: Option<String>,
290 #[cfg_attr(feature = "serde", serde(default))]
292 pub remove: Vec<FieldsRole>,
293 }
294
295 pub struct DataSetServerRolePermission {
297 pub permissions: Override,
299 }
300
301 #[cfg_attr(feature = "rocket", derive(FromForm))]
303 pub struct OptionsServerDelete {
304 pub leave_silently: Option<bool>,
306 }
307
308 pub struct DataEditRoleRanks {
310 pub ranks: Vec<String>,
311 }
312);