serenity/builder/
create_scheduled_event.rs1#[cfg(feature = "http")]
2use super::Builder;
3use super::CreateAttachment;
4#[cfg(feature = "http")]
5use crate::http::CacheHttp;
6#[cfg(feature = "http")]
7use crate::internal::prelude::*;
8use crate::model::prelude::*;
9
10#[derive(Clone, Debug, Serialize)]
12#[must_use]
13pub struct CreateScheduledEvent<'a> {
14 #[serde(skip_serializing_if = "Option::is_none")]
15 channel_id: Option<ChannelId>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 entity_metadata: Option<ScheduledEventMetadata>,
18 name: String,
19 privacy_level: ScheduledEventPrivacyLevel,
20 scheduled_start_time: String,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 scheduled_end_time: Option<String>,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 description: Option<String>,
25 entity_type: ScheduledEventType,
26 #[serde(skip_serializing_if = "Option::is_none")]
27 image: Option<String>,
28
29 #[serde(skip)]
30 audit_log_reason: Option<&'a str>,
31}
32
33impl<'a> CreateScheduledEvent<'a> {
34 pub fn new(
37 kind: ScheduledEventType,
38 name: impl Into<String>,
39 scheduled_start_time: impl Into<Timestamp>,
40 ) -> Self {
41 Self {
42 name: name.into(),
43 entity_type: kind,
44 scheduled_start_time: scheduled_start_time.into().to_string(),
45
46 image: None,
47 channel_id: None,
48 description: None,
49 entity_metadata: None,
50 scheduled_end_time: None,
51
52 privacy_level: ScheduledEventPrivacyLevel::GuildOnly,
56
57 audit_log_reason: None,
58 }
59 }
60
61 pub fn channel_id<C: Into<ChannelId>>(mut self, channel_id: C) -> Self {
64 self.channel_id = Some(channel_id.into());
65 self
66 }
67
68 pub fn name(mut self, name: impl Into<String>) -> Self {
70 self.name = name.into();
71 self
72 }
73
74 pub fn description(mut self, description: impl Into<String>) -> Self {
76 self.description = Some(description.into());
77 self
78 }
79
80 pub fn start_time(mut self, timestamp: impl Into<Timestamp>) -> Self {
83 self.scheduled_start_time = timestamp.into().to_string();
84 self
85 }
86
87 pub fn end_time(mut self, timestamp: impl Into<Timestamp>) -> Self {
90 self.scheduled_end_time = Some(timestamp.into().to_string());
91 self
92 }
93
94 pub fn kind(mut self, kind: ScheduledEventType) -> Self {
97 self.entity_type = kind;
98 self
99 }
100
101 pub fn location(mut self, location: impl Into<String>) -> Self {
106 self.entity_metadata = Some(ScheduledEventMetadata {
107 location: Some(location.into()),
108 });
109 self
110 }
111
112 pub fn image(mut self, image: &CreateAttachment) -> Self {
114 self.image = Some(image.to_base64());
115 self
116 }
117
118 pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
120 self.audit_log_reason = Some(reason);
121 self
122 }
123}
124
125#[cfg(feature = "http")]
126#[async_trait::async_trait]
127impl Builder for CreateScheduledEvent<'_> {
128 type Context<'ctx> = GuildId;
129 type Built = ScheduledEvent;
130
131 async fn execute(
142 self,
143 cache_http: impl CacheHttp,
144 ctx: Self::Context<'_>,
145 ) -> Result<Self::Built> {
146 #[cfg(feature = "cache")]
147 crate::utils::user_has_guild_perms(&cache_http, ctx, Permissions::CREATE_EVENTS)?;
148
149 cache_http.http().create_scheduled_event(ctx, &self, self.audit_log_reason).await
150 }
151}