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
use std::collections::HashMap;
use crate::internal::prelude::*;
use crate::model::guild::GuildWelcomeScreenEmoji;
use crate::utils;
#[derive(Clone, Debug, Default)]
pub struct EditGuildWelcomeScreen(pub HashMap<&'static str, Value>);
impl EditGuildWelcomeScreen {
pub fn enabled(&mut self, enabled: bool) -> &mut Self {
self.0.insert("enabled", Value::Bool(enabled));
self
}
pub fn description<D: ToString>(&mut self, description: D) -> &mut Self {
self.0.insert("description", Value::String(description.to_string()));
self
}
pub fn create_welcome_channel<F>(&mut self, f: F) -> &mut Self
where
F: FnOnce(&mut CreateGuildWelcomeChannel) -> &mut CreateGuildWelcomeChannel,
{
let mut data = CreateGuildWelcomeChannel::default();
f(&mut data);
self.add_welcome_channel(data);
self
}
pub fn add_welcome_channel(&mut self, channel: CreateGuildWelcomeChannel) -> &mut Self {
let new_data = utils::hashmap_to_json_map(channel.0);
let channels = self.0.entry("welcome_channels").or_insert_with(|| Value::Array(Vec::new()));
let channels_array = channels.as_array_mut().expect("Must be an array.");
channels_array.push(Value::Object(new_data));
self
}
pub fn set_welcome_channels(&mut self, channels: Vec<CreateGuildWelcomeChannel>) -> &mut Self {
let new_channels = channels
.into_iter()
.map(|f| Value::Object(utils::hashmap_to_json_map(f.0)))
.collect::<Vec<Value>>();
self.0.insert("welcome_channels", Value::Array(new_channels));
self
}
}
#[derive(Clone, Debug, Default)]
pub struct CreateGuildWelcomeChannel(pub HashMap<&'static str, Value>);
impl CreateGuildWelcomeChannel {
pub fn id(&mut self, id: u64) -> &mut Self {
self.0.insert("channel_id", Value::String(id.to_string()));
self
}
pub fn description<D: ToString>(&mut self, description: D) -> &mut Self {
self.0.insert("description", Value::String(description.to_string()));
self
}
pub fn emoji(&mut self, emoji: GuildWelcomeScreenEmoji) -> &mut Self {
match emoji {
GuildWelcomeScreenEmoji::Unicode(name) => {
self.0.insert("emoji_name", Value::String(name))
},
GuildWelcomeScreenEmoji::Custom(id) => {
self.0.insert("emoji_id", Value::String(id.to_string()))
},
};
self
}
}