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
//! Structures related to a Channel on Discord.
use chrono::{DateTime, FixedOffset};
use serde_repr::{Deserialize_repr, Serialize_repr};

use crate::User;

/// A guild or DM channel on Discord.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Channel {
    /// The channel ID of this channel.
    pub id: String,
    /// The type of channel.
    #[serde(rename = "type")]
    pub kind: Option<ChannelType>,
    /// The guild ID of this channel.
    #[serde(default)]
    pub guild_id: Option<String>,
    /// The position of this channel.
    #[serde(default)]
    pub position: i32,
    /// The explicit permission overwrites for members and roles.
    #[serde(default)]
    pub permission_overwrites: PermissionOverwrites,
    /// The name of the channel.
    #[serde(default)]
    pub name: String,
    /// The topic of this channel.
    #[serde(default)]
    pub topic: Option<String>,
    /// Whether or not this channel is an NSFW channel.
    #[serde(default)]
    pub nsfw: bool,
    /// The ID of the last message sent in this channel.
    #[serde(default)]
    pub last_message_id: Option<String>,
    /// The bitrate of this channel.
    #[serde(default)]
    pub bitrate: i32,
    /// The user limit, if voice.
    #[serde(default)]
    pub user_limit: i32,
    /// The cooldown between sending messages in this channel, in seconds.
    #[serde(default)]
    pub rate_limit_per_user: i32,
    /// The recepients, if DM.
    #[serde(default)]
    pub recipients: Vec<User>,
    /// The channel's icon hash if any.
    #[serde(default)]
    pub icon: Option<String>,
    /// The ID of the creator, if a DM.
    #[serde(default)]
    pub owner_id: String,
    /// The application ID, if the channel was created by a bot.
    #[serde(default)]
    pub application_id: String,
    /// The ID of the parent category.
    #[serde(default)]
    pub parent_id: Option<String>,
    /// When the last message was pinned.
    #[serde(default)]
    pub last_pin_timestamp: Option<DateTime<FixedOffset>>
}

/// A channel permission overwrite.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct PermissionOverwrites {
    /// The ID of the role or user.
    pub id: String,
    /// What this ID is for.
    #[serde(rename = "type")]
    pub kind: String,
    /// The allowed permission bitfield.
    pub allow: i32,
    /// The denied permissions bitfield.
    pub deny: i32
}

/// Represents the possible Channel types,
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone)]
#[repr(u8)]
pub enum ChannelType {
    Text,
    DM,
    Voice,
    GroupDM,
    Category
}