1use chrono::{DateTime, FixedOffset};
3use serde_repr::{Deserialize_repr, Serialize_repr};
4
5use crate::{
6 channel::Channel,
7 message::Emoji,
8 presence::Presence,
9 User,
10 voice::VoiceState,
11};
12use crate::snowflake::Snowflake;
13
14pub use self::{
15 audit_log::*,
16 member::*,
17 role::*
18};
19
20mod role;
21mod audit_log;
22mod member;
23
24#[derive(Deserialize, Debug, Serialize, Clone)]
26pub struct Guild {
27 pub id: Snowflake,
29 pub name: String,
31 pub icon: Option<String>,
33 pub splash: Option<String>,
35 pub owner: Option<bool>,
37 pub owner_id: String,
39 #[serde(default)]
41 pub permissions: i32,
42 pub region: String,
44 pub afk_channel_id: Option<String>,
46 pub afk_timeout: Option<i32>,
48 #[serde(default)]
50 pub embed_enabled: bool,
51 #[serde(default)]
53 pub embed_channel_id: String,
54 #[serde(default)]
56 pub member_count: i32,
57 pub features: Vec<String>,
59 pub roles: Vec<Role>,
61 pub emojis: Vec<Emoji>,
63 pub explicit_content_filter: ExplicitContentFilter,
65 pub application_id: Option<String>,
67 pub verification_level: VerificationLevel,
69 pub mfa_level: MfaLevel,
71 pub system_channel_id: Option<String>,
73 #[serde(default)]
75 pub joined_at: String,
76 #[serde(default)]
78 pub large: bool,
79 #[serde(default)]
81 pub unavailable: bool,
82 #[serde(default)]
84 pub widget_enabled: bool,
85 #[serde(default)]
87 pub widget_channel_id: String,
88 pub default_message_notifications: DefaultMessageNotifications,
90 pub voice_states: Vec<VoiceState>,
92 #[serde(default)]
94 pub channels: Vec<Channel>,
95 #[serde(default)]
97 pub members: Vec<GuildMember>,
98 #[serde(default)]
100 pub presences: Option<Vec<Presence>>
101}
102
103#[derive(Serialize, Deserialize, Debug, Clone)]
105pub struct UnavailableGuild {
106 pub id: Snowflake,
108 pub unavailable: bool
110}
111
112#[derive(Serialize, Deserialize, Debug, Clone)]
114pub struct GuildEmbed {
115 pub enabled: bool,
117 pub channel_id: Snowflake,
119}
120
121#[derive(Serialize, Deserialize, Debug, Clone)]
123pub struct ModifyGuildEmbedOptions {
124 #[serde(skip_serializing_if = "Option::is_none")]
125 enabled: Option<bool>,
126 #[serde(skip_serializing_if = "Option::is_none")]
127 channel_id: Option<Snowflake>,
128}
129
130impl ModifyGuildEmbedOptions {
131 pub fn enabled(mut self, opt: bool) -> Self {
133 self.enabled = Some(opt);
134 self
135 }
136
137 pub fn channel_id(mut self, id: Snowflake) -> Self {
139 self.channel_id = Some(id);
140 self
141 }
142}
143
144#[derive(Serialize, Deserialize, Debug, Clone)]
146pub struct ModifyGuildOptions {
147 #[serde(skip_serializing_if = "Option::is_none")]
148 name: Option<String>,
149 #[serde(skip_serializing_if = "Option::is_none")]
150 region: Option<String>,
151 #[serde(skip_serializing_if = "Option::is_none")]
152 verification_level: Option<VerificationLevel>,
153 #[serde(skip_serializing_if = "Option::is_none")]
154 default_message_notifications: Option<DefaultMessageNotifications>,
155 #[serde(skip_serializing_if = "Option::is_none")]
156 explicit_content_filter: Option<ExplicitContentFilter>,
157 #[serde(skip_serializing_if = "Option::is_none")]
158 afk_channel_id: Option<Snowflake>,
159 #[serde(skip_serializing_if = "Option::is_none")]
160 afk_timeout: Option<i32>,
161 #[serde(skip_serializing_if = "Option::is_none")]
162 icon: Option<String>,
163 #[serde(skip_serializing_if = "Option::is_none")]
164 owner: Option<Snowflake>,
165 #[serde(skip_serializing_if = "Option::is_none")]
166 splash: Option<String>,
167 #[serde(skip_serializing_if = "Option::is_none")]
168 system_channel_id: Option<Snowflake>,
169}
170
171impl ModifyGuildOptions {
172 pub fn name(mut self, name: &str) -> Self {
174 self.name = Some(name.to_string());
175 self
176 }
177
178 pub fn region(mut self, reg: &str) -> Self {
180 self.region = Some(reg.to_string());
181 self
182 }
183
184 pub fn verification_level(mut self, level: VerificationLevel) -> Self {
186 self.verification_level = Some(level);
187 self
188 }
189
190 pub fn default_message_notifications(mut self, level: DefaultMessageNotifications) -> Self {
192 self.default_message_notifications = Some(level);
193 self
194 }
195
196 pub fn explicit_content_filter(mut self, filter: ExplicitContentFilter) -> Self {
198 self.explicit_content_filter = Some(filter);
199 self
200 }
201
202 pub fn afk_channel(mut self, id: Snowflake) -> Self {
204 self.afk_channel_id = Some(id);
205 self
206 }
207
208 pub fn afk_timeout(mut self, timeout: i32) -> Self {
210 self.afk_timeout = Some(timeout);
211 self
212 }
213
214 pub fn icon(mut self, url: &str) -> Self {
216 self.icon = Some(url.to_string());
217 self
218 }
219
220 pub fn owner(mut self, id: Snowflake) -> Self {
222 self.owner = Some(id);
223 self
224 }
225
226 pub fn splash(mut self, url: &str) -> Self {
228 self.splash = Some(url.to_string());
229 self
230 }
231
232 pub fn system_channel(mut self, chan: Snowflake) -> Self {
234 self.system_channel_id = Some(chan);
235 self
236 }
237}
238
239#[derive(Deserialize, Debug, Clone)]
241pub struct GuildPrune {
242 pub pruned: i32
244}
245
246#[derive(Deserialize, Debug, Clone)]
247pub struct GuildIntegration {
248 pub id: Snowflake,
250 pub name: String,
252 #[serde(rename = "type")]
253 pub kind: String,
254 pub enabled: bool,
256 pub syncing: bool,
258 pub role_id: Snowflake,
260 pub expire_behavior: i32,
262 pub expire_grace_period: i32,
264 pub user: User,
266 pub account: IntegrationAccount,
268 pub synced_at: DateTime<FixedOffset>,
270}
271
272#[derive(Deserialize, Debug, Clone)]
273pub struct IntegrationAccount {
274 pub id: String,
276 pub name: String,
278}
279
280#[derive(Clone, Debug, Deserialize, Serialize, Default)]
282pub struct ModifyGuildIntegrationOptions {
283 #[serde(skip_serializing_if = "Option::is_none")]
284 expire_behavior: Option<i32>,
285 #[serde(skip_serializing_if = "Option::is_none")]
286 expire_grace_period: Option<i32>,
287 #[serde(skip_serializing_if = "Option::is_none")]
288 enable_emoticons: Option<bool>,
289}
290
291impl ModifyGuildIntegrationOptions {
292 pub fn expire_behavior(mut self, beh: i32) -> Self {
294 self.expire_behavior = Some(beh);
295 self
296 }
297
298 pub fn expire_grace_period(mut self, per: i32) -> Self {
300 self.expire_grace_period = Some(per);
301 self
302 }
303
304 pub fn enable_emoticons(mut self, opt: bool) -> Self {
306 self.enable_emoticons = Some(opt);
307 self
308 }
309}
310
311#[derive(Clone, Debug, Serialize, Default)]
313pub struct CreateGuildOptions {
314 #[serde(default)]
315 name: String,
316 #[serde(skip_serializing_if = "Option::is_none")]
317 region: Option<String>,
318 #[serde(skip_serializing_if = "Option::is_none")]
319 icon: Option<String>,
320 verification_level: Option<VerificationLevel>,
321 #[serde(skip_serializing_if = "Option::is_none")]
322 default_message_notifications: Option<DefaultMessageNotifications>,
323 #[serde(skip_serializing_if = "Option::is_none")]
324 explicit_content_filter: Option<ExplicitContentFilter>,
325}
326
327impl CreateGuildOptions {
328 pub fn name(mut self, name: &str) -> Self {
330 self.name = name.to_string();
331 self
332 }
333
334 pub fn voice_region(mut self, region: &str) -> Self {
336 self.region = Some(region.to_string());
337 self
338 }
339
340 pub fn icon(mut self, icon: String) -> Self {
342 self.icon = Some(icon);
343 self
344 }
345
346 pub fn verification_level(mut self, lvl: VerificationLevel) -> Self {
348 self.verification_level = Some(lvl);
349 self
350 }
351
352 pub fn default_message_notifications(mut self, notifs: DefaultMessageNotifications) -> Self {
354 self.default_message_notifications = Some(notifs);
355 self
356 }
357
358 pub fn explicit_content_filter(mut self, filter: ExplicitContentFilter) -> Self {
360 self.explicit_content_filter = Some(filter);
361 self
362 }
363}
364
365
366#[derive(Deserialize, Debug, Clone)]
368pub struct GuildBan {
369 pub reason: Option<String>,
371 pub user: User,
373}
374
375#[derive(Deserialize, Debug, Clone)]
377pub struct GuildBanAdd {
378 pub guild_id: Snowflake,
380 pub user: User
382}
383
384#[derive(Deserialize, Debug, Clone)]
386pub struct GuildBanRemove {
387 pub guild_id: Snowflake,
389 pub user: User
391}
392
393#[derive(Deserialize, Debug, Clone)]
395pub struct GuildEmojisUpdate {
396 pub guild_id: Snowflake,
398 pub emojis: Vec<Emoji>,
400}
401
402#[derive(Deserialize, Debug, Clone)]
404pub struct GuildIntegrationsUpdate {
405 pub guild_id: Snowflake
407}
408
409#[derive(Deserialize, Debug, Clone)]
411pub struct GuildMemberRemove {
412 pub guild_id: Snowflake,
414 pub user: User
416}
417
418#[derive(Deserialize, Clone, Debug)]
420pub struct GuildMemberUpdate {
421 pub guild_id: Snowflake,
423 pub roles: Vec<String>,
424 pub user: User,
426 pub nick: String
428}
429
430#[derive(Deserialize, Debug, Clone)]
432pub struct GuildMembersChunk {
433 pub guild_id: Snowflake,
435 pub members: Vec<GuildMember>
437}
438
439#[derive(Deserialize, Clone, Debug)]
441pub struct GuildRoleCreate {
442 pub guild_id: Snowflake,
444 pub role: Role
446}
447
448#[derive(Deserialize, Clone, Debug)]
450pub struct GuildRoleUpdate {
451 pub guild_id: String,
453 pub role: Role
455}
456
457#[derive(Deserialize, Clone, Debug)]
459pub struct GuildRoleDelete {
460 pub guild_id: Snowflake,
462 pub role: Snowflake
464}
465
466#[derive(Deserialize_repr, Debug, Serialize_repr, Clone)]
468#[repr(u8)]
469pub enum ExplicitContentFilter {
470 Disabled,
472 MembersWithoutRoles,
474 AllMembers
476}
477
478#[derive(Deserialize_repr, Debug, Serialize_repr, Clone)]
480#[repr(u8)]
481pub enum MfaLevel {
482 None,
484 Elevated,
486}
487
488#[derive(Deserialize_repr, Debug, Serialize_repr, Clone)]
490#[repr(u8)]
491pub enum DefaultMessageNotifications {
492 AllMessages,
494 OnlyMentions
496}
497
498#[derive(Deserialize_repr, Debug, Clone, Serialize_repr)]
500#[repr(u8)]
501pub enum VerificationLevel {
502 None,
504 Low,
506 Medium,
508 High,
510 Insane
512}