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
use chrono::{DateTime, FixedOffset};
use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::{Snowflake, User};
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Channel {
pub id: Snowflake,
#[serde(rename = "type")]
pub kind: Option<ChannelType>,
#[serde(default)]
pub guild_id: Option<Snowflake>,
#[serde(default)]
pub position: Option<i32>,
#[serde(default)]
pub permission_overwrites: Option<Vec<PermissionOverwrites>>,
#[serde(default)]
pub name: Option<String>,
#[serde(default)]
pub topic: Option<String>,
#[serde(default)]
pub nsfw: Option<bool>,
#[serde(default)]
pub last_message_id: Option<Snowflake>,
#[serde(default)]
pub bitrate: Option<i32>,
#[serde(default)]
pub user_limit: Option<i32>,
#[serde(default)]
pub rate_limit_per_user: Option<i32>,
#[serde(default)]
pub recipients: Option<Vec<User>>,
#[serde(default)]
pub icon: Option<String>,
#[serde(default)]
pub owner_id: Option<Snowflake>,
#[serde(default)]
pub application_id: Option<Snowflake>,
#[serde(default)]
pub parent_id: Option<Snowflake>,
#[serde(default)]
pub last_pin_timestamp: Option<DateTime<FixedOffset>>
}
impl ToString for Channel {
fn to_string(&self) -> String {
format!("<#{}>", self.id.0)
}
}
#[derive(Serialize, Clone, Debug, Default)]
pub struct ModifyChannel {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
position: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
topic: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
nsfw: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
rate_limit_per_user: Option<i8>,
#[serde(skip_serializing_if = "Option::is_none")]
bitrate: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
user_limit: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
parent_id: Option<Snowflake>
}
impl ModifyChannel {
pub fn new() -> Self {
ModifyChannel::default()
}
pub fn name(mut self, new_name: &str) -> Self {
self.name = Some(new_name.to_string());
self
}
pub fn set_position(mut self, pos: i32) -> Self {
self.position = Some(pos);
self
}
pub fn topic(mut self, top: &str) -> Self {
self.topic = Some(top.to_string());
self
}
pub fn nsfw(mut self, opt: bool) -> Self {
self.nsfw = Some(opt);
self
}
pub fn rate_limit_per_user(mut self, secs: i8) -> Self {
self.rate_limit_per_user = Some(secs);
self
}
pub fn user_limit(mut self, limit: i32) -> Self {
self.user_limit = Some(limit);
self
}
pub fn parent_id(mut self, id: u64) -> Self {
self.parent_id = Some(id.into());
self
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct PermissionOverwrites {
pub id: Snowflake,
#[serde(rename = "type")]
pub kind: String,
pub allow: i32,
pub deny: i32
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone)]
#[repr(u8)]
pub enum ChannelType {
Text,
DM,
Voice,
GroupDM,
Category
}