1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use super::{File, MemberCompositeKey, User};

#[cfg(feature = "validator")]
use validator::Validate;

auto_derived!(
    /// Server Ban
    pub struct ServerBan {
        /// Unique member id
        #[cfg_attr(feature = "serde", serde(rename = "_id"))]
        pub id: MemberCompositeKey,
        /// Reason for ban creation
        pub reason: Option<String>,
    }

    /// Information for new server ban
    #[cfg_attr(feature = "validator", derive(Validate))]
    pub struct DataBanCreate {
        /// Ban reason
        #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
        pub reason: Option<String>,
    }

    /// Just enough information to list a ban
    pub struct BannedUser {
        /// Id of the banned user
        #[cfg_attr(feature = "serde", serde(rename = "_id"))]
        pub id: String,
        /// Username of the banned user
        pub username: String,
        /// Discriminator of the banned user
        pub discriminator: String,
        /// Avatar of the banned user
        pub avatar: Option<File>,
    }

    /// Ban list result
    pub struct BanListResult {
        /// Users objects
        pub users: Vec<BannedUser>,
        /// Ban objects
        pub bans: Vec<ServerBan>,
    }
);

impl From<User> for BannedUser {
    fn from(user: User) -> Self {
        BannedUser {
            id: user.id,
            username: user.username,
            discriminator: user.discriminator,
            avatar: user.avatar,
        }
    }
}