twilight_model/guild/onboarding/
mod.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
//! Types for guild onboarding.

mod mode;
mod option;
mod prompt;
mod prompt_type;

use crate::id::{
    marker::{ChannelMarker, GuildMarker},
    Id,
};
use serde::{Deserialize, Serialize};

pub use self::{
    mode::OnboardingMode,
    option::{OnboardingPromptEmoji, OnboardingPromptOption},
    prompt::OnboardingPrompt,
    prompt_type::OnboardingPromptType,
};

/// The onboarding data for a guild.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Onboarding {
    /// Channel IDs that new members get opted into automatically
    pub default_channel_ids: Vec<Id<ChannelMarker>>,
    /// Whether the guild has enabled onboarding.
    pub enabled: bool,
    /// ID of the guild this onboarding is a part of.
    pub guild_id: Id<GuildMarker>,
    /// Current mode of onboarding.
    pub mode: OnboardingMode,
    /// Array of [`OnboardingPrompt`]s for the guild onboarding flow.
    pub prompts: Vec<OnboardingPrompt>,
}

#[cfg(test)]
mod tests {
    use super::{Onboarding, OnboardingMode};
    use crate::id::Id;
    use serde_test::Token;

    #[test]
    fn onboarding() {
        let onboarding = Onboarding {
            default_channel_ids: Vec::new(),
            enabled: true,
            guild_id: Id::new(123_456_789),
            mode: OnboardingMode::OnboardingDefault,
            prompts: Vec::new(),
        };

        serde_test::assert_tokens(
            &onboarding,
            &[
                Token::Struct {
                    name: "Onboarding",
                    len: 5,
                },
                Token::Str("default_channel_ids"),
                Token::Seq { len: Some(0) },
                Token::SeqEnd,
                Token::Str("enabled"),
                Token::Bool(true),
                Token::Str("guild_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("123456789"),
                Token::Str("mode"),
                Token::U8(0),
                Token::Str("prompts"),
                Token::Seq { len: Some(0) },
                Token::SeqEnd,
                Token::StructEnd,
            ],
        )
    }
}