serenity/builder/
edit_webhook.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(Debug, Default, Clone, Serialize)]
12#[must_use]
13pub struct EditWebhook<'a> {
14 #[serde(skip_serializing_if = "Option::is_none")]
15 name: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 avatar: Option<Option<String>>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 channel_id: Option<ChannelId>,
20
21 #[serde(skip)]
22 audit_log_reason: Option<&'a str>,
23}
24
25impl<'a> EditWebhook<'a> {
26 pub fn new() -> Self {
28 Self::default()
29 }
30
31 pub fn name(mut self, name: impl Into<String>) -> Self {
35 self.name = Some(name.into());
36 self
37 }
38
39 pub fn channel_id(mut self, channel_id: impl Into<ChannelId>) -> Self {
41 self.channel_id = Some(channel_id.into());
42 self
43 }
44
45 pub fn avatar(mut self, avatar: &CreateAttachment) -> Self {
47 self.avatar = Some(Some(avatar.to_base64()));
48 self
49 }
50
51 pub fn delete_avatar(mut self) -> Self {
53 self.avatar = Some(None);
54 self
55 }
56
57 pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
59 self.audit_log_reason = Some(reason);
60 self
61 }
62}
63
64#[cfg(feature = "http")]
65#[async_trait::async_trait]
66impl Builder for EditWebhook<'_> {
67 type Context<'ctx> = (WebhookId, Option<&'ctx str>);
68 type Built = Webhook;
69
70 async fn execute(
79 self,
80 cache_http: impl CacheHttp,
81 ctx: Self::Context<'_>,
82 ) -> Result<Self::Built> {
83 match ctx.1 {
84 Some(token) => {
85 cache_http
86 .http()
87 .edit_webhook_with_token(ctx.0, token, &self, self.audit_log_reason)
88 .await
89 },
90 None => cache_http.http().edit_webhook(ctx.0, &self, self.audit_log_reason).await,
91 }
92 }
93}