twilight_model/guild/invite/
guild.rs

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use super::WelcomeScreen;
use crate::{
    guild::{GuildFeature, VerificationLevel},
    id::{marker::GuildMarker, Id},
    util::image_hash::ImageHash,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct InviteGuild {
    /// Hash of the banner image.
    pub banner: Option<ImageHash>,
    /// Description used for guild discovery.
    pub description: Option<String>,
    /// List of features that the guild has had enabled.
    pub features: Vec<GuildFeature>,
    /// Hash of the icon image.
    pub icon: Option<ImageHash>,
    /// ID of the guild.
    pub id: Id<GuildMarker>,
    /// Name of the guild.
    pub name: String,
    /// Number of boosts the guild has.
    pub premium_subscription_count: Option<u64>,
    /// Hash of the splash image.
    pub splash: Option<ImageHash>,
    /// Vanity code unique to the guild for invites.
    pub vanity_url_code: Option<String>,
    /// Account verification level required to participate.
    pub verification_level: VerificationLevel,
    /// Welcome screen for a Community guild.
    pub welcome_screen: Option<WelcomeScreen>,
}

#[cfg(test)]
mod tests {
    use crate::{
        guild::{
            invite::{InviteGuild, WelcomeScreen, WelcomeScreenChannel},
            GuildFeature, VerificationLevel,
        },
        id::Id,
        test::image_hash,
    };
    use serde_test::Token;

    #[test]
    #[allow(clippy::too_many_lines)]
    fn test_invite_guild() {
        let value = InviteGuild {
            banner: Some(image_hash::BANNER),
            description: Some("a description".to_owned()),
            features: Vec::from([GuildFeature::Community]),
            icon: Some(image_hash::ICON),
            id: Id::new(1),
            name: "guild name".to_owned(),
            premium_subscription_count: Some(14),
            splash: Some(image_hash::SPLASH),
            vanity_url_code: Some("twilight".to_owned()),
            verification_level: VerificationLevel::Medium,
            welcome_screen: Some(WelcomeScreen {
                description: Some("welcome description".to_owned()),
                welcome_channels: vec![
                    WelcomeScreenChannel {
                        channel_id: Id::new(123),
                        description: "channel description".to_owned(),
                        emoji_id: None,
                        emoji_name: Some("\u{1f352}".to_owned()),
                    },
                    WelcomeScreenChannel {
                        channel_id: Id::new(456),
                        description: "custom description".to_owned(),
                        emoji_id: Some(Id::new(789)),
                        emoji_name: Some("custom_name".to_owned()),
                    },
                ],
            }),
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "InviteGuild",
                    len: 11,
                },
                Token::Str("banner"),
                Token::Some,
                Token::Str(image_hash::BANNER_INPUT),
                Token::Str("description"),
                Token::Some,
                Token::Str("a description"),
                Token::Str("features"),
                Token::Seq { len: Some(1) },
                Token::Str("COMMUNITY"),
                Token::SeqEnd,
                Token::Str("icon"),
                Token::Some,
                Token::Str(image_hash::ICON_INPUT),
                Token::Str("id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("1"),
                Token::Str("name"),
                Token::Str("guild name"),
                Token::Str("premium_subscription_count"),
                Token::Some,
                Token::U64(14),
                Token::Str("splash"),
                Token::Some,
                Token::Str(image_hash::SPLASH_INPUT),
                Token::Str("vanity_url_code"),
                Token::Some,
                Token::Str("twilight"),
                Token::Str("verification_level"),
                Token::U8(2),
                Token::Str("welcome_screen"),
                Token::Some,
                Token::Struct {
                    name: "WelcomeScreen",
                    len: 2,
                },
                Token::Str("description"),
                Token::Some,
                Token::Str("welcome description"),
                Token::Str("welcome_channels"),
                Token::Seq { len: Some(2) },
                Token::Struct {
                    name: "WelcomeScreenChannel",
                    len: 4,
                },
                Token::Str("channel_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("123"),
                Token::Str("description"),
                Token::Str("channel description"),
                Token::Str("emoji_id"),
                Token::None,
                Token::Str("emoji_name"),
                Token::Some,
                Token::Str("\u{1f352}"),
                Token::StructEnd,
                Token::Struct {
                    name: "WelcomeScreenChannel",
                    len: 4,
                },
                Token::Str("channel_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("456"),
                Token::Str("description"),
                Token::Str("custom description"),
                Token::Str("emoji_id"),
                Token::Some,
                Token::NewtypeStruct { name: "Id" },
                Token::Str("789"),
                Token::Str("emoji_name"),
                Token::Some,
                Token::Str("custom_name"),
                Token::StructEnd,
                Token::SeqEnd,
                Token::StructEnd,
                Token::StructEnd,
            ],
        )
    }
}