twilight_model/application/interaction/
context_type.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
4#[non_exhaustive]
5#[serde(from = "u8", into = "u8")]
6pub enum InteractionContextType {
7    /// Interaction can be used within servers.
8    Guild,
9    /// Interaction can be used within DMs with the app's bot user.
10    BotDm,
11    /// Interaction can be used within Group DMs and DMs other than
12    /// the app's bot user.
13    PrivateChannel,
14    /// Variant value is unknown to the library.
15    Unknown(u8),
16}
17
18impl InteractionContextType {
19    pub const fn kind(self) -> &'static str {
20        match self {
21            Self::Guild => "GUILD",
22            Self::BotDm => "BOT_DM",
23            Self::PrivateChannel => "PRIVATE_CHANNEL",
24            Self::Unknown(_) => "Unknown",
25        }
26    }
27}
28
29impl From<u8> for InteractionContextType {
30    fn from(value: u8) -> Self {
31        match value {
32            0 => Self::Guild,
33            1 => Self::BotDm,
34            2 => Self::PrivateChannel,
35            unknown => Self::Unknown(unknown),
36        }
37    }
38}
39
40impl From<InteractionContextType> for u8 {
41    fn from(value: InteractionContextType) -> Self {
42        match value {
43            InteractionContextType::Guild => 0,
44            InteractionContextType::BotDm => 1,
45            InteractionContextType::PrivateChannel => 2,
46            InteractionContextType::Unknown(unknown) => unknown,
47        }
48    }
49}