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
use crate::internal::prelude::*;
use crate::model::prelude::*;
use serde_json::{json, Value};
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct CreateChannel(pub HashMap<&'static str, Value>);
impl CreateChannel {
pub fn name<D: ToString>(&mut self, name: D) -> &mut Self {
self.0.insert("name", Value::String(name.to_string()));
self
}
pub fn kind(&mut self, kind: ChannelType) -> &mut Self {
self.0.insert("type", Value::Number(Number::from(kind as u8)));
self
}
pub fn category<I: Into<ChannelId>>(&mut self, id: I) -> &mut Self {
self.0.insert("parent_id", Value::Number(Number::from(id.into().0)));
self
}
pub fn topic<D: ToString>(&mut self, topic: D) -> &mut Self {
self.0.insert("topic", Value::String(topic.to_string()));
self
}
pub fn nsfw(&mut self, b: bool) -> &mut Self {
self.0.insert("nsfw", Value::Bool(b));
self
}
pub fn bitrate(&mut self, rate: u32) -> &mut Self {
self.0.insert("bitrate", Value::Number(Number::from(rate)));
self
}
pub fn user_limit(&mut self, limit: u32) -> &mut Self {
self.0.insert("user_limit", Value::Number(Number::from(limit)));
self
}
pub fn rate_limit(&mut self, limit: u64) -> &mut Self {
self.0.insert("rate_limit_per_user", Value::Number(Number::from(limit)));
self
}
pub fn position(&mut self, pos: u32) -> &mut Self {
self.0.insert("position", Value::Number(Number::from(pos)));
self
}
pub fn permissions<I>(&mut self, perms: I) -> &mut Self
where I: IntoIterator<Item=PermissionOverwrite>
{
let overwrites = perms.into_iter().map(|perm| {
let (id, kind) = match perm.kind {
PermissionOverwriteType::Member(id) => (id.0, "member"),
PermissionOverwriteType::Role(id) => (id.0, "role"),
PermissionOverwriteType::__Nonexhaustive => unreachable!(),
};
json!({
"allow": perm.allow.bits(),
"deny": perm.deny.bits(),
"id": id,
"type": kind,
})
}).collect();
self.0.insert("permission_overwrites", Value::Array(overwrites));
self
}
}
impl Default for CreateChannel {
fn default() -> Self {
let mut builder = CreateChannel(HashMap::new());
builder.kind(ChannelType::Text);
builder
}
}