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
use std::collections::HashMap;
#[cfg(feature = "model")]
use crate::http::Http;
#[cfg(feature = "model")]
use crate::internal::prelude::*;
use crate::json::{json, Value};
#[cfg(feature = "model")]
use crate::model::channel::AttachmentType;
use crate::model::guild::ScheduledEventType;
use crate::model::id::ChannelId;
use crate::model::Timestamp;
#[cfg(feature = "model")]
use crate::utils::encode_image;
#[derive(Clone, Debug)]
pub struct CreateScheduledEvent(pub HashMap<&'static str, Value>);
impl CreateScheduledEvent {
pub fn channel_id<C: Into<ChannelId>>(&mut self, channel_id: C) -> &mut Self {
self.0.insert("channel_id", Value::from(channel_id.into().0));
self
}
pub fn name<S: ToString>(&mut self, name: S) -> &mut Self {
self.0.insert("name", Value::from(name.to_string()));
self
}
pub fn description<S: ToString>(&mut self, description: S) -> &mut Self {
self.0.insert("description", Value::from(description.to_string()));
self
}
#[inline]
pub fn start_time<T: Into<Timestamp>>(&mut self, timestamp: T) -> &mut Self {
self._timestamp("scheduled_start_time", timestamp.into());
self
}
#[inline]
pub fn end_time<T: Into<Timestamp>>(&mut self, timestamp: T) -> &mut Self {
self._timestamp("scheduled_end_time", timestamp.into());
self
}
fn _timestamp(&mut self, field: &'static str, timestamp: Timestamp) {
self.0.insert(field, Value::from(timestamp.to_string()));
}
pub fn kind(&mut self, kind: ScheduledEventType) -> &mut Self {
self.0.insert("entity_type", Value::from(kind.num()));
self
}
pub fn location<S: ToString>(&mut self, location: S) -> &mut Self {
let obj = json!({
"location": location.to_string(),
});
self.0.insert("entity_metadata", obj);
self
}
#[cfg(feature = "model")]
pub async fn image<'a>(
&mut self,
http: impl AsRef<Http>,
image: impl Into<AttachmentType<'a>>,
) -> Result<&mut Self> {
let image_data = image.into().data(&http.as_ref().client).await?;
self.0.insert("image", Value::from(encode_image(&image_data)));
Ok(self)
}
}
impl Default for CreateScheduledEvent {
fn default() -> Self {
let mut map = HashMap::new();
map.insert("privacy_level", Value::from(2));
CreateScheduledEvent(map)
}
}