twilight_model/guild/
feature.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#![allow(deprecated)]
use std::borrow::Cow;

use serde::{Deserialize, Serialize};

/// Special and optional guild features.
///
/// See [Discord Docs/Guild Features].
///
/// [Discord Docs/Guild Features]: https://discord.com/developers/docs/resources/guild#guild-object-guild-features
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
#[serde(from = "String", into = "Cow<'static, str>")]
pub enum GuildFeature {
    /// Has access to set an animated guild banner image.
    AnimatedBanner,
    /// Has access to set an animated guild icon.
    AnimatedIcon,
    /// Has set up auto moderation rules.
    AutoModeration,
    /// Has access to set a guild banner image.
    Banner,
    /// Can enable welcome screen, membership screening, stage channels,
    /// discovery, and receives community updates.
    Community,
    /// Guild has enabled monetization.
    CreatorMonetizableProvisional,
    /// Guild has enabled the role subscription promotional page.
    CreatorStorePage,
    /// Guild has been set as a support server on the App Directory.
    DeveloperSupportServer,
    /// Is able to be discovered in the directory.
    Discoverable,
    /// Is able to be featured in the directory.
    Featurable,
    /// Invites have been paused, this prevents new users from joining.
    InvitesDisabled,
    /// Has access to set an invite splash background.
    InviteSplash,
    /// Has enabled membership screening.
    MemberVerificationGateEnabled,
    /// Has increased custom sticker slots.
    MoreStickers,
    /// Has access to create news channels.
    News,
    /// Is partnered.
    Partnered,
    /// Can be previewed before joining via membership screening or the directory.
    PreviewEnabled,
    /// Has access to create private threads.
    PrivateThreads,
    /// Guild has disabled alerts for join raids in the configured safety alerts channel.
    RaidAlertsDisabled,
    /// Is able to set role icons.
    RoleIcons,
    /// Guild has role subscriptions that can be purchased.
    RoleSubscriptionsAvailableForPurchase,
    /// Guild has enabled role subscriptions.
    RoleSubscriptionsEnabled,
    /// Has enabled ticketed events.
    TicketedEventsEnabled,
    /// Has access to set a vanity URL.
    VanityUrl,
    /// Is verified.
    Verified,
    /// Has access to set 384kps bitrate in voice (previously VIP voice servers).
    VipRegions,
    /// Has enabled the welcome screen.
    WelcomeScreenEnabled,
    /// Variant value is unknown to the library.
    Unknown(String),
}

impl From<GuildFeature> for Cow<'static, str> {
    fn from(value: GuildFeature) -> Self {
        match value {
            GuildFeature::AnimatedBanner => "ANIMATED_BANNER".into(),
            GuildFeature::AnimatedIcon => "ANIMATED_ICON".into(),
            GuildFeature::AutoModeration => "AUTO_MODERATION".into(),
            GuildFeature::Banner => "BANNER".into(),
            GuildFeature::Community => "COMMUNITY".into(),
            GuildFeature::CreatorMonetizableProvisional => "CREATOR_MONETIZABLE_PROVISIONAL".into(),
            GuildFeature::CreatorStorePage => "CREATOR_STORE_PAGE".into(),
            GuildFeature::DeveloperSupportServer => "DEVELOPER_SUPPORT_SERVER".into(),
            GuildFeature::Discoverable => "DISCOVERABLE".into(),
            GuildFeature::Featurable => "FEATURABLE".into(),
            GuildFeature::InvitesDisabled => "INVITES_DISABLED".into(),
            GuildFeature::InviteSplash => "INVITE_SPLASH".into(),
            GuildFeature::MemberVerificationGateEnabled => {
                "MEMBER_VERIFICATION_GATE_ENABLED".into()
            }
            GuildFeature::MoreStickers => "MORE_STICKERS".into(),
            GuildFeature::News => "NEWS".into(),
            GuildFeature::Partnered => "PARTNERED".into(),
            GuildFeature::PreviewEnabled => "PREVIEW_ENABLED".into(),
            GuildFeature::PrivateThreads => "PRIVATE_THREADS".into(),
            GuildFeature::RaidAlertsDisabled => "RAID_ALERTS_DISABLED".into(),
            GuildFeature::RoleIcons => "ROLE_ICONS".into(),
            GuildFeature::RoleSubscriptionsAvailableForPurchase => {
                "ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE".into()
            }
            GuildFeature::RoleSubscriptionsEnabled => "ROLE_SUBSCRIPTIONS_ENABLED".into(),
            GuildFeature::TicketedEventsEnabled => "TICKETED_EVENTS_ENABLED".into(),
            GuildFeature::VanityUrl => "VANITY_URL".into(),
            GuildFeature::Verified => "VERIFIED".into(),
            GuildFeature::VipRegions => "VIP_REGIONS".into(),
            GuildFeature::WelcomeScreenEnabled => "WELCOME_SCREEN_ENABLED".into(),
            GuildFeature::Unknown(unknown) => unknown.into(),
        }
    }
}

impl From<String> for GuildFeature {
    fn from(value: String) -> Self {
        match value.as_str() {
            "ANIMATED_BANNER" => Self::AnimatedBanner,
            "ANIMATED_ICON" => Self::AnimatedIcon,
            "AUTO_MODERATION" => Self::AutoModeration,
            "BANNER" => Self::Banner,
            "COMMUNITY" => Self::Community,
            "CREATOR_MONETIZABLE_PROVISIONAL" => GuildFeature::CreatorMonetizableProvisional,
            "CREATOR_STORE_PAGE" => GuildFeature::CreatorStorePage,
            "DEVELOPER_SUPPORT_SERVER" => Self::DeveloperSupportServer,
            "DISCOVERABLE" => Self::Discoverable,
            "FEATURABLE" => Self::Featurable,
            "INVITES_DISABLED" => Self::InvitesDisabled,
            "INVITE_SPLASH" => Self::InviteSplash,
            "MEMBER_VERIFICATION_GATE_ENABLED" => Self::MemberVerificationGateEnabled,
            "MORE_STICKERS" => Self::MoreStickers,
            "NEWS" => Self::News,
            "PARTNERED" => Self::Partnered,
            "PREVIEW_ENABLED" => Self::PreviewEnabled,
            "PRIVATE_THREADS" => Self::PrivateThreads,
            "RAID_ALERTS_DISABLED" => Self::RaidAlertsDisabled,
            "ROLE_ICONS" => Self::RoleIcons,
            "ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE" => {
                GuildFeature::RoleSubscriptionsAvailableForPurchase
            }
            "ROLE_SUBSCRIPTIONS_ENABLED" => GuildFeature::RoleSubscriptionsEnabled,
            "TICKETED_EVENTS_ENABLED" => Self::TicketedEventsEnabled,
            "VANITY_URL" => Self::VanityUrl,
            "VERIFIED" => Self::Verified,
            "VIP_REGIONS" => Self::VipRegions,
            "WELCOME_SCREEN_ENABLED" => Self::WelcomeScreenEnabled,
            _ => Self::Unknown(value),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::GuildFeature;
    use serde_test::Token;

    #[test]
    fn variants() {
        serde_test::assert_tokens(
            &GuildFeature::AnimatedBanner,
            &[Token::Str("ANIMATED_BANNER")],
        );
        serde_test::assert_tokens(&GuildFeature::AnimatedIcon, &[Token::Str("ANIMATED_ICON")]);
        serde_test::assert_tokens(
            &GuildFeature::AutoModeration,
            &[Token::Str("AUTO_MODERATION")],
        );
        serde_test::assert_tokens(&GuildFeature::Banner, &[Token::Str("BANNER")]);
        serde_test::assert_tokens(&GuildFeature::Community, &[Token::Str("COMMUNITY")]);
        serde_test::assert_tokens(
            &GuildFeature::CreatorMonetizableProvisional,
            &[Token::Str("CREATOR_MONETIZABLE_PROVISIONAL")],
        );
        serde_test::assert_tokens(
            &GuildFeature::CreatorStorePage,
            &[Token::Str("CREATOR_STORE_PAGE")],
        );
        serde_test::assert_tokens(
            &GuildFeature::DeveloperSupportServer,
            &[Token::Str("DEVELOPER_SUPPORT_SERVER")],
        );
        serde_test::assert_tokens(&GuildFeature::Discoverable, &[Token::Str("DISCOVERABLE")]);
        serde_test::assert_tokens(&GuildFeature::Featurable, &[Token::Str("FEATURABLE")]);
        serde_test::assert_tokens(
            &GuildFeature::InvitesDisabled,
            &[Token::Str("INVITES_DISABLED")],
        );
        serde_test::assert_tokens(&GuildFeature::InviteSplash, &[Token::Str("INVITE_SPLASH")]);
        serde_test::assert_tokens(
            &GuildFeature::MemberVerificationGateEnabled,
            &[Token::Str("MEMBER_VERIFICATION_GATE_ENABLED")],
        );
        serde_test::assert_tokens(&GuildFeature::MoreStickers, &[Token::Str("MORE_STICKERS")]);
        serde_test::assert_tokens(&GuildFeature::News, &[Token::Str("NEWS")]);
        serde_test::assert_tokens(&GuildFeature::Partnered, &[Token::Str("PARTNERED")]);
        serde_test::assert_tokens(
            &GuildFeature::PreviewEnabled,
            &[Token::Str("PREVIEW_ENABLED")],
        );
        serde_test::assert_tokens(
            &GuildFeature::PrivateThreads,
            &[Token::Str("PRIVATE_THREADS")],
        );
        serde_test::assert_tokens(&GuildFeature::RoleIcons, &[Token::Str("ROLE_ICONS")]);
        serde_test::assert_tokens(
            &GuildFeature::RoleSubscriptionsAvailableForPurchase,
            &[Token::Str("ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE")],
        );
        serde_test::assert_tokens(
            &GuildFeature::RoleSubscriptionsEnabled,
            &[Token::Str("ROLE_SUBSCRIPTIONS_ENABLED")],
        );
        serde_test::assert_tokens(
            &GuildFeature::TicketedEventsEnabled,
            &[Token::Str("TICKETED_EVENTS_ENABLED")],
        );
        serde_test::assert_tokens(&GuildFeature::VanityUrl, &[Token::Str("VANITY_URL")]);
        serde_test::assert_tokens(&GuildFeature::Verified, &[Token::Str("VERIFIED")]);
        serde_test::assert_tokens(&GuildFeature::VipRegions, &[Token::Str("VIP_REGIONS")]);
        serde_test::assert_tokens(
            &GuildFeature::WelcomeScreenEnabled,
            &[Token::Str("WELCOME_SCREEN_ENABLED")],
        );
        serde_test::assert_tokens(
            &GuildFeature::Unknown("UNKNOWN".to_owned()),
            &[Token::Str("UNKNOWN")],
        );
    }
}