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
use std::collections::HashMap;
use super::CreateEmbed;
#[cfg(feature = "unstable_discord_api")]
use crate::builder::CreateComponents;
use crate::internal::prelude::*;
use crate::model::channel::MessageFlags;
use crate::utils;
#[derive(Clone, Debug, Default)]
pub struct EditMessage(pub HashMap<&'static str, Value>);
impl EditMessage {
#[inline]
pub fn content<D: ToString>(&mut self, content: D) -> &mut Self {
self.0.insert("content", Value::String(content.to_string()));
self
}
fn _add_embed(&mut self, embed: CreateEmbed) -> &mut Self {
let map = utils::hashmap_to_json_map(embed.0);
let embed = Value::Object(map);
let embeds = self.0.entry("embeds").or_insert_with(|| Value::Array(Vec::new()));
let embeds_array = embeds.as_array_mut().expect("Embeds must be an array");
embeds_array.push(embed);
self
}
pub fn add_embed<F>(&mut self, f: F) -> &mut Self
where
F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed,
{
let mut embed = CreateEmbed::default();
f(&mut embed);
self._add_embed(embed)
}
pub fn add_embeds(&mut self, embeds: Vec<CreateEmbed>) -> &mut Self {
for embed in embeds {
self._add_embed(embed);
}
self
}
pub fn embed<F>(&mut self, f: F) -> &mut Self
where
F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed,
{
let mut embed = CreateEmbed::default();
f(&mut embed);
self.0.insert("embeds", Value::Array(Vec::new()));
self._add_embed(embed)
}
pub fn set_embed(&mut self, embed: CreateEmbed) -> &mut Self {
self.0.insert("embeds", Value::Array(Vec::new()));
self._add_embed(embed)
}
pub fn set_embeds(&mut self, embeds: Vec<CreateEmbed>) -> &mut Self {
self.0.insert("embeds", Value::Array(Vec::new()));
for embed in embeds {
self._add_embed(embed);
}
self
}
pub fn suppress_embeds(&mut self, suppress: bool) -> &mut Self {
let flags = if suppress { 1 << 2 } else { 0 };
self.0.insert("flags", serde_json::Value::Number(serde_json::Number::from(flags)));
self
}
#[cfg(feature = "unstable_discord_api")]
pub fn components<F>(&mut self, f: F) -> &mut Self
where
F: FnOnce(&mut CreateComponents) -> &mut CreateComponents,
{
let mut components = CreateComponents::default();
f(&mut components);
self.0.insert("components", Value::Array(components.0));
self
}
pub fn flags(&mut self, flags: MessageFlags) -> &mut Self {
self.0.insert("flags", Value::Number(serde_json::Number::from(flags.bits)));
self
}
}